From e848ecc2360465d9fb35b357fa9628004434cbc7 Mon Sep 17 00:00:00 2001 From: fanxb Date: Tue, 7 Mar 2023 20:57:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openRenamerBackend/entity/vo/FileObj.ts | 116 ++++++++++++---------- openRenamerBackend/service/FileService.ts | 6 +- openRenamerBackend/util/MediaUtil.ts | 29 ++++-- openRenamerFront/src/views/home/Home.vue | 6 +- 4 files changed, 94 insertions(+), 63 deletions(-) diff --git a/openRenamerBackend/entity/vo/FileObj.ts b/openRenamerBackend/entity/vo/FileObj.ts index 4246849..473cb2f 100644 --- a/openRenamerBackend/entity/vo/FileObj.ts +++ b/openRenamerBackend/entity/vo/FileObj.ts @@ -1,55 +1,71 @@ import * as pathUtil from "path"; +import {isVideo, isSub, isNfo} from "../../util/MediaUtil" + export default class FileObj { - /** - * 文件名 - */ - name: string; - /** - 原始名字 - */ - originName: string; - /** - * 拓展名 - */ - expandName: string; - /** - * 去掉拓展名后的名字 - */ - realName: string; - /** - * 所属路径 - */ - path: string; - /** - * 是否文件夹 - */ - isFolder: boolean; - /** - * 重命名错误原因 - */ - errorMessage: string; - /** - * 创建时间ms - */ - createdTime: number; - /** - * 更新时间ms - */ - updatedTime: number; + /** + * 文件名 + */ + name: string; + /** + 原始名字 + */ + originName: string; + /** + * 拓展名 + */ + expandName: string; + /** + * 去掉拓展名后的名字 + */ + realName: string; + /** + * 所属路径 + */ + path: string; + /** + * 是否文件夹 + */ + isFolder: boolean; + /** + * 文件大小 + */ + size: number; + /** + * 重命名错误原因 + */ + errorMessage: string; + /** + * 创建时间ms + */ + createdTime: number; + /** + * 更新时间ms + */ + updatedTime: number; + /** + * 是否广告文件 + */ + isAdFile: boolean; - constructor(name: string, path, isFolder, createdTime, updatedTime) { - this.name = name; - this.originName = name; - this.expandName = pathUtil.extname(name); - if (this.expandName.length > 0) { - this.realName = name.substring(0, name.lastIndexOf(".")); - } else { - this.realName = name; - } - this.path = path; - this.isFolder = isFolder; - this.createdTime = createdTime; - this.updatedTime = updatedTime; - } + constructor(name: string, path, isFolder, size: number, createdTime, updatedTime) { + this.name = name; + this.originName = name; + this.expandName = pathUtil.extname(name); + if (this.expandName.length > 0) { + this.realName = name.substring(0, name.lastIndexOf(".")); + let end = this.expandName.toLowerCase().replace(".", ""); + if (isVideo(end)) { + this.isAdFile = size < 5 * 1024 * 1024; + } else this.isAdFile = !(isSub(end) || isNfo(end)); + } else { + this.realName = name; + } + this.path = path; + this.isFolder = isFolder; + this.size = size; + this.createdTime = createdTime; + this.updatedTime = updatedTime; + + } } \ No newline at end of file diff --git a/openRenamerBackend/service/FileService.ts b/openRenamerBackend/service/FileService.ts index fde1eb3..9467a05 100644 --- a/openRenamerBackend/service/FileService.ts +++ b/openRenamerBackend/service/FileService.ts @@ -42,12 +42,12 @@ class FileService { if (fileList[index].startsWith('.')) { if (showHidden) { (stat.isDirectory() ? folderList : files).push( - new FileObj(fileList[index], pathStr, stat.isDirectory(), stat.birthtime.getTime(), stat.mtime.getTime()), + new FileObj(fileList[index], pathStr, stat.isDirectory(), stat.size, stat.birthtime.getTime(), stat.mtime.getTime()), ); } } else { (stat.isDirectory() ? folderList : files).push( - new FileObj(fileList[index], pathStr, stat.isDirectory(), stat.birthtime.getTime(), stat.mtime.getTime()), + new FileObj(fileList[index], pathStr, stat.isDirectory(), stat.size, stat.birthtime.getTime(), stat.mtime.getTime()), ); } } catch (e) { @@ -82,7 +82,7 @@ class FileService { let filePath = path.join(file.path, file.name); let temp = (await fs.readdir(filePath)).map(item => { let stat = fs.statSync(path.join(filePath, item)); - return new FileObj(item, filePath, stat.isDirectory(), stat.birthtime.getTime(), stat.mtime.getTime()); + return new FileObj(item, filePath, stat.isDirectory(), stat.size, stat.birthtime.getTime(), stat.mtime.getTime()); }); await FileService.readDirRecursion(res, temp, depth + 1); } diff --git a/openRenamerBackend/util/MediaUtil.ts b/openRenamerBackend/util/MediaUtil.ts index 4303aca..236d751 100644 --- a/openRenamerBackend/util/MediaUtil.ts +++ b/openRenamerBackend/util/MediaUtil.ts @@ -1,23 +1,36 @@ const videoSet = new Set(["flv", 'avi', 'wmv', 'dat', 'vob', 'mpg', 'mpeg', 'mp4', '3gp', '3g2', 'mkv', 'rm', 'rmvb', 'mov', 'qt', 'ogg', 'ogv', 'oga', 'mod']); + /** * 判断文件后缀是否为视频类型 * @param str 文件后缀 */ export function isVideo(str: string) { - if (!str) { - return false; - } - return videoSet.has(str.toLowerCase()); + if (!str) { + return false; + } + return videoSet.has(str.toLowerCase()); } const subSet = new Set(['sub', 'sst', 'son', 'srt', 'ssa', 'ass', 'smi', 'psb', 'pjs', 'stl', 'tts', 'vsf', 'zeg']); + /** * 判断文件是否为字幕文件 * @param str 文件后缀 */ export function isSub(str: string) { - if (!str) { - return false; - } - return subSet.has(str.toLowerCase()); + if (!str) { + return false; + } + return subSet.has(str.toLowerCase()); +} + +/** + * 判断文件是否为字幕文件 + * @param str 文件后缀 + */ +export function isNfo(str: string) { + if (!str) { + return false; + } + return "nfo" == str; } \ No newline at end of file diff --git a/openRenamerFront/src/views/home/Home.vue b/openRenamerFront/src/views/home/Home.vue index dfe8ad0..79154d6 100644 --- a/openRenamerFront/src/views/home/Home.vue +++ b/openRenamerFront/src/views/home/Home.vue @@ -24,7 +24,7 @@
反选 - 一键选择 + 一键选择 移除 @@ -199,7 +199,6 @@ export default { this.newName = list[0].name; this.currentEditFile = list[0]; this.showNameEditDialog = true; - await this.showResult(); }, async doEditFile() { if (!this.newName) { @@ -282,6 +281,9 @@ export default { async refreshSavePathList() { this.savePathList = await HttpUtil.get("/file/path"); }, + async choseAdFile() { + this.fileList.forEach(item => item.checked = item.isAdFile); + } }, };