mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-01 20:42:50 +08:00
fix(web): post-review fixes for source tabs
- Reset per-platform fields on fetch failure (was leaving stale data for up to 5 minutes after the user logged out of NetEase). - Extract availableSources getter on the store; deduplicate the daily/ user availability computeds in Home.vue and Library.vue. - Add comment explaining why recommendAvailable always seeds netease. - Import Source type in SourceTabs.vue from the store instead of redeclaring locally, removing a future type-drift risk. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ac55a346be
commit
ec02887d22
4 files changed
+27
-37
No files matched your search
@@ -14,7 +14,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
type Source = 'netease' | 'qq';
|
import type { Source } from '../stores/player.js';
|
||||||
|
|
||||||
const LABELS: Record<Source, string> = {
|
const LABELS: Record<Source, string> = {
|
||||||
netease: '网易云',
|
netease: '网易云',
|
||||||
|
|||||||
+21
-18
@@ -94,6 +94,13 @@ export const usePlayerStore = defineStore('player', {
|
|||||||
if (this.isPaused) return Math.min(timing.serverElapsed, maxDuration);
|
if (this.isPaused) return Math.min(timing.serverElapsed, maxDuration);
|
||||||
return Math.min(timing.serverElapsed + (Date.now() - timing.serverSyncTime) / 1000, maxDuration);
|
return Math.min(timing.serverElapsed + (Date.now() - timing.serverSyncTime) / 1000, maxDuration);
|
||||||
},
|
},
|
||||||
|
/** Sources that are currently logged in. Order: netease before qq. */
|
||||||
|
availableSources(): Source[] {
|
||||||
|
const s: Source[] = [];
|
||||||
|
if (this.authStatus.netease) s.push('netease');
|
||||||
|
if (this.authStatus.qq) s.push('qq');
|
||||||
|
return s;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
@@ -401,24 +408,20 @@ export const usePlayerStore = defineStore('player', {
|
|||||||
|
|
||||||
const [neRecPL, neDaily, neUserPL, qqRecPL, qqDaily, qqUserPL, bili] = results;
|
const [neRecPL, neDaily, neUserPL, qqRecPL, qqDaily, qqUserPL, bili] = results;
|
||||||
|
|
||||||
if (neRecPL.status === 'fulfilled') {
|
this.recommendPlaylists.netease =
|
||||||
this.recommendPlaylists.netease = neRecPL.value.data.playlists ?? [];
|
neRecPL.status === 'fulfilled' ? (neRecPL.value.data.playlists ?? []) : [];
|
||||||
}
|
this.dailySongs.netease =
|
||||||
if (neDaily.status === 'fulfilled') {
|
neDaily.status === 'fulfilled' ? (neDaily.value.data.songs ?? []) : [];
|
||||||
this.dailySongs.netease = neDaily.value.data.songs ?? [];
|
this.userPlaylists.netease =
|
||||||
}
|
neUserPL.status === 'fulfilled' ? (neUserPL.value.data.playlists ?? []) : [];
|
||||||
if (neUserPL.status === 'fulfilled') {
|
this.recommendPlaylists.qq =
|
||||||
this.userPlaylists.netease = neUserPL.value.data.playlists ?? [];
|
qqRecPL.status === 'fulfilled' ? (qqRecPL.value.data.playlists ?? []) : [];
|
||||||
}
|
this.dailySongs.qq =
|
||||||
if (qqRecPL.status === 'fulfilled') {
|
qqDaily.status === 'fulfilled' ? (qqDaily.value.data.songs ?? []) : [];
|
||||||
this.recommendPlaylists.qq = qqRecPL.value.data.playlists ?? [];
|
this.userPlaylists.qq =
|
||||||
}
|
qqUserPL.status === 'fulfilled' ? (qqUserPL.value.data.playlists ?? []) : [];
|
||||||
if (qqDaily.status === 'fulfilled') {
|
// bilibili popular: keep previous value on failure (it's an anonymous endpoint
|
||||||
this.dailySongs.qq = qqDaily.value.data.songs ?? [];
|
// unrelated to user auth state, and stale popular results are harmless)
|
||||||
}
|
|
||||||
if (qqUserPL.status === 'fulfilled') {
|
|
||||||
this.userPlaylists.qq = qqUserPL.value.data.playlists ?? [];
|
|
||||||
}
|
|
||||||
if (bili.status === 'fulfilled') {
|
if (bili.status === 'fulfilled') {
|
||||||
this.bilibiliPopular = bili.value.data.songs ?? [];
|
this.bilibiliPopular = bili.value.data.songs ?? [];
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-12
@@ -137,23 +137,15 @@ const USER_PLAYLIST_LIMIT = 20;
|
|||||||
const userPlaylistsExpanded = ref(false);
|
const userPlaylistsExpanded = ref(false);
|
||||||
|
|
||||||
// Available sources per section.
|
// Available sources per section.
|
||||||
|
// Recommend playlists work anonymously on netease, so it's always available;
|
||||||
|
// QQ requires login. This intentionally differs from dailyAvailable/userAvailable.
|
||||||
const recommendAvailable = computed<Source[]>(() => {
|
const recommendAvailable = computed<Source[]>(() => {
|
||||||
const s: Source[] = ['netease'];
|
const s: Source[] = ['netease'];
|
||||||
if (store.authStatus.qq) s.push('qq');
|
if (store.authStatus.qq) s.push('qq');
|
||||||
return s;
|
return s;
|
||||||
});
|
});
|
||||||
const dailyAvailable = computed<Source[]>(() => {
|
const dailyAvailable = computed<Source[]>(() => store.availableSources);
|
||||||
const s: Source[] = [];
|
const userAvailable = computed<Source[]>(() => store.availableSources);
|
||||||
if (store.authStatus.netease) s.push('netease');
|
|
||||||
if (store.authStatus.qq) s.push('qq');
|
|
||||||
return s;
|
|
||||||
});
|
|
||||||
const userAvailable = computed<Source[]>(() => {
|
|
||||||
const s: Source[] = [];
|
|
||||||
if (store.authStatus.netease) s.push('netease');
|
|
||||||
if (store.authStatus.qq) s.push('qq');
|
|
||||||
return s;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Persisted active source per section.
|
// Persisted active source per section.
|
||||||
const recommendSource = ref<Source>(loadTabSource('home.recommend'));
|
const recommendSource = ref<Source>(loadTabSource('home.recommend'));
|
||||||
|
|||||||
@@ -63,12 +63,7 @@ const store = usePlayerStore();
|
|||||||
const history = ref<Song[]>([]);
|
const history = ref<Song[]>([]);
|
||||||
const historyLoading = ref(true);
|
const historyLoading = ref(true);
|
||||||
|
|
||||||
const userAvailable = computed<Source[]>(() => {
|
const userAvailable = computed<Source[]>(() => store.availableSources);
|
||||||
const s: Source[] = [];
|
|
||||||
if (store.authStatus.netease) s.push('netease');
|
|
||||||
if (store.authStatus.qq) s.push('qq');
|
|
||||||
return s;
|
|
||||||
});
|
|
||||||
|
|
||||||
const userSource = ref<Source>(loadTabSource('library.user'));
|
const userSource = ref<Source>(loadTabSource('library.user'));
|
||||||
watch(userSource, (v) => saveTabSource('library.user', v));
|
watch(userSource, (v) => saveTabSource('library.user', v));
|
||||||
|
|||||||
Reference in new issue
Block a user