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 {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;
}
}

View File

@ -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);
}

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']);
/**
*
* @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;
}

View File

@ -24,7 +24,7 @@
<div style="margin-top: 5px">
<el-button type="primary" size="small" @click="selectAllFiles">反选</el-button>
<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 effect="dark" content="移除(非删除)需要重命名的文件" placement="bottom">
<el-button type="warning" size="small" @click="removeCheckedFiles">移除</el-button>
@ -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);
}
},
};