fix: migration wrong directory (#3278)

* fix: migration wrong directory

* reload model after migration

Signed-off-by: James <namnh0122@gmail.com>

---------

Signed-off-by: James <namnh0122@gmail.com>
This commit is contained in:
NamH 2024-08-06 17:15:24 +07:00 committed by GitHub
parent 44a6401000
commit 7fb1354287
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 18 additions and 8 deletions

View File

@ -231,7 +231,10 @@ export function handleAppIPCs() {
const destinationFolderPath = join(configration.data_folder, 'models')
if (!existsSync(destinationFolderPath)) mkdirSync(destinationFolderPath)
console.log('destinationFolderPath', destinationFolderPath)
console.log(
`Syncing model from ${allModelFolders} to ${destinationFolderPath}`
)
const reflect = require('@alumna/reflect')
for (const modelName of allModelFolders) {
@ -305,7 +308,6 @@ export function handleAppIPCs() {
src: modelFolderPath,
dest: destinationPath,
recursive: true,
exclude: ['model.json'],
delete: false,
overwrite: true,
errorOnExist: false,

View File

@ -64,6 +64,7 @@ const host = '127.0.0.1'
app
.whenReady()
.then(setupCore)
.then(() => {
if (!gotTheLock) {
app.quit()
@ -119,7 +120,6 @@ app
log.info(`stdout: ${stdout}`)
})
})
.then(setupCore)
.then(createUserSpace)
.then(migrate)
.then(setupMenu)

View File

@ -4,7 +4,6 @@ import { join } from 'path'
import { AppConfiguration } from '@janhq/core/node'
import os from 'os'
const configurationFileName = 'settings.json'
const defaultJanDataFolder = join(os.homedir(), 'jan')
@ -60,6 +59,7 @@ export const getAppConfigurations = (): AppConfiguration => {
// Retrieve Application Support folder path
// Fallback to user home directory if not found
const configurationFile = getConfigurationFilePath()
console.debug('getAppConfiguration file path', configurationFile)
if (!existsSync(configurationFile)) {
// create default app config if we don't have one
@ -74,6 +74,7 @@ export const getAppConfigurations = (): AppConfiguration => {
const appConfigurations: AppConfiguration = JSON.parse(
readFileSync(configurationFile, 'utf-8')
)
console.debug('app config', JSON.stringify(appConfigurations))
return appConfigurations
} catch (err) {
console.error(
@ -86,7 +87,7 @@ export const getAppConfigurations = (): AppConfiguration => {
const getConfigurationFilePath = () =>
join(
global.core?.appPath() ||
process.env[process.platform == 'win32' ? 'USERPROFILE' : 'HOME'],
process.env[process.platform == 'win32' ? 'USERPROFILE' : 'HOME'],
configurationFileName
)

View File

@ -11,6 +11,8 @@ import Spinner from '@/containers/Loader/Spinner'
import useMigratingData from '@/hooks/useMigratingData'
import useModels from '@/hooks/useModels'
import { didShowMigrationWarningAtom } from '@/helpers/atoms/AppConfig.atom'
export const showMigrationModalAtom = atom<boolean>(false)
@ -29,6 +31,7 @@ const ModalMigrations = () => {
useState<MigrationState>('idle')
const [modelMigrationState, setModelMigrationState] =
useState<MigrationState>('idle')
const { getModels } = useModels()
const getStepTitle = () => {
switch (step) {
@ -71,7 +74,8 @@ const ModalMigrations = () => {
setStep(2)
await migratingModels()
await migrationThreadsAndMessages()
}, [migratingModels, migrationThreadsAndMessages])
getModels()
}, [migratingModels, migrationThreadsAndMessages, getModels])
const onDismiss = useCallback(() => {
setStep(1)

View File

@ -43,10 +43,13 @@ const DataMigration: React.FC = () => {
<div className="flex w-full flex-col items-start justify-between gap-4 border-b border-[hsla(var(--app-border))] py-4 first:pt-0 last:border-none sm:flex-row">
<div className="flex-shrink-0 space-y-1">
<div className="flex gap-x-2">
<h6 className="font-semibold capitalize">Clear logs</h6>
<h6 className="font-semibold capitalize">
Migrate data from old version of Jan app
</h6>
</div>
<p className="font-medium leading-relaxed text-[hsla(var(--text-secondary))]">
Clear all logs from Jan app.
Migrate multiple times can cause duplicate threads, please consider
using the remove threads button to clean up existing threads data
</p>
</div>
<div className="flex flex-row gap-x-2">