feat:增加优化

This commit is contained in:
fanxb 2023-03-07 20:57:05 +08:00
parent 7ae783caa5
commit e848ecc236
4 changed files with 94 additions and 63 deletions

View File

@ -1,55 +1,71 @@
import * as pathUtil from "path"; import * as pathUtil from "path";
import {isVideo, isSub, isNfo} from "../../util/MediaUtil"
export default class FileObj { export default class FileObj {
/** /**
* *
*/ */
name: string; name: string;
/** /**
*/ */
originName: string; originName: string;
/** /**
* *
*/ */
expandName: string; expandName: string;
/** /**
* *
*/ */
realName: string; realName: string;
/** /**
* *
*/ */
path: string; path: string;
/** /**
* *
*/ */
isFolder: boolean; isFolder: boolean;
/** /**
* *
*/ */
errorMessage: string; size: number;
/** /**
* ms *
*/ */
createdTime: number; errorMessage: string;
/** /**
* ms * ms
*/ */
updatedTime: number; createdTime: number;
/**
* ms
*/
updatedTime: number;
/**
* 广
*/
isAdFile: boolean;
constructor(name: string, path, isFolder, createdTime, updatedTime) { constructor(name: string, path, isFolder, size: number, createdTime, updatedTime) {
this.name = name; this.name = name;
this.originName = name; this.originName = name;
this.expandName = pathUtil.extname(name); this.expandName = pathUtil.extname(name);
if (this.expandName.length > 0) { if (this.expandName.length > 0) {
this.realName = name.substring(0, name.lastIndexOf(".")); this.realName = name.substring(0, name.lastIndexOf("."));
} else { let end = this.expandName.toLowerCase().replace(".", "");
this.realName = name; if (isVideo(end)) {
} this.isAdFile = size < 5 * 1024 * 1024;
this.path = path; } else this.isAdFile = !(isSub(end) || isNfo(end));
this.isFolder = isFolder; } else {
this.createdTime = createdTime; this.realName = name;
this.updatedTime = updatedTime; }
} this.path = path;
this.isFolder = isFolder;
this.size = size;
this.createdTime = createdTime;
this.updatedTime = updatedTime;
}
} }

View File

@ -42,12 +42,12 @@ class FileService {
if (fileList[index].startsWith('.')) { if (fileList[index].startsWith('.')) {
if (showHidden) { if (showHidden) {
(stat.isDirectory() ? folderList : files).push( (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 { } else {
(stat.isDirectory() ? folderList : files).push( (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) { } catch (e) {
@ -82,7 +82,7 @@ class FileService {
let filePath = path.join(file.path, file.name); let filePath = path.join(file.path, file.name);
let temp = (await fs.readdir(filePath)).map(item => { let temp = (await fs.readdir(filePath)).map(item => {
let stat = fs.statSync(path.join(filePath, 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); await FileService.readDirRecursion(res, temp, depth + 1);
} }

View File

@ -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']); 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 * @param str
*/ */
export function isVideo(str: string) { export function isVideo(str: string) {
if (!str) { if (!str) {
return false; return false;
} }
return videoSet.has(str.toLowerCase()); return videoSet.has(str.toLowerCase());
} }
const subSet = new Set(['sub', 'sst', 'son', 'srt', 'ssa', 'ass', 'smi', 'psb', 'pjs', 'stl', 'tts', 'vsf', 'zeg']); const subSet = new Set(['sub', 'sst', 'son', 'srt', 'ssa', 'ass', 'smi', 'psb', 'pjs', 'stl', 'tts', 'vsf', 'zeg']);
/** /**
* *
* @param str * @param str
*/ */
export function isSub(str: string) { export function isSub(str: string) {
if (!str) { if (!str) {
return false; return false;
} }
return subSet.has(str.toLowerCase()); return subSet.has(str.toLowerCase());
}
/**
*
* @param str
*/
export function isNfo(str: string) {
if (!str) {
return false;
}
return "nfo" == str;
} }

View File

@ -24,7 +24,7 @@
<div style="margin-top: 5px"> <div style="margin-top: 5px">
<el-button type="primary" size="small" @click="selectAllFiles">反选</el-button> <el-button type="primary" size="small" @click="selectAllFiles">反选</el-button>
<el-tooltip effect="dark" content="一键选中所有的非视频、字幕文件和小于5MB的视频文件" placement="bottom"> <el-tooltip effect="dark" content="一键选中所有的非视频、字幕文件和小于5MB的视频文件" placement="bottom">
<el-button type="success" size="small" @click="">一键选择</el-button> <el-button type="success" size="small" @click="choseAdFile">一键选择</el-button>
</el-tooltip> </el-tooltip>
<el-tooltip effect="dark" content="移除(非删除)需要重命名的文件" placement="bottom"> <el-tooltip effect="dark" content="移除(非删除)需要重命名的文件" placement="bottom">
<el-button type="warning" size="small" @click="removeCheckedFiles">移除</el-button> <el-button type="warning" size="small" @click="removeCheckedFiles">移除</el-button>
@ -199,7 +199,6 @@ export default {
this.newName = list[0].name; this.newName = list[0].name;
this.currentEditFile = list[0]; this.currentEditFile = list[0];
this.showNameEditDialog = true; this.showNameEditDialog = true;
await this.showResult();
}, },
async doEditFile() { async doEditFile() {
if (!this.newName) { if (!this.newName) {
@ -282,6 +281,9 @@ export default {
async refreshSavePathList() { async refreshSavePathList() {
this.savePathList = await HttpUtil.get("/file/path"); this.savePathList = await HttpUtil.get("/file/path");
}, },
async choseAdFile() {
this.fileList.forEach(item => item.checked = item.isAdFile);
}
}, },
}; };