From 880fc888e60aced51ea0991b6281a3f152203b02 Mon Sep 17 00:00:00 2001 From: MoYingJi Date: Mon, 24 Nov 2025 13:34:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(file):=20=E5=A4=A7=E5=B0=8F=E5=86=99?= =?UTF-8?q?=E4=B8=8D=E6=95=8F=E6=84=9F=E7=9A=84=20FastGlob?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 FastGlob 的 options 参数提取到了 globOpt 函数,在那里统一设置 在 globOpt 里设置了 `caseSensitiveMatch: false` --- electron/main/ipc/ipc-file.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/electron/main/ipc/ipc-file.ts b/electron/main/ipc/ipc-file.ts index e8de5cc..97a2bb0 100644 --- a/electron/main/ipc/ipc-file.ts +++ b/electron/main/ipc/ipc-file.ts @@ -7,11 +7,17 @@ import { File, Picture, Id3v2Settings } from "node-taglib-sharp"; import { ipcLog } from "../logger"; import { download } from "electron-dl"; import FastGlob from "fast-glob"; +import { Options as GlobOptions } from "fast-glob/out/settings"; /** * 文件相关 IPC */ const initFileIpc = (): void => { + const globOpt = (cwd?: string): GlobOptions => ({ + cwd, + caseSensitiveMatch: false + }); + // 默认文件夹 ipcMain.handle( "get-default-dir", @@ -27,7 +33,7 @@ const initFileIpc = (): void => { const filePath = resolve(dirPath).replace(/\\/g, "/"); console.info(`📂 Fetching music files from: ${filePath}`); // 查找指定目录下的所有音乐文件 - const musicFiles = await FastGlob("**/*.{mp3,wav,flac,aac,webm}", { cwd: filePath }); + const musicFiles = await FastGlob("**/*.{mp3,wav,flac,aac,webm}", globOpt(filePath)); // 解析元信息 const metadataPromises = musicFiles.map(async (file) => { const filePath = join(dirPath, file); @@ -207,7 +213,7 @@ const initFileIpc = (): void => { try { // 查找 ttml if (!result.ttml) { - const ttmlFiles = await FastGlob(patterns.ttml, { cwd: dir }); + const ttmlFiles = await FastGlob(patterns.ttml, globOpt(dir)); if (ttmlFiles.length > 0) { const filePath = join(dir, ttmlFiles[0]); await access(filePath); @@ -217,7 +223,7 @@ const initFileIpc = (): void => { // 查找 lrc if (!result.lrc) { - const lrcFiles = await FastGlob(patterns.lrc, { cwd: dir }); + const lrcFiles = await FastGlob(patterns.lrc, globOpt(dir)); if (lrcFiles.length > 0) { const filePath = join(dir, lrcFiles[0]); await access(filePath); From c6f0d0b75a4f75a5fdca44987a3539d27880c1fe Mon Sep 17 00:00:00 2001 From: imsyy Date: Mon, 24 Nov 2025 15:24:54 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=AD=8C=E8=AF=8D?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8D=E5=8C=BA=E5=88=86=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main/ipc/ipc-file.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/electron/main/ipc/ipc-file.ts b/electron/main/ipc/ipc-file.ts index 97a2bb0..2b76b62 100644 --- a/electron/main/ipc/ipc-file.ts +++ b/electron/main/ipc/ipc-file.ts @@ -6,16 +6,20 @@ import { getFileID, getFileMD5, metaDataLyricsArrayToLrc } from "../utils/helper import { File, Picture, Id3v2Settings } from "node-taglib-sharp"; import { ipcLog } from "../logger"; import { download } from "electron-dl"; -import FastGlob from "fast-glob"; import { Options as GlobOptions } from "fast-glob/out/settings"; +import FastGlob from "fast-glob"; /** * 文件相关 IPC */ const initFileIpc = (): void => { + /** + * 获取全局搜索配置 + * @param cwd 当前工作目录 + */ const globOpt = (cwd?: string): GlobOptions => ({ cwd, - caseSensitiveMatch: false + caseSensitiveMatch: false, }); // 默认文件夹 @@ -133,23 +137,25 @@ const initFileIpc = (): void => { }> => { try { const filePath = resolve(path).replace(/\\/g, "/"); - const { common } = await parseFile(filePath); // 尝试获取同名的歌词文件 const filePathWithoutExt = filePath.replace(/\.[^.]+$/, ""); for (const ext of ["ttml", "lrc"] as const) { const lyricPath = `${filePathWithoutExt}.${ext}`; - ipcLog.info("lyricPath", lyricPath); - try { - await access(lyricPath); - const lyric = await readFile(lyricPath, "utf-8"); - if (lyric && lyric != "") return { lyric, format: ext }; - } catch { - /* empty */ + const matches = await FastGlob(lyricPath, globOpt()); + ipcLog.info("lyric matches", matches); + if (matches.length > 0) { + try { + const lyric = await readFile(matches[0], "utf-8"); + if (lyric && lyric !== "") return { lyric, format: ext }; + } catch { + /* empty */ + } } } // 尝试获取元数据 + const { common } = await parseFile(filePath); const lyric = common?.lyrics?.[0]?.syncText; if (lyric && lyric.length > 0) { return { lyric: metaDataLyricsArrayToLrc(lyric), format: "lrc" };