修改了代理

This commit is contained in:
史悦
2026-01-14 18:09:16 +08:00
parent 99d71f05cf
commit 54d97beb15
2 changed files with 45 additions and 53 deletions

View File

@@ -140,7 +140,7 @@
// Use relative path for API proxy to avoid CORS issues
// Nginx forwards /api/ to sync-server, which proxies /music-api to music-dl.sayqz.com
const API_BASE = "/music-api";
const API_BASE = "/api/music-api";
// Use relative path for sync service, assuming Nginx proxy is configured to forward /api/kv to the sync service
const SYNC_API_BASE = "/api";
@@ -270,15 +270,8 @@
return { results: [], total: 0 };
}
},
getSongUrl:async (id, source, br = '320k') => {
try {
const res = await fetch(`${API_BASE}?source=${source}&id=${id}&type=url&br=${br}`);
const data = await res.json();
return data.url;
} catch (e) {
console.error("Get song url failed", e);
return null;
}
getSongUrl: (id, source, br = '320k') => {
return `${API_BASE}?source=${source}&id=${id}&type=url&br=${br}`;
},
getPicUrl: (id, source) => {
return `${API_BASE}?source=${source}&id=${id}&type=pic`;
@@ -1277,43 +1270,31 @@
}, [playlist, currentSong, mode, volume, quality]);
useEffect(() => {
let isMounted = true;
if (currentSong) {
const audio = audioRef.current;
if (!audio) return;
const fetchAndPlay = async () => {
// Update URL when quality changes or song changes
const url = await api.getSongUrl(currentSong.id, currentSong.platform || currentSong.source, quality);
if (!isMounted || !url) return;
// Check if song changed while fetching
if (currentSongRef.current?.id !== currentSong.id) return;
// Only update src if it's different to avoid reloading same song on re-render (unless quality changed)
// Note: audioRef.current.src returns full absolute URL
const currentSrc = audio.src;
const wasPlaying = isPlaying;
const deferOnIOS = autoNextPendingRef.current;
autoNextPendingRef.current = false;
// Simple check if src changed significantly (avoiding minor encoding diffs if possible, but exact match is safer)
if (currentSrc !== url) {
audio.src = url;
if (wasPlaying) {
playAudioWithFallback(audio, { deferOnIOS });
}
} else if (deferOnIOS && wasPlaying) {
playAudioWithFallback(audio, { deferOnIOS: true });
}
};
// Update URL when quality changes or song changes
const url = api.getSongUrl(currentSong.id, currentSong.platform || currentSong.source, quality);
fetchAndPlay();
// Only update src if it's different to avoid reloading same song on re-render (unless quality changed)
// Note: audioRef.current.src returns full absolute URL
const currentSrc = audio.src;
const wasPlaying = isPlaying;
const deferOnIOS = autoNextPendingRef.current;
autoNextPendingRef.current = false;
// Simple check if src changed significantly (avoiding minor encoding diffs if possible, but exact match is safer)
if (currentSrc !== url) {
audio.src = url;
if (wasPlaying) {
playAudioWithFallback(audio, { deferOnIOS });
}
} else if (deferOnIOS && wasPlaying) {
playAudioWithFallback(audio, { deferOnIOS: true });
}
} else {
autoNextPendingRef.current = false;
}
return () => { isMounted = false; };
}, [currentSong, quality]); // Re-run when quality changes
useEffect(() => {
@@ -1429,16 +1410,11 @@
if (options.immediate) {
const audio = audioRef.current;
if (!audio || !nextSong) return;
api.getSongUrl(nextSong.id, nextSong.platform || nextSong.source, quality).then(url => {
if (!url) return;
// Ensure we are still trying to play the same song
if (currentSongRef.current?.id === nextSong.id) {
if (audio.src !== url) {
audio.src = url;
}
playAudioWithFallback(audio, { deferOnIOS: options.deferOnIOS });
}
});
const url = api.getSongUrl(nextSong.id, nextSong.platform || nextSong.source, quality);
if (audio.src !== url) {
audio.src = url;
}
playAudioWithFallback(audio, { deferOnIOS: options.deferOnIOS });
}
};