diff --git a/src/main/events/rpc/routes/picbed/index.ts b/src/main/events/rpc/routes/picbed/index.ts index 8250ebf3..f3fded78 100644 --- a/src/main/events/rpc/routes/picbed/index.ts +++ b/src/main/events/rpc/routes/picbed/index.ts @@ -7,6 +7,7 @@ import deleteRoutes from '~/events/rpc/routes/picbed/delete' import { IRPCActionType, IRPCType } from '~/utils/enum' import { deleteUploaderConfig, + duplicateUploaderConfig, getUploaderConfigList, resetUploaderConfig, selectUploaderConfig, @@ -45,6 +46,15 @@ const picbedRoutes = [ }, type: IRPCType.INVOKE, }, + { + action: IRPCActionType.PICBED_DUPLICATE_CONFIG, + handler: async (_: IIPCEvent, args: [type: string, id: string, newName: string]) => { + const [type, id, newName] = args + const config = duplicateUploaderConfig(type, id, newName) + return config + }, + type: IRPCType.INVOKE, + }, { action: IRPCActionType.UPLOADER_SELECT, handler: async (_: IIPCEvent, args: [type: string, id: string]) => { diff --git a/src/main/utils/enum.ts b/src/main/utils/enum.ts index 19007e56..9b104133 100644 --- a/src/main/utils/enum.ts +++ b/src/main/utils/enum.ts @@ -92,6 +92,7 @@ export const IRPCActionType = { PICBED_GET_PICBED_CONFIG: 'PICBED_GET_PICBED_CONFIG', PICBED_GET_CONFIG_LIST: 'PICBED_GET_CONFIG_LIST', PICBED_DELETE_CONFIG: 'PICBED_DELETE_CONFIG', + PICBED_DUPLICATE_CONFIG: 'PICBED_DUPLICATE_CONFIG', UPLOADER_CHANGE_CURRENT: 'UPLOADER_CHANGE_CURRENT', UPLOADER_SELECT: 'UPLOADER_SELECT', UPLOADER_UPDATE_CONFIG: 'UPLOADER_UPDATE_CONFIG', diff --git a/src/main/utils/handleUploaderConfig.ts b/src/main/utils/handleUploaderConfig.ts index 2af94aea..f800c780 100644 --- a/src/main/utils/handleUploaderConfig.ts +++ b/src/main/utils/handleUploaderConfig.ts @@ -151,6 +151,34 @@ export const deleteUploaderConfig = (type: string, id: string): IUploaderConfigI } } +export const duplicateUploaderConfig = (type: string, id: string, newName: string): IUploaderConfigItem | void => { + const { configList, defaultId } = getUploaderConfigList(type) + const originalConfig = configList.find((item: IStringKeyMap) => item._id === id) + if (!originalConfig) { + return + } + + const duplicatedConfig: IUploaderConfigListItem = { + ...originalConfig, + _configName: newName, + _id: uuid(), + _createdAt: Date.now(), + _updatedAt: Date.now(), + } + + const updatedConfigList = [...configList, duplicatedConfig] + console.log('updatedConfigList', updatedConfigList) + + picgo.saveConfig({ + [`uploader.${type}.configList`]: updatedConfigList, + }) + + return { + configList: updatedConfigList, + defaultId, + } +} + /** * upgrade old uploader config to new format */ diff --git a/src/renderer/components/InputBoxDialog.vue b/src/renderer/components/InputBoxDialog.vue index 69bfd005..1b4e928d 100644 --- a/src/renderer/components/InputBoxDialog.vue +++ b/src/renderer/components/InputBoxDialog.vue @@ -1,51 +1,61 @@