PicList/src/main/migrate/index.ts

53 lines
1.6 KiB
TypeScript
Raw Normal View History

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'
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) => {
// #557 极端情况可能会出现配置不存在,需要重新写入
if (shortKeyConfig === undefined) {
const defaultShortKeyConfig = {
enable: true,
key: 'CommandOrControl+Shift+P',
name: 'upload',
label: '快捷上传'
}
db.set('settings.shortKey[picgo:upload]', defaultShortKeyConfig)
return true
}
if (shortKeyConfig.upload) {
2019-12-19 06:17:21 -05:00
// @ts-ignore
shortKeyConfig['picgo:upload'] = {
enable: true,
key: shortKeyConfig.upload,
name: 'upload',
label: '快捷上传'
2019-09-10 02:38:08 -04:00
}
// @ts-ignore
delete shortKeyConfig.upload
2019-09-11 07:30:08 -04:00
db.set('settings.shortKey', shortKeyConfig)
return true
2019-09-10 02:38:08 -04:00
}
return false
2019-09-10 02:38:08 -04:00
}
2021-07-26 12:15:11 -04:00
const migrateGalleryFromVersion230 = async (configDB: typeof ConfigStore, galleryDB: DBStore) => {
const originGallery: ImgInfo[] = configDB.get('uploaded')
const configPath = configDB.getConfigPath()
const configBakPath = path.join(path.dirname(configPath), 'config-bak.json')
if (fse.existsSync(configBakPath)) {
return
}
// migrate gallery from config to gallery db
2021-08-01 02:50:25 -04:00
if (originGallery && originGallery?.length > 0) {
fse.copyFileSync(configPath, configBakPath)
2021-07-26 12:15:11 -04:00
await galleryDB.insertMany(originGallery)
2021-08-01 02:50:25 -04:00
configDB.set('uploaded', [])
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
}