修复音乐界面添加重复歌单报错
This commit is contained in:
+11
-2
@@ -15,6 +15,15 @@ const SPECTRUM_REFERENCE_VOLUME = 10;
|
||||
const SPECTRUM_MIN_VOLUME = 5;
|
||||
const SPECTRUM_MAX_REFERENCE_VOLUME = 15;
|
||||
|
||||
function getApiErrorMessage(error: unknown, fallback: string): string {
|
||||
if (typeof error === 'string') return error;
|
||||
if (error && typeof error === 'object' && 'message' in error) {
|
||||
const message = (error as { message?: unknown }).message;
|
||||
if (typeof message === 'string' && message.trim()) return message;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
type MusicSource = 'wy' | 'tx' | 'kw' | 'kg' | 'mg';
|
||||
type MusicQuality = '128k' | '320k' | 'flac' | 'flac24bit';
|
||||
|
||||
@@ -1164,7 +1173,7 @@ export default function MusicPage() {
|
||||
} else {
|
||||
const data = await response.json();
|
||||
setToast({
|
||||
message: data.error || '删除失败',
|
||||
message: getApiErrorMessage(data.error, '删除失败'),
|
||||
type: 'error',
|
||||
onClose: () => setToast(null),
|
||||
});
|
||||
@@ -1217,7 +1226,7 @@ export default function MusicPage() {
|
||||
} else {
|
||||
const data = await response.json();
|
||||
setToast({
|
||||
message: data.error || '移除失败',
|
||||
message: getApiErrorMessage(data.error, '移除失败'),
|
||||
type: 'error',
|
||||
onClose: () => setToast(null),
|
||||
});
|
||||
|
||||
@@ -31,6 +31,15 @@ interface AddToPlaylistModalProps {
|
||||
onError?: (message: string) => void;
|
||||
}
|
||||
|
||||
function getApiErrorMessage(error: unknown, fallback: string): string {
|
||||
if (typeof error === 'string') return error;
|
||||
if (error && typeof error === 'object' && 'message' in error) {
|
||||
const message = (error as { message?: unknown }).message;
|
||||
if (typeof message === 'string' && message.trim()) return message;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
function MusicLoadingIndicator({
|
||||
text,
|
||||
size = 'md',
|
||||
@@ -139,7 +148,7 @@ export default function AddToPlaylistModal({
|
||||
await loadPlaylists();
|
||||
} else {
|
||||
const data = await response.json();
|
||||
onError?.(data.error || '创建歌单失败');
|
||||
onError?.(getApiErrorMessage(data.error, '创建歌单失败'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('创建歌单失败:', error);
|
||||
@@ -175,7 +184,7 @@ export default function AddToPlaylistModal({
|
||||
onClose();
|
||||
} else {
|
||||
const data = await response.json();
|
||||
onError?.(data.error || '添加失败');
|
||||
onError?.(getApiErrorMessage(data.error, '添加失败'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('添加到歌单失败:', error);
|
||||
|
||||
Reference in New Issue
Block a user