mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-20 15:50:04 +08:00
✨ Feature: picbeds config can be reseted to empty now
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user