mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 15:36:49 +08:00
fix(rule): bug
- 替换错误的规则校验方法。
This commit is contained in:
@@ -8,41 +8,12 @@ import { CustomRule, FilterRuleGroup } from '@/api/types'
|
|||||||
import CustomerRuleCard from '@/components/cards/CustomRuleCard.vue'
|
import CustomerRuleCard from '@/components/cards/CustomRuleCard.vue'
|
||||||
import FilterRuleGroupCard from '@/components/cards/FilterRuleGroupCard.vue'
|
import FilterRuleGroupCard from '@/components/cards/FilterRuleGroupCard.vue'
|
||||||
import ImportCodeDialog from '@/components/dialog/ImportCodeDialog.vue'
|
import ImportCodeDialog from '@/components/dialog/ImportCodeDialog.vue'
|
||||||
import internal from 'stream'
|
|
||||||
|
|
||||||
// 自定义规则列表
|
// 自定义规则列表
|
||||||
const customRules = ref<CustomRule[]>([])
|
const customRules = ref<CustomRule[]>([])
|
||||||
// 自定义规则类型,仅用于导入判断
|
|
||||||
const customRulesType = ref<CustomRule>({
|
|
||||||
// 规则ID
|
|
||||||
id: '',
|
|
||||||
// 名称
|
|
||||||
name: '',
|
|
||||||
// 包含
|
|
||||||
include: '',
|
|
||||||
// 排除
|
|
||||||
exclude: '',
|
|
||||||
// 大小范围
|
|
||||||
size_range: '',
|
|
||||||
// 最少做种人数
|
|
||||||
seeders: '',
|
|
||||||
// 发布时间
|
|
||||||
publish_time: '',
|
|
||||||
})
|
|
||||||
|
|
||||||
// 所有规则组列表
|
// 所有规则组列表
|
||||||
const filterRuleGroups = ref<FilterRuleGroup[]>([])
|
const filterRuleGroups = ref<FilterRuleGroup[]>([])
|
||||||
// 规则组类型,仅用于导入判断
|
|
||||||
const filterRuleGroupsType = ref<FilterRuleGroup>({
|
|
||||||
// 名称
|
|
||||||
name: '',
|
|
||||||
// 规则串
|
|
||||||
rule_string: '',
|
|
||||||
// 适用类媒体类型 None-全部 电影/电视剧
|
|
||||||
media_type: '',
|
|
||||||
// # 适用媒体类别 None-全部 对应二级分类
|
|
||||||
category: '',
|
|
||||||
})
|
|
||||||
|
|
||||||
// 种子优先规则
|
// 种子优先规则
|
||||||
const selectedTorrentPriority = ref<string>('seeder')
|
const selectedTorrentPriority = ref<string>('seeder')
|
||||||
@@ -218,13 +189,13 @@ function saveCodeString(type: string, codeString: any) {
|
|||||||
try {
|
try {
|
||||||
if (type === 'custom') {
|
if (type === 'custom') {
|
||||||
for (const value of parsedCode) {
|
for (const value of parsedCode) {
|
||||||
if (!validateValueAgainstInterface(value, customRulesType)) return false
|
if (!checkValueValidity(value, type)) return false
|
||||||
}
|
}
|
||||||
const newCustomRules = extractCustomRules(parsedCode) || []
|
const newCustomRules = extractCustomRules(parsedCode) || []
|
||||||
customRules.value = [...customRules.value, ...newCustomRules]
|
customRules.value = [...customRules.value, ...newCustomRules]
|
||||||
} else if (type === 'group') {
|
} else if (type === 'group') {
|
||||||
for (const value of parsedCode) {
|
for (const value of parsedCode) {
|
||||||
if (!validateValueAgainstInterface(value, filterRuleGroupsType)) return false
|
if (!checkValueValidity(value, type)) return false
|
||||||
}
|
}
|
||||||
const newFilterRuleGroups = extractFilterRuleGroups(parsedCode) || []
|
const newFilterRuleGroups = extractFilterRuleGroups(parsedCode) || []
|
||||||
filterRuleGroups.value = [...filterRuleGroups.value, ...newFilterRuleGroups]
|
filterRuleGroups.value = [...filterRuleGroups.value, ...newFilterRuleGroups]
|
||||||
@@ -269,22 +240,34 @@ function extractFilterRuleGroups(value: any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateValueAgainstInterface(value: any, interfaceDefinition: any): boolean {
|
// 根据ID简单区分规则与规则组
|
||||||
console.log(value)
|
function checkValueValidity(value: any, type: string): boolean {
|
||||||
console.log(interfaceDefinition)
|
// 允许空值存在,不影响最终的导入
|
||||||
try {
|
if (!value) return true
|
||||||
// 循环判断是否命中全部接口定义,暂时只检查是否存在,不检查是否多出
|
if (!type) return false
|
||||||
for (const key in interfaceDefinition.value) {
|
const keys = Object.keys(value)
|
||||||
if (value[key] === undefined) {
|
const uniqueKeys = new Set(keys)
|
||||||
$toast.error(`导入规则失败!输入了不符合要求的数据!`)
|
|
||||||
return false
|
const hasName = keys.includes('name')
|
||||||
}
|
const hasId = keys.includes('id')
|
||||||
|
const noDuplicates = keys.length === uniqueKeys.size
|
||||||
|
if (type == 'custom') {
|
||||||
|
if (!hasName || !hasId || !noDuplicates) {
|
||||||
|
if (!noDuplicates) $toast.warning(`存在重名值`)
|
||||||
|
if (!hasId) $toast.error(`导入失败!发现有规则不存在ID,可能属于优先级规则组!`)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
return true
|
} else if (type == 'group') {
|
||||||
} catch (e) {
|
if (!hasName || hasId || !noDuplicates) {
|
||||||
console.error(e)
|
if (!noDuplicates) $toast.warning(`存在重名值`)
|
||||||
|
if (hasId) $toast.error(`导入失败!发现有规则存在ID,可能属于自定义规则!`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error(`传入了不合法类型`)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 规则变化时赋值
|
// 规则变化时赋值
|
||||||
|
|||||||
Reference in New Issue
Block a user