Skip to content

Commit 880fc88

Browse files
committed
feat(file): 大小写不敏感的 FastGlob
将 FastGlob 的 options 参数提取到了 globOpt 函数,在那里统一设置 在 globOpt 里设置了 `caseSensitiveMatch: false`
1 parent f4c8be7 commit 880fc88

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

electron/main/ipc/ipc-file.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ import { File, Picture, Id3v2Settings } from "node-taglib-sharp";
77
import { ipcLog } from "../logger";
88
import { download } from "electron-dl";
99
import FastGlob from "fast-glob";
10+
import { Options as GlobOptions } from "fast-glob/out/settings";
1011

1112
/**
1213
* 文件相关 IPC
1314
*/
1415
const initFileIpc = (): void => {
16+
const globOpt = (cwd?: string): GlobOptions => ({
17+
cwd,
18+
caseSensitiveMatch: false
19+
});
20+
1521
// 默认文件夹
1622
ipcMain.handle(
1723
"get-default-dir",
@@ -27,7 +33,7 @@ const initFileIpc = (): void => {
2733
const filePath = resolve(dirPath).replace(/\\/g, "/");
2834
console.info(`📂 Fetching music files from: ${filePath}`);
2935
// 查找指定目录下的所有音乐文件
30-
const musicFiles = await FastGlob("**/*.{mp3,wav,flac,aac,webm}", { cwd: filePath });
36+
const musicFiles = await FastGlob("**/*.{mp3,wav,flac,aac,webm}", globOpt(filePath));
3137
// 解析元信息
3238
const metadataPromises = musicFiles.map(async (file) => {
3339
const filePath = join(dirPath, file);
@@ -207,7 +213,7 @@ const initFileIpc = (): void => {
207213
try {
208214
// 查找 ttml
209215
if (!result.ttml) {
210-
const ttmlFiles = await FastGlob(patterns.ttml, { cwd: dir });
216+
const ttmlFiles = await FastGlob(patterns.ttml, globOpt(dir));
211217
if (ttmlFiles.length > 0) {
212218
const filePath = join(dir, ttmlFiles[0]);
213219
await access(filePath);
@@ -217,7 +223,7 @@ const initFileIpc = (): void => {
217223

218224
// 查找 lrc
219225
if (!result.lrc) {
220-
const lrcFiles = await FastGlob(patterns.lrc, { cwd: dir });
226+
const lrcFiles = await FastGlob(patterns.lrc, globOpt(dir));
221227
if (lrcFiles.length > 0) {
222228
const filePath = join(dir, lrcFiles[0]);
223229
await access(filePath);

0 commit comments

Comments
 (0)