2021-07-26 12:15:11 -04:00
|
|
|
import { DBStore } from '@picgo/store'
|
|
|
|
import ConfigStore from '~/main/apis/core/datastore'
|
|
|
|
import path from 'path'
|
|
|
|
import fse from 'fs-extra'
|
2022-01-08 02:44:09 -05:00
|
|
|
import { PicGo as PicGoCore } from 'picgo'
|
2022-08-20 04:44:55 -04:00
|
|
|
import { T } from '~/main/i18n'
|
2019-09-10 02:38:08 -04:00
|
|
|
// from v2.1.2
|
2021-07-26 12:15:11 -04:00
|
|
|
const updateShortKeyFromVersion212 = (db: typeof ConfigStore, shortKeyConfig: IShortKeyConfigs | IOldShortKeyConfigs) => {
|
2020-08-22 10:15:46 -04:00
|
|
|
// #557 极端情况可能会出现配置不存在,需要重新写入
|
|
|
|
if (shortKeyConfig === undefined) {
|
|
|
|
const defaultShortKeyConfig = {
|
|
|
|
enable: true,
|
|
|
|
key: 'CommandOrControl+Shift+P',
|
|
|
|
name: 'upload',
|
2022-01-11 08:50:29 -05:00
|
|
|
label: T('QUICK_UPLOAD')
|
2020-08-22 10:15:46 -04:00
|
|
|
}
|
|
|
|
db.set('settings.shortKey[picgo:upload]', defaultShortKeyConfig)
|
|
|
|
return true
|
|
|
|
}
|
2019-09-11 03:31:27 -04:00
|
|
|
if (shortKeyConfig.upload) {
|
2019-12-19 06:17:21 -05:00
|
|
|
// @ts-ignore
|
2019-09-11 03:31:27 -04:00
|
|
|
shortKeyConfig['picgo:upload'] = {
|
|
|
|
enable: true,
|
|
|
|
key: shortKeyConfig.upload,
|
2019-12-22 04:22:32 -05:00
|
|
|
name: 'upload',
|
2022-01-11 08:50:29 -05:00
|
|
|
label: T('QUICK_UPLOAD')
|
2019-09-10 02:38:08 -04:00
|
|
|
}
|
2021-04-23 12:44:49 -04:00
|
|
|
// @ts-ignore
|
2019-09-11 03:31:27 -04:00
|
|
|
delete shortKeyConfig.upload
|
2019-09-11 07:30:08 -04:00
|
|
|
db.set('settings.shortKey', shortKeyConfig)
|
2020-08-22 10:15:46 -04:00
|
|
|
return true
|
2019-09-10 02:38:08 -04:00
|
|
|
}
|
2020-08-22 10:15:46 -04:00
|
|
|
return false
|
2019-09-10 02:38:08 -04:00
|
|
|
}
|
|
|
|
|
2021-08-01 05:02:54 -04:00
|
|
|
const migrateGalleryFromVersion230 = async (configDB: typeof ConfigStore, galleryDB: DBStore, picgo: PicGoCore) => {
|
2022-06-12 08:20:08 -04:00
|
|
|
const originGallery: ImgInfo[] = picgo.getConfig('uploaded')
|
2022-04-04 07:22:30 -04:00
|
|
|
// if hasMigrate, we don't need to migrate
|
|
|
|
const hasMigrate: boolean = configDB.get('__migrateUploaded')
|
|
|
|
if (hasMigrate) {
|
|
|
|
return
|
|
|
|
}
|
2021-07-26 12:15:11 -04:00
|
|
|
const configPath = configDB.getConfigPath()
|
2021-08-01 05:02:54 -04:00
|
|
|
const configBakPath = path.join(path.dirname(configPath), 'config.bak.json')
|
2021-07-26 12:15:11 -04:00
|
|
|
// migrate gallery from config to gallery db
|
2021-08-20 22:42:52 -04:00
|
|
|
if (originGallery && Array.isArray(originGallery) && originGallery?.length > 0) {
|
2021-08-01 05:02:54 -04:00
|
|
|
if (fse.existsSync(configBakPath)) {
|
|
|
|
fse.copyFileSync(configPath, configBakPath)
|
|
|
|
}
|
2021-07-26 12:15:11 -04:00
|
|
|
await galleryDB.insertMany(originGallery)
|
2021-08-01 05:02:54 -04:00
|
|
|
picgo.saveConfig({
|
2022-04-04 07:22:30 -04:00
|
|
|
uploaded: [],
|
|
|
|
__migrateUploaded: true
|
2021-08-01 05:02:54 -04:00
|
|
|
})
|
2021-07-26 12:15:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 02:38:08 -04:00
|
|
|
export {
|
2021-07-26 12:15:11 -04:00
|
|
|
updateShortKeyFromVersion212,
|
|
|
|
migrateGalleryFromVersion230
|
2019-09-10 02:38:08 -04:00
|
|
|
}
|