Skip to content

Commit

Permalink
🐛 Fix(custom): fix format convert bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuingsmile committed Jan 30, 2024
1 parent d87a014 commit ea82600
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"multer": "^1.4.5-lts.1",
"node-ssh-no-cpu-features": "^1.0.1",
"nodejs-file-downloader": "^4.12.1",
"piclist": "^1.7.8",
"piclist": "^1.7.9",
"pinia": "^2.1.7",
"pinia-plugin-persistedstate": "^3.2.0",
"proxy-agent": "^5.0.0",
Expand Down
24 changes: 15 additions & 9 deletions src/renderer/pages/PicGoSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@
:label="$T('UPLOAD_PAGE_IMAGE_PROCESS_CONVERTFORMAT_SPECIFIC')"
>
<el-input
v-model="compressForm.formatConvertObj"
v-model="formatConvertObj"
placeholder="{&quot;jpg&quot;: &quot;png&quot;, &quot;png&quot;: &quot;jpg&quot;}"
type="textarea"
:autosize="{ minRows: 2, maxRows: 4}"
Expand Down Expand Up @@ -1692,6 +1692,8 @@ const waterMarkForm = reactive<any>({
watermarkPosition: 'southeast'
})
const formatConvertObj = ref('{}')
const compressForm = reactive<any>({
quality: 100,
isConvert: false,
Expand All @@ -1706,26 +1708,26 @@ const compressForm = reactive<any>({
rotateDegree: 0,
isRemoveExif: false,
isFlip: false,
isFlop: false,
formatConvertObj: '{}'
isFlop: false
})
function closeDialog () {
imageProcessDialogVisible.value = false
}
function handleSaveConfig () {
let formatConvertObj = {}
let iformatConvertObj = {}
try {
formatConvertObj = JSON.parse(compressForm.formatConvertObj)
iformatConvertObj = JSON.parse(formatConvertObj.value)
} catch (error) {
}
const formatConvertObjEntries = Object.entries(formatConvertObj)
const formatConvertObjEntries = Object.entries(iformatConvertObj)
const formatConvertObjEntriesFilter = formatConvertObjEntries.filter((item: any) => {
return imageExtList.includes(item[0]) && availableFormat.includes(item[1])
})
const formatConvertObjFilter = Object.fromEntries(formatConvertObjEntriesFilter)
compressForm.formatConvertObj = JSON.stringify(formatConvertObjFilter)
formatConvertObj.value = JSON.stringify(formatConvertObjFilter)
compressForm.formatConvertObj = formatConvertObjFilter
saveConfig('buildIn.compress', toRaw(compressForm))
saveConfig('buildIn.watermark', toRaw(waterMarkForm))
closeDialog()
Expand All @@ -1750,9 +1752,13 @@ async function initForm () {
compressForm.isFlip = compress.isFlip ?? false
compressForm.isFlop = compress.isFlop ?? false
try {
compressForm.formatConvertObj = JSON.stringify(compress.formatConvertObj ?? {})
if (typeof compress.formatConvertObj === 'object') {
formatConvertObj.value = JSON.stringify(compress.formatConvertObj)
} else {
formatConvertObj.value = compress.formatConvertObj ?? '{}'
}
} catch (error) {
compressForm.formatConvertObj = '{}'
formatConvertObj.value = '{}'
}
}
if (watermark) {
Expand Down
24 changes: 15 additions & 9 deletions src/renderer/pages/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
:label="$T('UPLOAD_PAGE_IMAGE_PROCESS_CONVERTFORMAT_SPECIFIC')"
>
<el-input
v-model="compressForm.formatConvertObj"
v-model="formatConvertObj"
placeholder="{&quot;jpg&quot;: &quot;png&quot;, &quot;png&quot;: &quot;jpg&quot;}"
type="textarea"
:autosize="{ minRows: 2, maxRows: 4}"
Expand Down Expand Up @@ -516,26 +516,28 @@ const compressForm = reactive<any>({
rotateDegree: 0,
isRemoveExif: false,
isFlip: false,
isFlop: false,
formatConvertObj: '{}'
isFlop: false
})
const formatConvertObj = ref('{}')
function closeDialog () {
imageProcessDialogVisible.value = false
}
function handleSaveConfig () {
let formatConvertObj = {}
let iformatConvertObj = {}
try {
formatConvertObj = JSON.parse(compressForm.formatConvertObj)
iformatConvertObj = JSON.parse(formatConvertObj.value)
} catch (error) {
}
const formatConvertObjEntries = Object.entries(formatConvertObj)
const formatConvertObjEntries = Object.entries(iformatConvertObj)
const formatConvertObjEntriesFilter = formatConvertObjEntries.filter((item: any) => {
return imageExtList.includes(item[0]) && availableFormat.includes(item[1])
})
const formatConvertObjFilter = Object.fromEntries(formatConvertObjEntriesFilter)
compressForm.formatConvertObj = JSON.stringify(formatConvertObjFilter)
formatConvertObj.value = JSON.stringify(formatConvertObjFilter)
compressForm.formatConvertObj = formatConvertObjFilter
saveConfig('buildIn.compress', toRaw(compressForm))
saveConfig('buildIn.watermark', toRaw(waterMarkForm))
closeDialog()
Expand All @@ -560,9 +562,13 @@ async function initData () {
compressForm.isFlip = compress.isFlip ?? false
compressForm.isFlop = compress.isFlop ?? false
try {
compressForm.formatConvertObj = JSON.stringify(compress.formatConvertObj ?? {})
if (typeof compress.formatConvertObj === 'object') {
formatConvertObj.value = JSON.stringify(compress.formatConvertObj)
} else {
formatConvertObj.value = compress.formatConvertObj ?? '{}'
}
} catch (error) {
compressForm.formatConvertObj = '{}'
formatConvertObj.value = '{}'
}
}
if (watermark) {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12392,10 +12392,10 @@ performance-now@^2.1.0:
resolved "https://registry.npmmirror.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
integrity sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==

piclist@^1.7.8:
version "1.7.8"
resolved "https://registry.yarnpkg.com/piclist/-/piclist-1.7.8.tgz#7d013354608a9d45a52e1947b0591c3a60b6a37e"
integrity sha512-GXHGpq03J7aZKDJ/fMvuUrOy+aeE5g9mFObhfKRE2p89IPbv/Y1ll9OcQkjf8wcqWPdC1240u5p+GOMyUgr2Dg==
piclist@^1.7.9:
version "1.7.9"
resolved "https://registry.yarnpkg.com/piclist/-/piclist-1.7.9.tgz#1677f63c0596d0b23fd082ce4a3f10c6b4f7244a"
integrity sha512-+H32vNqfe3bCNhkreEJXzWT4fUOyPntNxCPjeo5btxAhbaVEfP8GwXA1XfX8NrJb3ml6sQzIk26FrQ2bzK+Bwg==
dependencies:
"@aws-sdk/client-s3" "3.421.0"
"@aws-sdk/lib-storage" "3.421.0"
Expand Down

0 comments on commit ea82600

Please sign in to comment.