mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-11 01:12:49 +08:00
fix: honor artist shuffle permissions and discard stale page requests
This commit is contained in:
1 parent
9bcddb1881
commit
d16aca2ba6
1 file changed
+17
-4
@@ -46,7 +46,7 @@
|
|||||||
播放
|
播放
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
v-if="canPlayAll"
|
v-if="canShuffle"
|
||||||
class="shuffle-btn"
|
class="shuffle-btn"
|
||||||
:disabled="!artist"
|
:disabled="!artist"
|
||||||
title="随机播放该歌手的全部歌曲"
|
title="随机播放该歌手的全部歌曲"
|
||||||
@@ -139,12 +139,16 @@ const { can, guestCan } = useSession();
|
|||||||
// Same permission as "play all" on a playlist: members need player.control,
|
// Same permission as "play all" on a playlist: members need player.control,
|
||||||
// guests need the playCollection flag.
|
// guests need the playCollection flag.
|
||||||
const canPlayAll = computed(() => can('player.control') || guestCan('playCollection'));
|
const canPlayAll = computed(() => can('player.control') || guestCan('playCollection'));
|
||||||
|
const canShuffle = computed(() =>
|
||||||
|
canPlayAll.value && (can('player.control') || guestCan('playMode')),
|
||||||
|
);
|
||||||
|
|
||||||
const artist = ref<ArtistDetail | null>(null);
|
const artist = ref<ArtistDetail | null>(null);
|
||||||
const hotSongs = ref<Song[]>([]);
|
const hotSongs = ref<Song[]>([]);
|
||||||
const albums = ref<Album[]>([]);
|
const albums = ref<Album[]>([]);
|
||||||
const loading = ref(true);
|
const loading = ref(true);
|
||||||
const expanded = ref(false);
|
const expanded = ref(false);
|
||||||
|
let artistRequest = 0;
|
||||||
|
|
||||||
const platform = computed(() => (route.query.platform as string) || 'netease');
|
const platform = computed(() => (route.query.platform as string) || 'netease');
|
||||||
const platformLabel = computed(() => (platform.value === 'qq' ? 'QQ 音乐' : '网易云音乐'));
|
const platformLabel = computed(() => (platform.value === 'qq' ? 'QQ 音乐' : '网易云音乐'));
|
||||||
@@ -164,13 +168,19 @@ async function playAll() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function shuffleAll() {
|
async function shuffleAll() {
|
||||||
|
if (!canShuffle.value) return;
|
||||||
// Shuffle reuses the queue's own random mode (the same switch the player
|
// Shuffle reuses the queue's own random mode (the same switch the player
|
||||||
// toolbar exposes), so the play button and the mode badge stay consistent.
|
// toolbar exposes), so the play button and the mode badge stay consistent.
|
||||||
await store.setMode('random');
|
try {
|
||||||
await store.playArtist(artistId(), platform.value);
|
await store.setMode('random');
|
||||||
|
await store.playArtist(artistId(), platform.value);
|
||||||
|
} catch (err: any) {
|
||||||
|
store.notify(err?.response?.status === 403 ? '没有权限切换随机播放' : '切换随机播放失败', 'error');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadArtist() {
|
async function loadArtist() {
|
||||||
|
const request = ++artistRequest;
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
// Reset every per-artist piece: RouterView reuses this component when only the
|
// Reset every per-artist piece: RouterView reuses this component when only the
|
||||||
// route params change, so artist → artist navigation must not show stale rows.
|
// route params change, so artist → artist navigation must not show stale rows.
|
||||||
@@ -182,13 +192,16 @@ async function loadArtist() {
|
|||||||
const res = await axios.get(`/api/music/artist/${artistId()}`, {
|
const res = await axios.get(`/api/music/artist/${artistId()}`, {
|
||||||
params: { platform: platform.value },
|
params: { platform: platform.value },
|
||||||
});
|
});
|
||||||
|
if (request !== artistRequest) return;
|
||||||
artist.value = res.data?.artist ?? null;
|
artist.value = res.data?.artist ?? null;
|
||||||
hotSongs.value = res.data?.songs ?? [];
|
hotSongs.value = res.data?.songs ?? [];
|
||||||
albums.value = res.data?.albums ?? [];
|
albums.value = res.data?.albums ?? [];
|
||||||
} catch {
|
} catch {
|
||||||
|
if (request !== artistRequest) return;
|
||||||
artist.value = null;
|
artist.value = null;
|
||||||
|
} finally {
|
||||||
|
if (request === artistRequest) loading.value = false;
|
||||||
}
|
}
|
||||||
loading.value = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(loadArtist);
|
onMounted(loadArtist);
|
||||||
|
|||||||
Reference in new issue
Block a user