From be68f0fadb94f38fea8695a3a58f3054ce94f76a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E8=90=8C=E5=93=92=E8=B5=AB=E8=90=9D?= Date: Thu, 23 Feb 2023 12:00:32 +0800 Subject: [PATCH] :sparkles: Feature: configs of picBeds can be auto imported to manage config now --- package.json | 2 +- src/renderer/manage/pages/logIn.vue | 189 +++++++++++++++++++++++++++- yarn.lock | 8 +- 3 files changed, 193 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 02efd58..b5e35d2 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "mime-types": "^2.1.35", "mitt": "^3.0.0", "nodejs-file-downloader": "^4.10.6", - "piclist": "^0.0.9", + "piclist": "^0.1.0", "pinia": "^2.0.32", "pinia-plugin-persistedstate": "^3.1.0", "qiniu": "^7.8.0", diff --git a/src/renderer/manage/pages/logIn.vue b/src/renderer/manage/pages/logIn.vue index aef070d..2e35186 100644 --- a/src/renderer/manage/pages/logIn.vue +++ b/src/renderer/manage/pages/logIn.vue @@ -256,6 +256,8 @@ import { shell } from 'electron' import { useRouter } from 'vue-router' import { useManageStore } from '../store/manageStore' import { formObjToTableData } from '../utils/common' +import { getConfig as getPicBedsConfig } from '@/utils/dataSender' +import { formatEndpoint } from '~/main/manage/utils/common' const activeName = ref('login') const configResult:IStringKeyMap = reactive({}) @@ -528,7 +530,192 @@ function handleConfigImport (alias: string) { } } -onBeforeMount(() => { +async function getCurrentConfigList () { + const configList = await getPicBedsConfig('uploader') ?? {} + const pbList = ['aliyun', 'tcyun', 'upyun', 'qiniu', 'smms', 'qiniu', 'github', 'webdavplist', 'aws-s3'] + for (const pb of pbList) { + if (configList[pb] && configList[pb].configList.length > 0) { + for (const config of configList[pb].configList) { + await transUpToManage(config, pb) + } + } + } +} + +async function transUpToManage (config: IUploaderConfigListItem, picBedName: string) { + const resultMap: IStringKeyMap = {} + switch (picBedName) { + case 'smms': + if (!config.token) { + return + } + resultMap.alias = `smms-${config._configName ?? 'Default'}-imp` + resultMap.picBedName = 'smms' + resultMap.token = config.token + resultMap.paging = true + saveConfig(`picBed.${resultMap.alias}`, resultMap) + break + case 'aliyun': + if (!config.accessKeyId || !config.accessKeySecret) { + return + } + resultMap.alias = `aliyun-${config._configName ?? 'Default'}-imp` + resultMap.picBedName = 'aliyun' + resultMap.accessKeyId = config.accessKeyId + resultMap.accessKeySecret = config.accessKeySecret + resultMap.bucketName = '' + resultMap.baseDir = '/' + resultMap.paging = true + resultMap.itemsPerPage = 50 + resultMap.isAutoCustomUrl = !config.customUrl + resultMap.transformedConfig = JSON.stringify(config.customUrl + ? { + [config.bucket]: { + customUrl: config.customUrl + } + } + : {}) + resultMap.paging = true + saveConfig(`picBed.${resultMap.alias}`, resultMap) + break + case 'qiniu': + if (!config.accessKey || !config.secretKey) { + return + } + resultMap.alias = `qiniu-${config._configName ?? 'Default'}-imp` + resultMap.picBedName = 'qiniu' + resultMap.accessKey = config.accessKey + resultMap.secretKey = config.secretKey + resultMap.bucketName = '' + resultMap.baseDir = '/' + resultMap.isAutoCustomUrl = false + resultMap.transformedConfig = JSON.stringify({ [config.bucket]: config.url }) + resultMap.paging = true + resultMap.itemsPerPage = 50 + saveConfig(`picBed.${resultMap.alias}`, resultMap) + break + case 'tcyun': + if (!config.secretId || !config.secretKey || config.version === 'v4') { + return + } + resultMap.alias = `tcyun-${config._configName ?? 'Default'}-imp` + resultMap.picBedName = 'tcyun' + resultMap.secretId = config.secretId + resultMap.secretKey = config.secretKey + resultMap.bucketName = '' + resultMap.baseDir = '/' + resultMap.appId = config.appId + resultMap.isAutoCustomUrl = !config.customUrl + resultMap.transformedConfig = JSON.stringify(config.customUrl + ? { + [config.bucket]: { + customUrl: config.customUrl + } + } + : {}) + resultMap.paging = true + resultMap.itemsPerPage = 50 + saveConfig(`picBed.${resultMap.alias}`, resultMap) + break + case 'github': + if (!config.token) { + return + } + resultMap.alias = `github-${config._configName ?? 'Default'}-imp` + resultMap.picBedName = 'github' + resultMap.token = config.token + resultMap.githubUsername = config.repo.split('/')[0] + resultMap.customUrl = '' + resultMap.proxy = '' + resultMap.paging = true + resultMap.itemsPerPage = 50 + saveConfig(`picBed.${resultMap.alias}`, resultMap) + break + case 'upyun': + if (!config.operator || !config.password) { + return + } + resultMap.alias = `upyun-${config._configName ?? 'Default'}-imp` + resultMap.picBedName = 'upyun' + resultMap.operator = config.operator + resultMap.password = config.password + resultMap.bucketName = config.bucket + resultMap.baseDir = '/' + resultMap.customUrl = config.url + resultMap.transformedConfig = JSON.stringify({ + [config.bucket]: { + customUrl: config.url, + baseDir: '/', + area: '', + operator: config.operator, + password: config.password + } + }) + resultMap.paging = true + resultMap.itemsPerPage = 50 + saveConfig(`picBed.${resultMap.alias}`, resultMap) + break + case 'webdavplist': + if (!config.host) { + return + } + resultMap.alias = `webdav-${config._configName ?? 'Default'}-imp` + resultMap.endpoint = formatEndpoint(config.host, config.sslEnabled) + resultMap.picBedName = 'webdavplist' + resultMap.username = config.username + resultMap.password = config.password + resultMap.bucketName = 'webdav' + resultMap.baseDir = config.path || '/' + resultMap.customUrl = config.customUrl || '' + resultMap.sslEnabled = !!config.sslEnabled + resultMap.proxy = '' + resultMap.transformedConfig = JSON.stringify({ + webdav: { + operator: '', + password: config.password, + baseDir: config.path || '/', + customUrl: config.customUrl || '', + area: '' + } + }) + saveConfig(`picBed.${resultMap.alias}`, resultMap) + break + case 'aws-s3': + if (!config.accessKeyID || !config.secretAccessKey) { + return + } + resultMap.alias = `s3-${config._configName ?? 'Default'}-imp` + resultMap.picBedName = 's3plist' + resultMap.accessKeyId = config.accessKeyID + resultMap.secretAccessKey = config.secretAccessKey + resultMap.endpoint = config.endpoint || '' + resultMap.baseDir = '/' + resultMap.bucketName = '' + resultMap.paging = true + resultMap.itemsPerPage = 50 + resultMap.proxy = '' + resultMap.sslEnabled = config.endpoint ? config.endpoint.startsWith('https') : false + resultMap.aclForUpload = 'public-read' + resultMap.s3ForcePathStyle = config.pathStyleAccess + resultMap.transformedConfig = JSON.stringify( + config.urlPrefix + ? { + [config.bucket]: { + customUrl: config.urlPrefix + } + } + : {} + ) + saveConfig(`picBed.${resultMap.alias}`, resultMap) + break + default: + return + } + await manageStore.refreshConfig() +} + +onBeforeMount(async () => { + await getCurrentConfigList() getExistingConfig('login') getAllConfigAliasArray() }) diff --git a/yarn.lock b/yarn.lock index dfc3f6b..e21f291 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10919,10 +10919,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@^0.0.9: - version "0.0.9" - resolved "https://registry.npmjs.org/piclist/-/piclist-0.0.9.tgz#1c610728480594fc7cfd04d3bde5b542ecc910ee" - integrity sha512-ZDNP1uQT3JACUG1s1RhRlB35DuZPFuDlDPrv8aBPdVlfAjO9nuY7ICEZ3qj8AHPQb7R98R8fSJZq8juYMqXPzw== +piclist@^0.1.0: + version "0.1.0" + resolved "https://registry.npmjs.org/piclist/-/piclist-0.1.0.tgz#4aa99617508c4f5d0ab871743c0d1ccea9a685d2" + integrity sha512-LEMPbIB2VCQZKkTEq4S/lEimieRZVOnKL3s/pWEUzVeDXAg7lw4bCaIA6hUJuouHtomz9OH3PH8ghKMnInDg/w== dependencies: "@picgo/i18n" "^1.0.0" "@picgo/store" "^2.0.4"