feat:增加优化
This commit is contained in:
parent
7ae783caa5
commit
e848ecc236
@ -1,4 +1,6 @@
|
||||
import * as pathUtil from "path";
|
||||
import {isVideo, isSub, isNfo} from "../../util/MediaUtil"
|
||||
|
||||
export default class FileObj {
|
||||
/**
|
||||
* 文件名
|
||||
@ -24,6 +26,10 @@ export default class FileObj {
|
||||
* 是否文件夹
|
||||
*/
|
||||
isFolder: boolean;
|
||||
/**
|
||||
* 文件大小
|
||||
*/
|
||||
size: number;
|
||||
/**
|
||||
* 重命名错误原因
|
||||
*/
|
||||
@ -36,20 +42,30 @@ export default class FileObj {
|
||||
* 更新时间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.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;
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
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 文件后缀
|
||||
@ -11,6 +12,7 @@ export function isVideo(str: string) {
|
||||
}
|
||||
|
||||
const subSet = new Set(['sub', 'sst', 'son', 'srt', 'ssa', 'ass', 'smi', 'psb', 'pjs', 'stl', 'tts', 'vsf', 'zeg']);
|
||||
|
||||
/**
|
||||
* 判断文件是否为字幕文件
|
||||
* @param str 文件后缀
|
||||
@ -21,3 +23,14 @@ export function isSub(str: string) {
|
||||
}
|
||||
return subSet.has(str.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断文件是否为字幕文件
|
||||
* @param str 文件后缀
|
||||
*/
|
||||
export function isNfo(str: string) {
|
||||
if (!str) {
|
||||
return false;
|
||||
}
|
||||
return "nfo" == str;
|
||||
}
|
@ -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);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user