fix: model migration stopped working (#1378)

This commit is contained in:
Louis 2024-01-05 13:50:17 +07:00 committed by GitHub
parent 9609c4f83e
commit 1400ef053c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,17 +50,16 @@ export default class JanModelExtension implements ModelExtension {
private async copyModelsToHomeDir() { private async copyModelsToHomeDir() {
try { try {
// list all of the files under the home directory
// Check for migration conditions
if (await fs.existsSync(JanModelExtension._homeDir)) { if (
// ignore if the model is already downloaded localStorage.getItem(`${EXTENSION_NAME}-version`) === VERSION &&
(await fs.existsSync(JanModelExtension._homeDir))
) {
// ignore if the there is no need to migrate
console.debug('Models already persisted.') console.debug('Models already persisted.')
return return
} }
// Get available models
const readyModels = (await this.getDownloadedModels()).map((e) => e.id)
// copy models folder from resources to home directory // copy models folder from resources to home directory
const resourePath = await getResourcePath() const resourePath = await getResourcePath()
const srcPath = await joinPath([resourePath, 'models']) const srcPath = await joinPath([resourePath, 'models'])
@ -72,18 +71,7 @@ export default class JanModelExtension implements ModelExtension {
console.debug('Finished syncing models') console.debug('Finished syncing models')
const reconfigureModels = (await this.getConfiguredModels()).filter((e) =>
readyModels.includes(e.id)
)
console.debug('Finished updating downloaded models')
// update back the status
await Promise.all(
reconfigureModels.map(async (model) => this.saveModel(model))
)
// Finished migration // Finished migration
localStorage.setItem(`${EXTENSION_NAME}-version`, VERSION) localStorage.setItem(`${EXTENSION_NAME}-version`, VERSION)
} catch (err) { } catch (err) {
console.error(err) console.error(err)
@ -203,7 +191,7 @@ export default class JanModelExtension implements ModelExtension {
): Promise<Model[]> { ): Promise<Model[]> {
try { try {
if (!(await fs.existsSync(JanModelExtension._homeDir))) { if (!(await fs.existsSync(JanModelExtension._homeDir))) {
console.error('Model folder not found') console.debug('Model folder not found')
return [] return []
} }