Feature: picbeds config can be reseted to empty now

This commit is contained in:
萌萌哒赫萝
2023-03-24 13:32:16 +08:00
parent f0daf97028
commit 086b2871e7
9 changed files with 72 additions and 8 deletions

View File

@@ -4,6 +4,7 @@ import { RPC_ACTIONS } from '#/events/constants'
import {
deleteUploaderConfig,
getUploaderConfigList,
resetUploaderConfig,
selectUploaderConfig,
updateUploaderConfig
} from '~/main/utils/handleUploaderConfig'
@@ -33,6 +34,11 @@ class RPCServer {
this.sendBack(event, action, true, callbackId)
break
}
case IRPCActionType.RESET_UPLOADER_CONFIG: {
this.resetUploaderConfig(args as IResetUploaderConfigArgs)
this.sendBack(event, action, true, callbackId)
break
}
default: {
this.sendBack(event, action, null, callbackId)
break
@@ -74,6 +80,12 @@ class RPCServer {
const res = updateUploaderConfig(type, id, config)
return res
}
private resetUploaderConfig (args: IResetUploaderConfigArgs) {
const [type, id] = args
const res = resetUploaderConfig(type, id)
return res
}
}
const rpcServer = new RPCServer()

View File

@@ -167,3 +167,23 @@ export const updateUploaderConfig = (type: string, id: string, config: IStringKe
[`picBed.${type}`]: updatedConfig
})
}
/**
* Reset selected congfig id to default
*/
export const resetUploaderConfig = (type: string, id: string) => {
const { configList } = getUploaderConfigList(type)
configList.forEach((item: IStringKeyMap) => {
if (item._id === id) {
Object.keys(item).forEach(key => {
if (!['_configName', '_id', '_createdAt', '_updatedAt'].includes(key)) {
delete item[key]
}
})
}
})
picgo.saveConfig({
[`uploader.${type}.configList`]: configList
})
}