From e3043e791848439041aebb8bf75d39be6a3b9f34 Mon Sep 17 00:00:00 2001 From: Hawtim Zhang Date: Thu, 22 Oct 2020 22:35:29 +0800 Subject: [PATCH] fix: commitMP3 and countrycode to countryCode (#41) * feat: add config to resolve path alias. * feat: use vue-i18n for language switch * feat: add .editorconfig for ide * fix: add no-referrer to avoid CROB * fix: setCookie and fix typo * feat: integrate vue-i18n * feat: player component i18n support * fix: duplicate key warning in explore page * fix: like songs number changed in library page * fire: remove todo * fix: same text search on enter will cause error * fix: scrobble error params type * feat: prettier task supported * fix: prettier ignore config update * fix: conflict * fix: commitMP3 and countrycode to countryCode * lint: prettier --- src/components/TrackListItem.vue | 5 ++++- src/store/actions.js | 7 ++++++- src/utils/common.js | 5 +++++ src/views/loginAccount.vue | 4 ++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/components/TrackListItem.vue b/src/components/TrackListItem.vue index d8dc8eb..bb574ae 100644 --- a/src/components/TrackListItem.vue +++ b/src/components/TrackListItem.vue @@ -15,7 +15,10 @@ />
{{ track.no diff --git a/src/store/actions.js b/src/store/actions.js index 4cea2e1..58d0b2b 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -1,6 +1,7 @@ import { updateMediaSessionMetaData } from "@/utils/mediaSession"; import { getTrackDetail, scrobble, getMP3 } from "@/api/track"; import { isLoggedIn } from "@/utils/auth"; +import { updateHttps } from "@/utils/common"; export default { switchTrack({ state, dispatch, commit }, basicTrack) { @@ -43,7 +44,11 @@ export default { if (isLoggedIn) { getMP3(track.id).then((data) => { - commitMP3(data.data[0].url.replace(/^http:/, "https:")); + // 未知情况下会没有返回数据导致报错,增加防范逻辑 + if (data.data[0]) { + const url = updateHttps(data.data[0].url); + commitMP3(url); + } }); } else { commitMP3(`https://music.163.com/song/media/outer/url?id=${track.id}`); diff --git a/src/utils/common.js b/src/utils/common.js index d061bf9..575e634 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -70,3 +70,8 @@ export function throttle(fn, time) { }, time); }; } + +export function updateHttps(url) { + if (!url) return ""; + return url.replace(/^http:/, "https:"); +} diff --git a/src/views/loginAccount.vue b/src/views/loginAccount.vue index 36c8918..2958bc0 100644 --- a/src/views/loginAccount.vue +++ b/src/views/loginAccount.vue @@ -12,7 +12,7 @@