This commit is contained in:
fanxb 2023-01-12 22:55:40 +08:00
parent f9a546cb97
commit 40b363c3e5
6 changed files with 142 additions and 28 deletions

View File

@ -0,0 +1,49 @@
import { Context } from "koa";
import FileService from "../service/FileService";
import config from "../config";
const router = {};
/**
*
*/
router["GET /file/query"] = async function (ctx: Context) {
ctx.body = await FileService.readPath(ctx.query.path as string, ctx.query.showHidden === '1');
};
/**
*windows
*/
router['GET /file/isWindows'] = async function (ctx: Context) {
ctx.body = config.isWindows;
}
/**
*
*/
router["GET /file/path/exist"] = async function (ctx: Context) {
ctx.body = await FileService.checkExist(ctx.query.path as string);
};
/**
*
*/
router["POST /file/path/save"] = async function (ctx: Context) {
ctx.body = await FileService.savePath(ctx.request.body);
};
/**
*
*/
router["GET /file/path"] = async function (ctx: Context) {
ctx.body = await FileService.getSaveList();
};
/**
*
*/
router["DELETE /file/path/delete"] = async function (ctx: Context) {
ctx.body = await FileService.deleteOne(ctx.query.id);
};
export default router;

View File

@ -0,0 +1,9 @@
export default interface AutoPlanConfigDto {
paths: Array<string>,
version: Number,
ignoreSeason0: Boolean,
ignorePaths: Array<string>,
deleteSmallVideo: boolean,
rules: Array<string>,
start: boolean
}

View File

@ -0,0 +1,34 @@
import config from '../config';
import * as path from 'path';
import * as fs from 'fs-extra';
import ProcessHelper from '../util/ProcesHelper';
import FileObj from '../entity/vo/FileObj';
import SavePathDao from '../dao/SavePathDao';
import SavePath from '../entity/po/SavePath';
import AutoPlanConfigDto from '../entity/dto/AutoPlanConfigDto';
import GlobalConfig from 'entity/po/GlobalConfig';
import GlobalConfigService from './GlobalConfigService';
const autoConfigCode = "autoConfig";
class AutoPlanService {
/**
*
*/
static async saveAutoConfig(body: AutoPlanConfigDto): Promise<void> {
let configBody: GlobalConfig = {
code: autoConfigCode,
val: JSON.stringify(body),
description: "自动化计划配置"
};
await GlobalConfigService.insertOrReplace(configBody);
if (!body.start) {
return;
}
let old = await GlobalConfigService.getVal(autoConfigCode);
if (old && old.length)
}
}
export default AutoPlanService;

View File

