From dcf13b2f07f248f7d5b4248f8b9e69e65d310491 Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Wed, 4 Jun 2025 21:18:46 +1000 Subject: [PATCH] refactor: move resource URL refresh from favorites loading to playback/preload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace passive resource checking on playlist item mount with active checking during playback and preload operations. This improves performance by reducing unnecessary network requests and ensures resources are validated only when needed. Changes: - Create songResourceChecker utility for centralized resource validation - Remove resource checking from PlayListItem component - Add resource validation in Player component before playback - Add resource validation in usePlayQueueStore before preload - Maintain data consistency between play queue and favorites 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/components/PlayListItem.vue | 24 ---------- src/components/Player.vue | 38 +++++++++++++-- src/stores/usePlayQueueStore.ts | 29 ++++++++++-- src/utils/index.ts | 3 +- src/utils/songResourceChecker.ts | 80 ++++++++++++++++++++++++++++++++ 5 files changed, 142 insertions(+), 32 deletions(-) create mode 100644 src/utils/songResourceChecker.ts diff --git a/src/components/PlayListItem.vue b/src/components/PlayListItem.vue index f16540c..f526b15 100644 --- a/src/components/PlayListItem.vue +++ b/src/components/PlayListItem.vue @@ -2,11 +2,8 @@ import { artistsOrganize } from '../utils' import { ref } from 'vue' import { useFavourites } from '../stores/useFavourites' -import apis from '../apis' -import axios from 'axios' import StarSlashIcon from '../assets/icons/starslash.vue' -import { onMounted } from 'vue' const favourites = useFavourites() @@ -20,27 +17,6 @@ const props = defineProps<{ const emit = defineEmits<{ (e: 'play', index: number): void }>() - -onMounted(async () => { - try { - // 添加缓存控制头和随机参数来避免缓存 - await axios.head(props.item.song.sourceUrl ?? '', { - headers: { - 'Cache-Control': 'no-cache, no-store, must-revalidate', - 'Pragma': 'no-cache', - 'Expires': '0' - }, - params: { - _t: Date.now() // 添加时间戳参数避免缓存 - } - }) - } catch (error) { - // 刷新资源地址 - const updatedSong = await apis.getSong(props.item.song.cid) - console.log('Updated song:', updatedSong) - favourites.updateSongInFavourites(props.item.song.cid, updatedSong) - } -})