Fix/improve file utils (#3116)
* Enhance update error logging and fix duplicate type import - Improve error logging in AppUpdater with more detailed error information and timestamps - Remove duplicate MCPServer type import in Inputbar component * fix: ensure directory existence and optimize file operations
This commit is contained in:
parent
7ce55cf90f
commit
7fb6fcdeeb
@ -6,14 +6,24 @@ import { FileType, FileTypes } from '@types'
|
||||
import { app } from 'electron'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
// 创建文件类型映射表,提高查找效率
|
||||
const fileTypeMap = new Map<string, FileTypes>()
|
||||
|
||||
// 初始化映射表
|
||||
function initFileTypeMap() {
|
||||
imageExts.forEach((ext) => fileTypeMap.set(ext, FileTypes.IMAGE))
|
||||
videoExts.forEach((ext) => fileTypeMap.set(ext, FileTypes.VIDEO))
|
||||
audioExts.forEach((ext) => fileTypeMap.set(ext, FileTypes.AUDIO))
|
||||
textExts.forEach((ext) => fileTypeMap.set(ext, FileTypes.TEXT))
|
||||
documentExts.forEach((ext) => fileTypeMap.set(ext, FileTypes.DOCUMENT))
|
||||
}
|
||||
|
||||
// 初始化映射表
|
||||
initFileTypeMap()
|
||||
|
||||
export function getFileType(ext: string): FileTypes {
|
||||
ext = ext.toLowerCase()
|
||||
if (imageExts.includes(ext)) return FileTypes.IMAGE
|
||||
if (videoExts.includes(ext)) return FileTypes.VIDEO
|
||||
if (audioExts.includes(ext)) return FileTypes.AUDIO
|
||||
if (textExts.includes(ext)) return FileTypes.TEXT
|
||||
if (documentExts.includes(ext)) return FileTypes.DOCUMENT
|
||||
return FileTypes.OTHER
|
||||
return fileTypeMap.get(ext) || FileTypes.OTHER
|
||||
}
|
||||
|
||||
export function getAllFiles(dirPath: string, arrayOfFiles: FileType[] = []): FileType[] {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user