Skip to content

Commit

Permalink
fix: user can't view model setting in local api server (janhq#1807)
Browse files Browse the repository at this point in the history
* fix: cannot change jan data folder

Signed-off-by: James <[email protected]>

* fix: user can't view model setting in local api server

Signed-off-by: James <[email protected]>

---------

Signed-off-by: James <[email protected]>
Co-authored-by: James <[email protected]>
  • Loading branch information
namchuai and James authored Jan 27, 2024
1 parent 23dfb1c commit 642d7aa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
38 changes: 24 additions & 14 deletions web/hooks/usePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ export const usePath = () => {
const selectedModel = useAtomValue(selectedModelAtom)

const onReviewInFinder = async (type: string) => {
if (!activeThread) return
const activeThreadState = threadStates[activeThread.id]
if (!activeThreadState.isFinishInit) {
alert('Thread is not started yet')
return
// TODO: this logic should be refactored.
if (type !== 'Model') {
if (!activeThread) return
const activeThreadState = threadStates[activeThread.id]
if (!activeThreadState.isFinishInit) {
alert('Thread is not started yet')
return
}
}

const userSpace = await getJanDataFolderPath()
let filePath = undefined
const assistantId = activeThread.assistants[0]?.assistant_id
const assistantId = activeThread?.assistants[0]?.assistant_id
switch (type) {
case 'Engine':
case 'Thread':
filePath = await joinPath(['threads', activeThread.id])
filePath = await joinPath(['threads', activeThread?.id ?? ''])
break
case 'Model':
if (!selectedModel) return
Expand All @@ -44,20 +47,27 @@ export const usePath = () => {
}

const onViewJson = async (type: string) => {
if (!activeThread) return
const activeThreadState = threadStates[activeThread.id]
if (!activeThreadState.isFinishInit) {
alert('Thread is not started yet')
return
// TODO: this logic should be refactored.
if (type !== 'Model') {
if (!activeThread) return
const activeThreadState = threadStates[activeThread.id]
if (!activeThreadState.isFinishInit) {
alert('Thread is not started yet')
return
}
}

const userSpace = await getJanDataFolderPath()
let filePath = undefined
const assistantId = activeThread.assistants[0]?.assistant_id
const assistantId = activeThread?.assistants[0]?.assistant_id
switch (type) {
case 'Engine':
case 'Thread':
filePath = await joinPath(['threads', activeThread.id, 'thread.json'])
filePath = await joinPath([
'threads',
activeThread?.id ?? '',
'thread.json',
])
break
case 'Model':
if (!selectedModel) return
Expand Down
9 changes: 4 additions & 5 deletions web/screens/Settings/Advanced/DataFolder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,17 @@ const DataFolder = () => {
}, [janDataFolderPath, setShowSameDirectory, setShowDirectoryConfirm])

const onUserConfirmed = useCallback(async () => {
const destination = destinationPath
if (!destination) return
if (!destinationPath) return
try {
const appConfiguration: AppConfiguration =
await window.core?.api?.getAppConfigurations()
const currentJanDataFolder = appConfiguration.data_folder
appConfiguration.data_folder = destination
await fs.syncFile(currentJanDataFolder, destination)
appConfiguration.data_folder = destinationPath
await fs.syncFile(currentJanDataFolder, destinationPath)
await window.core?.api?.updateAppConfiguration(appConfiguration)

console.debug(
`File sync finished from ${currentJanDataFolder} to ${destination}`
`File sync finished from ${currentJanDataFolder} to ${destinationPath}`
)

localStorage.setItem(SUCCESS_SET_NEW_DESTINATION, 'true')
Expand Down

0 comments on commit 642d7aa

Please sign in to comment.