mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-06 20:42:57 +08:00
✨ Feature(custom): optimize per picbed setting logic when the value is same to default
This commit is contained in:
@@ -1111,40 +1111,38 @@ const compressForm = ref<IBuildInCompressOptions>({
|
|||||||
/* Only used if configId is not provided */
|
/* Only used if configId is not provided */
|
||||||
const formatConvertObjStr = ref('{}')
|
const formatConvertObjStr = ref('{}')
|
||||||
|
|
||||||
|
const defaultSkipProcessSetting = {
|
||||||
|
skipProcessExtList: 'zip,rar,7z,tar,gz,tar.gz,tar.bz2,tar.xz',
|
||||||
|
}
|
||||||
/* Only used if configId is not provided */
|
/* Only used if configId is not provided */
|
||||||
const skipProcessForm = ref<IBuildInSkipProcessOptions>({
|
const skipProcessForm = ref<IBuildInSkipProcessOptions>({
|
||||||
skipProcessExtList: 'zip,rar,7z,tar,gz,tar.gz,tar.bz2,tar.xz',
|
...defaultSkipProcessSetting,
|
||||||
})
|
})
|
||||||
|
|
||||||
const isInitialized = ref(false)
|
const isInitialized = ref(false)
|
||||||
|
|
||||||
function saveSkipProcessConfig() {
|
|
||||||
saveConfig(configPaths.buildIn.skipProcess, toRaw(skipProcessForm.value))
|
|
||||||
}
|
|
||||||
|
|
||||||
function saveCompressConfig() {
|
|
||||||
const cleanFullMap: Record<string, any> = {}
|
|
||||||
Object.entries(compressForm.value.formatConvertObjMap || {}).forEach(([picbedType, value]) => {
|
|
||||||
try {
|
|
||||||
const cleanedObj = cleanFormatConvertObj(value)
|
|
||||||
|
|
||||||
if (Object.keys(cleanedObj).length > 0) {
|
|
||||||
cleanFullMap[picbedType] = cleanedObj
|
|
||||||
}
|
|
||||||
} catch (_error) {}
|
|
||||||
})
|
|
||||||
if (JSON.stringify(cleanFullMap) !== JSON.stringify(compressForm.value.formatConvertObjMap)) {
|
|
||||||
compressForm.value.formatConvertObjMap = cleanFullMap
|
|
||||||
}
|
|
||||||
|
|
||||||
saveConfig(configPaths.buildIn.compress, toRaw(compressForm.value))
|
|
||||||
}
|
|
||||||
|
|
||||||
function saveWaterMarkConfig() {
|
function saveWaterMarkConfig() {
|
||||||
saveConfig(configPaths.buildIn.watermark, toRaw(waterMarkForm.value))
|
saveConfig(configPaths.buildIn.watermark, toRaw(waterMarkForm.value))
|
||||||
}
|
}
|
||||||
|
|
||||||
const singleConfigSettings = ref<IBuildInListItem>({} as IBuildInListItem)
|
const singleConfigSettings = ref<IBuildInListItem>({
|
||||||
|
id: '',
|
||||||
|
compress: {
|
||||||
|
...defaultCompressSetting,
|
||||||
|
},
|
||||||
|
watermark: {
|
||||||
|
...defaultWaterMarkSetting,
|
||||||
|
},
|
||||||
|
skipProcess: {
|
||||||
|
...defaultSkipProcessSetting,
|
||||||
|
},
|
||||||
|
rename: {
|
||||||
|
enable: false,
|
||||||
|
format: '{filename}',
|
||||||
|
},
|
||||||
|
autoRename: false,
|
||||||
|
manualRename: false,
|
||||||
|
} as IBuildInListItem)
|
||||||
|
|
||||||
function cleanFormatConvertObj(obj: any) {
|
function cleanFormatConvertObj(obj: any) {
|
||||||
const cleanedObj: Record<string, any> = {}
|
const cleanedObj: Record<string, any> = {}
|
||||||
@@ -1157,18 +1155,6 @@ function cleanFormatConvertObj(obj: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function initData() {
|
async function initData() {
|
||||||
//single config settings
|
|
||||||
if (configId) {
|
|
||||||
const buildInList = await getConfig<Undefinable<IBuildInListItem[]>>(configPaths.buildIn.list)
|
|
||||||
if (!buildInList) {
|
|
||||||
console.error('Failed to load built-in config list.')
|
|
||||||
}
|
|
||||||
const targetConfig = buildInList?.find(item => item.id === configId)
|
|
||||||
if (targetConfig) {
|
|
||||||
singleConfigSettings.value = targetConfig
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// global settings
|
// global settings
|
||||||
const compress = (await getConfig<IBuildInCompressOptions>(configPaths.buildIn.compress)) || {}
|
const compress = (await getConfig<IBuildInCompressOptions>(configPaths.buildIn.compress)) || {}
|
||||||
const watermark = (await getConfig<IBuildInWaterMarkOptions>(configPaths.buildIn.watermark)) || {}
|
const watermark = (await getConfig<IBuildInWaterMarkOptions>(configPaths.buildIn.watermark)) || {}
|
||||||
@@ -1230,6 +1216,17 @@ async function initData() {
|
|||||||
...skipProcess,
|
...skipProcess,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (configId) {
|
||||||
|
let buildInList = await getConfig<Undefinable<IBuildInListItem[]>>(configPaths.buildIn.list)
|
||||||
|
if (!buildInList) {
|
||||||
|
saveConfig(configPaths.buildIn.list, [])
|
||||||
|
buildInList = []
|
||||||
|
}
|
||||||
|
const targetConfig = buildInList?.find(item => item.id === configId)
|
||||||
|
if (!targetConfig) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function safeSetMapValue(form: any, fieldName: string, picbedType: string, value: any, defaultValue: any) {
|
function safeSetMapValue(form: any, fieldName: string, picbedType: string, value: any, defaultValue: any) {
|
||||||
@@ -1250,7 +1247,7 @@ function safeSetMapValue(form: any, fieldName: string, picbedType: string, value
|
|||||||
if (!form[mapFieldName]) {
|
if (!form[mapFieldName]) {
|
||||||
form[mapFieldName] = {}
|
form[mapFieldName] = {}
|
||||||
}
|
}
|
||||||
if (value === defaultValue) {
|
if (value === defaultValue && form[fieldName] === defaultValue) {
|
||||||
delete form[mapFieldName][picbedType]
|
delete form[mapFieldName][picbedType]
|
||||||
} else {
|
} else {
|
||||||
if (fieldName === 'formatConvertObj') {
|
if (fieldName === 'formatConvertObj') {
|
||||||
@@ -1261,6 +1258,28 @@ function safeSetMapValue(form: any, fieldName: string, picbedType: string, value
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function saveSkipProcessConfig() {
|
||||||
|
saveConfig(configPaths.buildIn.skipProcess, toRaw(skipProcessForm.value))
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveCompressConfig() {
|
||||||
|
const cleanFullMap: Record<string, any> = {}
|
||||||
|
Object.entries(compressForm.value.formatConvertObjMap || {}).forEach(([picbedType, value]) => {
|
||||||
|
try {
|
||||||
|
const cleanedObj = cleanFormatConvertObj(value)
|
||||||
|
|
||||||
|
if (Object.keys(cleanedObj).length > 0) {
|
||||||
|
cleanFullMap[picbedType] = cleanedObj
|
||||||
|
}
|
||||||
|
} catch (_error) {}
|
||||||
|
})
|
||||||
|
if (JSON.stringify(cleanFullMap) !== JSON.stringify(compressForm.value.formatConvertObjMap)) {
|
||||||
|
compressForm.value.formatConvertObjMap = cleanFullMap
|
||||||
|
}
|
||||||
|
|
||||||
|
saveConfig(configPaths.buildIn.compress, toRaw(compressForm.value))
|
||||||
|
}
|
||||||
|
|
||||||
watch(activeTab, () => {
|
watch(activeTab, () => {
|
||||||
nextTick(updateTabIndicator)
|
nextTick(updateTabIndicator)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -104,7 +104,7 @@
|
|||||||
},
|
},
|
||||||
"generalSettings": "General",
|
"generalSettings": "General",
|
||||||
"perPicBed": {
|
"perPicBed": {
|
||||||
"defaultValue": "Default Value: {value}",
|
"defaultValue": "Global Value: {value}",
|
||||||
"description": "Configure settings for each PicBed individually",
|
"description": "Configure settings for each PicBed individually",
|
||||||
"title": "Per-PicBed Settings"
|
"title": "Per-PicBed Settings"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -104,7 +104,7 @@
|
|||||||
},
|
},
|
||||||
"generalSettings": "常规",
|
"generalSettings": "常规",
|
||||||
"perPicBed": {
|
"perPicBed": {
|
||||||
"defaultValue": "默认值: {value}",
|
"defaultValue": "全局值: {value}",
|
||||||
"description": "为每个图床单独配置设置",
|
"description": "为每个图床单独配置设置",
|
||||||
"title": "图床独立设置"
|
"title": "图床独立设置"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -104,7 +104,7 @@
|
|||||||
},
|
},
|
||||||
"generalSettings": "常規",
|
"generalSettings": "常規",
|
||||||
"perPicBed": {
|
"perPicBed": {
|
||||||
"defaultValue": "默認值: {value}",
|
"defaultValue": "全局值: {value}",
|
||||||
"description": "為每個圖床單獨配置設置",
|
"description": "為每個圖床單獨配置設置",
|
||||||
"title": "圖床獨立設置"
|
"title": "圖床獨立設置"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user