mirror of
https://github.com/imsyy/SPlayer.git
synced 2026-04-25 15:05:58 +03:00
[GH-ISSUE #505] 网页端更改本地歌曲文件夹代码报错 #274
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @tym2008 on GitHub (Oct 22, 2025).
Original GitHub issue: https://github.com/imsyy/SPlayer/issues/505
是网页端还是客户端
网页端
当前系统环境
CF Pages
当前 Node.js 及 npm 版本
v22
当前版本
v3.0.0-beta4
具体信息
新合并进Pr的代码导致网页端报错
此段代码
@tym2008 commented on GitHub (Oct 22, 2025):
AI改后的代码 改后网页端正常 客户端未测试
`
/**
获取 更改本地目录 函数
@param settingsKey 设置项 key
*...
@param errorMessage 错误信息
@param defaultDirType 【新增】需要动态获取的默认目录类型(如 'music'),仅 Electron 环境有效
*/
const changeLocalPath = (
settingsKey: string,
includeSubFolders: boolean,
errorConsole: string,
errorMessage: string,
defaultDirType?: "music" | "videos" | string, // 接受一个字符串来决定获取哪个目录
) => async (delIndex?: number) => {
try {
// 核心保护:如果不是 Electron 环境,直接静默失败
if (!isElectron) {
window.$message.warning("该功能仅在桌面客户端中可用");
return;
}
const settingStore = useSettingStore();
if (typeof delIndex === "number" && delIndex >= 0) {
settingStore[settingsKey].splice(delIndex, 1);
} else {
const selectedDir = await window.electron.ipcRenderer.invoke("choose-path");
if (!selectedDir) return;
// ----> 主要逻辑修改在这里 <----
// 1. 动态获取默认路径(如果需要)
let defaultPath: string | undefined = undefined;
if (defaultDirType) {
defaultPath = await window.electron.ipcRenderer.invoke("get-default-dir", defaultDirType);
}
// 2. 构建现有路径列表
const allPath = defaultPath ? [defaultPath, ...settingStore[settingsKey]] : settingStore[settingsKey];
if (includeSubFolders) {
const isSubfolder = await window.electron.ipcRenderer.invoke(
"check-if-subfolder",
allPath,
selectedDir,
);
if (!isSubfolder) {
settingStore[settingsKey].push(selectedDir);
} else {
window.$message.error("添加的目录与现有目录有重叠,请重新选择");
}
} else {
if (allPath.includes(selectedDir)) {
window.$message.error("添加的目录已存在");
} else {
settingStore[settingsKey].push(selectedDir);
}
}
}
} catch (error) {
console.error(
${errorConsole}:, error);window.$message.error(errorMessage);
}
};
/**
更改本地音乐目录
@param delIndex 删除文件夹路径的索引
*/
export const changeLocalMusicPath = changeLocalPath(
"localFilesPath", true,
"Error changing local path",
"更改本地歌曲文件夹出错,请重试",
"music"
);
/**
*/
export const changeLocalLyricPath = changeLocalPath(
"localLyricPath", false,
"Error changing local lyric path",
"更改本地歌词文件夹出错,请重试",
);
`