Skip to content

Commit

Permalink
✨ Feature: configs of picBeds can be auto imported to manage config now
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuingsmile committed Feb 23, 2023
1 parent 1dacd3c commit be68f0f
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
189 changes: 188 additions & 1 deletion src/renderer/manage/pages/logIn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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({})
Expand Down Expand Up @@ -528,7 +530,192 @@ function handleConfigImport (alias: string) {
}
}
onBeforeMount(() => {
async function getCurrentConfigList () {
const configList = await getPicBedsConfig<any>('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()
})
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit be68f0f

Please sign in to comment.