"feat: 同步功能增强与配置优化,支持多类型同步及日志分级"
This commit is contained in:
		| @@ -1,11 +1,26 @@ | ||||
| import fs from 'fs'; | ||||
| export const fileIsExist = (filePath: string, isFile = false) => { | ||||
| import fs from 'node:fs'; | ||||
|  | ||||
| export const fileIsExist = (filePath: string) => { | ||||
|   try { | ||||
|     // 检查文件或者目录是否存在 | ||||
|     fs.accessSync(filePath, fs.constants.F_OK); | ||||
|     if (isFile) { | ||||
|       fs.accessSync(filePath, fs.constants.R_OK); | ||||
|     } | ||||
|     return true; | ||||
|   } catch (error) { | ||||
|     return false; | ||||
|   } | ||||
| }; | ||||
| export const pathExists = (path: string, type?: 'file' | 'directory') => { | ||||
|   try { | ||||
|     // 检查路径是否存在 | ||||
|     fs.accessSync(path, fs.constants.F_OK); | ||||
|  | ||||
|     // 如果需要检查类型 | ||||
|     if (type) { | ||||
|       const stats = fs.statSync(path); | ||||
|       if (type === 'file' && !stats.isFile()) return false; | ||||
|       if (type === 'directory' && !stats.isDirectory()) return false; | ||||
|     } | ||||
|  | ||||
|     return true; | ||||
|   } catch (error) { | ||||
|     return false; | ||||
|   | ||||
| @@ -2,6 +2,7 @@ import MD5 from 'crypto-js/md5.js'; | ||||
| import fs from 'node:fs'; | ||||
|  | ||||
| export const getHash = (file: string) => { | ||||
|   if (!fs.existsSync(file)) return ''; | ||||
|   const content = fs.readFileSync(file, 'utf-8'); | ||||
|   return MD5(content).toString(); | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user