@ -4,7 +4,7 @@
<el-menu-item :disabled="editRule != null" index="insert">插入</el-menu-item> <el-menu-item :disabled="editRule != null" index="insert">插入</el-menu-item>
<el-menu-item :disabled="editRule != null" index="delete">删除</el-menu-item> <el-menu-item :disabled="editRule != null" index="delete">删除</el-menu-item>
<!-- <el-menu-item index="replace">替换</el-menu-item> --> <!-- <el-menu-item index="replace">替换</el-menu-item> -->
<el-menu-item :disabled="editRule != null" index="serialization">序列化</el-menu-item> <el-menu-item :disabled="editRule != null || isAutoPlan" index="serialization">序列化</el-menu-item>
<el-menu-item :disabled="editRule != null" index="auto">自动识别</el-menu-item> <el-menu-item :disabled="editRule != null" index="auto">自动识别</el-menu-item>
</el-menu> </el-menu>
<div class="rule"> <div class="rule">
@ -26,25 +26,25 @@ import SerializationRule from "./rules/SerializationRule.vue";
import AutoRule from "./rules/AutoRule"; import AutoRule from "./rules/AutoRule";
export default { export default {
components: { InsertRule, DeleteRule, SerializationRule, AutoRule }, components: { InsertRule, DeleteRule, SerializationRule, AutoRule },
props: ["editRule"], props: ["editRule", "isAutoPlan"],
emits: ["ruleAdd"], emits: ["ruleAdd"],
name: "Rule", name: "Rule",
data() { data () {
return { return {
currentIndex: "insert", currentIndex: "insert",
options: [{ label: "插入", value: "insert" }], options: [{ label: "插入", value: "insert" }],
}; };
}, },
created() { created () {
if (this.editRule) { if (this.editRule) {
this.currentIndex = this.editRule.type; this.currentIndex = this.editRule.type;
} }
}, },
methods: { methods: {
menuChange(index) { menuChange (index) {
this.currentIndex = index; this.currentIndex = index;
}, },
submit() { submit () {
let data = this.$refs["rule"].exportObj(); let data = this.$refs["rule"].exportObj();
if (data != null) { if (data != null) {
this.$emit("ruleAdd", data); this.$emit("ruleAdd", data);

View File

@ -38,8 +38,8 @@
<el-button type="primary" size="small" text @click="addRuleDialogShow = true">+ 新增规则</el-button> <el-button type="primary" size="small" text @click="addRuleDialogShow = true">+ 新增规则</el-button>
</div> </div>
</div> </div>
<el-dialog title="新增规则" v-model="addRuleDialogShow" width="70%" @close="ruleDialogClose"> <el-dialog :title="editRule ? '编辑规则' : '新增规则'" v-model="addRuleDialogShow" width="70%" @close="ruleDialogClose">
<rule :editRule="editRule" @ruleAdd="ruleAdd" v-if="addRuleDialogShow" /> <rule :editRule="editRule" @ruleAdd="ruleAdd" v-if="addRuleDialogShow" :isAutoPlan="rules != undefined" />
</el-dialog> </el-dialog>
<el-dialog title="模板管理" v-model="ruleTemplateShow" width="70%"> <el-dialog title="模板管理" v-model="ruleTemplateShow" width="70%">
<application-rule-list v-if="ruleTemplateShow" :curId="chosedTemplate.id" @templateUpdate="templateUpdate" /> <application-rule-list v-if="ruleTemplateShow" :curId="chosedTemplate.id" @templateUpdate="templateUpdate" />

View File

@ -1,14 +1,15 @@
<template> <template>
<div> <div>
<el-form label-width="100px"> <el-form ref="configRuleRef" label-width="100px" :model="body" :rules="bodyRule">
<el-form-item label="剧集目录"> <input type="text" class="form-control" style="display:none" />
<el-form-item label="剧集目录" prop="paths">
<div style="text-align:left"> <div style="text-align:left">
<template v-for="(item, index) in body.paths" :key="item"> <template v-for="(item, index) in body.paths" :key="item">
<el-tag closable @close="closePath(index, 'folder')">{{ item }}</el-tag> <br /> <el-tag closable @close="closePath(index, 'folder')">{{ item }}</el-tag> <br />
</template> </template>
<div style="display:flex;align-items:center"> <div style="display:flex;align-items:center">
<el-button type="primary" link @click="showFolderDialog = true">+新增目录</el-button> <el-button type="primary" link @click="showFolderDialog = true">+新增目录</el-button>
<tips message="添加剧集的上级目录,比如'/美剧'目录下就是美剧的剧集文件夹" /> <tips message="添加剧集的上级目录,此目录下的每一个文件夹都将被认为是一部剧" />
</div> </div>
</div> </div>
</el-form-item> </el-form-item>
@ -26,18 +27,23 @@
</div> </div>
</el-form-item> </el-form-item>
<el-form-item label="忽略特典"> <el-form-item label="忽略特典">
<el-switch v-model="body.ignoreSeason0" class="ml-2" <el-switch v-model="body.ignoreSeason0" class="ml-2" />
style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949" />
<tips message="season 0/特典通常命名不规范,建议手动处理" /> <tips message="season 0/特典通常命名不规范,建议手动处理" />
</el-form-item> </el-form-item>
<el-form-item label="删除小文件"> <el-form-item label="删除小文件">
<el-switch v-model="body.deleteSmallVideo" class="ml-2" <el-switch v-model="body.deleteSmallVideo" class="ml-2" />
style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949" />
<tips message="删除小于2M的视频文件此类文件通常为广告" /> <tips message="删除小于2M的视频文件此类文件通常为广告" />
</el-form-item> </el-form-item>
<el-form-item label="规则"> <el-form-item label="规则" prop="rules">
<RuleBlock :rules="body.rules" @ruleUpdate="ruleUpdate" /> <RuleBlock :rules="body.rules" @ruleUpdate="ruleUpdate" />
</el-form-item> </el-form-item>
<el-form-item label="忽略现有">
<el-switch v-model="body.ignoreExist" class="ml-2" />
<tips message="是否忽略现有文件.打开开关会忽略现有文件,关闭会重命名现有文件" />
</el-form-item>
<el-form-item label="开始任务">
<el-switch v-model="body.start" class="ml-2" />
</el-form-item>
</el-form> </el-form>
<el-button type="primary" @click="submit"> 保存自动化配置 </el-button> <el-button type="primary" @click="submit"> 保存自动化配置 </el-button>
<el-dialog title="选择目录" v-model="showFolderDialog" width="70%"> <el-dialog title="选择目录" v-model="showFolderDialog" width="70%">
@ -51,18 +57,25 @@ import FileChose from "@/components/FileChose.vue";
import RuleBlock from "@/components/rules/RuleBlock.vue"; import RuleBlock from "@/components/rules/RuleBlock.vue";
import Tips from '@/components/Tips.vue'; import Tips from '@/components/Tips.vue';
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import { ref, reactive, onMounted, computed, defineProps } from "vue"; import { ref, reactive, onMounted } from "vue";
import http from "@/utils/HttpUtil"; import http from "@/utils/HttpUtil";
// //
let body = reactive({ let body = ref({
paths: [], paths: [],
version: 1, version: 1,
ignoreSeason0: true, ignoreSeason0: true,
ignorePaths: [], ignorePaths: [],
deleteSmallVideo: true, deleteSmallVideo: true,
rules: [] rules: [],
ignoreExist: false,
start: false
}); });
let bodyRule = reactive({
paths: { type: 'array', required: true, message: '目录不能为空', trigger: 'change' },
rules: { type: 'array', required: true, message: '目录不能为空', trigger: 'change' },
})
const configRuleRef = ref();
let showFolderDialog = ref(false); let showFolderDialog = ref(false);
let ignoreInputVisible = ref(false); let ignoreInputVisible = ref(false);
let ignoreInput = ref(""); let ignoreInput = ref("");
@ -81,42 +94,51 @@ onMounted(async () => {
return; return;
} }
if (res.autoConfig != undefined) { if (res.autoConfig != undefined) {
body = reactive(JSON.parse(res.autoConfig)); body.value = JSON.parse(res.autoConfig);
} }
}); });
// //
async function folderChose (data) { async function folderChose (data) {
if (body.paths.indexOf(data) > -1) { if (body.value.paths.indexOf(data) > -1) {
ElMessage({ type: 'warning', message: "路径已存在" }); ElMessage({ type: 'warning', message: "路径已存在" });
return; return;
} }
body.paths.push(data); body.value.paths.push(data);
showFolderDialog.value = false; showFolderDialog.value = false;
} }
// //
async function addIngoreFile () { async function addIngoreFile () {
if (body.ignorePaths.indexOf(ignoreInput) > -1) { if (body.value.ignorePaths.indexOf(ignoreInput.value) > -1) {
ElMessage({ type: 'warning', message: "名称已存在" }); ElMessage({ type: 'warning', message: "名称已存在" });
return; return;
} }
body.ignorePaths.push(ignoreInput.value); if (ignoreInput.value.length > 0) {
body.value.ignorePaths.push(ignoreInput.value);
}
ignoreInput.value = ""; ignoreInput.value = "";
ignoreInputVisible.value = false; ignoreInputVisible.value = false;
return false;
} }
// //
async function closePath (index, type) { async function closePath (index, type) {
(type === 'folder' ? body.paths : body.ignorePaths).splice(index, 1); (type === 'folder' ? body.value.paths : body.value.ignorePaths).splice(index, 1);
} }
// //
function ruleUpdate (rules) { function ruleUpdate (rules) {
body.rules = rules; body.value.rules = rules;
} }
// //
async function submit () { async function submit () {
await http.post("/config/insertOrUpdate", null, { code: "autoConfig", val: JSON.stringify(body), description: "自动化配置" }); console.dir(configRuleRef.value);
ElMessage({ type: 'success', message: "保存成功" }); configRuleRef.value.validate(async valid => {
if (!valid) {
return;
}
await http.post("/config/insertOrUpdate", null, { code: "autoConfig", val: JSON.stringify(body.value), description: "自动化配置" });
ElMessage({ type: 'success', message: "保存成功" });
})
} }
</script> </script>