mirror of
https://github.com/imsyy/SPlayer.git
synced 2025-11-25 03:14:57 +08:00
feat(file): 大小写不敏感的 FastGlob
将 FastGlob 的 options 参数提取到了 globOpt 函数,在那里统一设置 在 globOpt 里设置了 `caseSensitiveMatch: false`
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user