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
})
}

View File

@@ -27,14 +27,24 @@
type="uploader"
>
<el-form-item>
<el-button
class="confirm-btn"
type="primary"
round
@click="handleConfirm"
>
{{ $T('CONFIRM') }}
</el-button>
<el-button-group>
<el-button
class="confirm-btn"
type="info"
round
@click="handleReset"
>
{{ $T('RESET_PICBED_CONFIG') }}
</el-button>
<el-button
class="confirm-btn"
type="success"
round
@click="handleConfirm"
>
{{ $T('CONFIRM') }}
</el-button>
</el-button-group>
</el-form-item>
</config-form>
<div
@@ -63,6 +73,7 @@ import {
} from 'electron'
import { OPEN_URL } from '~/universal/events/constants'
import { Link } from '@element-plus/icons-vue'
const type = ref('')
const config = ref<IPicGoPluginConfig[]>([])
const picBedName = ref('')
@@ -90,6 +101,17 @@ const handleConfirm = async () => {
}
}
const handleReset = async () => {
await triggerRPC<void>(IRPCActionType.RESET_UPLOADER_CONFIG, type.value, $route.params.configId)
const successNotification = new Notification($T('SETTINGS_RESULT'), {
body: $T('TIPS_RESET_SUCCEED')
})
successNotification.onclick = () => {
return true
}
$router.back()
}
const linkToLogInList = ['github', 'tcyun', 'aliyun', 'smms', 'qiniu', 'imgur', 'upyun', 'githubPlus']
function handelNameClick () {

View File

@@ -63,4 +63,5 @@ export enum IRPCActionType {
CHANGE_CURRENT_UPLOADER = 'CHANGE_CURRENT_UPLOADER',
SELECT_UPLOADER = 'SELECT_UPLOADER',
UPDATE_UPLOADER_CONFIG = 'UPDATE_UPLOADER_CONFIG',
RESET_UPLOADER_CONFIG = 'RESET_UPLOADER_CONFIG'
}

View File

@@ -46,6 +46,7 @@ interface ILocales {
INPUT: string
CANCEL: string
CONFIRM: string
RESET_PICBED_CONFIG: string
CHOOSE_SHOWED_PICBED: string
CHOOSE_PASTE_FORMAT: string
SEARCH: string
@@ -201,6 +202,7 @@ interface ILocales {
TIPS_NEED_RELOAD: string
TIPS_PLEASE_CHOOSE_LOG_LEVEL: string
TIPS_SET_SUCCEED: string
TIPS_RESET_SUCCEED: string
TIPS_PLUGIN_NOT_GUI_IMPLEMENT: string
TIPS_CLICK_NOTIFICATION_TO_RELOAD: string
TIPS_GET_PLUGIN_LIST_FAILED: string

View File

@@ -2,3 +2,4 @@ type IGetUploaderConfigListArgs = [type: string]
type IDeleteUploaderConfigArgs = [type: string, id: string]
type ISelectUploaderConfigArgs = [type: string, id: string]
type IUpdateUploaderConfigArgs = [type: string, id: string, config: IStringKeyMap]
type IResetUploaderConfigArgs = [type: string, id: string]