jan/electron/utils/migration.ts
Louis 5250061c11
feat: Jan Server, API and decoupled clients (#948)
* chore: expose fs apis

* chore: correct electron import path

* update download api

Signed-off-by: James <james@jan.ai>

* update chat_completion

Signed-off-by: James <james@jan.ai>

* fix electron import

Signed-off-by: James <james@jan.ai>

* feat: adding API support at 1337 (#991)

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>

* feat: Add /chat/completion api and handler

* chore: add todo for modelList

* chore: read engine.json for openai chat_completion (#1030)

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>

* refactor: move routes to shared node module

* refactor: exported modules from core with types (#1172)

* refactor: exported modules from core with types

* fix: fix file reading args

* refactor: fileManager handles

* fix: app issues with server refactoring

* refactor: shared server module (#1210)

* chore: resolve main

* chore: update makefile

---------

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
Co-authored-by: NamH <NamNh0122@gmail.com>
Co-authored-by: hiro <vuonghoainam.work@gmail.com>
2023-12-28 17:57:39 +07:00

31 lines
1.1 KiB
TypeScript

import { app } from 'electron'
import { join } from 'path'
import { rmdir } from 'fs'
import Store from 'electron-store'
import { userSpacePath } from './path'
/**
* Migrates the extensions by deleting the `extensions` directory in the user data path.
* If the `migrated_version` key in the `Store` object does not match the current app version,
* the function deletes the `extensions` directory and sets the `migrated_version` key to the current app version.
* @returns A Promise that resolves when the migration is complete.
*/
export function migrateExtensions() {
return new Promise((resolve) => {
const store = new Store()
if (store.get('migrated_version') !== app.getVersion()) {
console.debug('start migration:', store.get('migrated_version'))
const fullPath = join(userSpacePath, 'extensions')
rmdir(fullPath, { recursive: true }, function (err) {
if (err) console.error(err)
store.set('migrated_version', app.getVersion())
console.debug('migrate extensions done')
resolve(undefined)
})
} else {
resolve(undefined)
}
})
}