Commit 0c30a085 authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

fix: non existent chat page issue

parent b777b6d2
...@@ -75,7 +75,14 @@ async def get_chat_by_id(id: str, cred=Depends(bearer_scheme)): ...@@ -75,7 +75,14 @@ async def get_chat_by_id(id: str, cred=Depends(bearer_scheme)):
if user: if user:
chat = Chats.get_chat_by_id_and_user_id(id, user.id) chat = Chats.get_chat_by_id_and_user_id(id, user.id)
return ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
if chat:
return ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
else:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=ERROR_MESSAGES.NOT_FOUND,
)
else: else:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, status_code=status.HTTP_401_UNAUTHORIZED,
......
...@@ -26,5 +26,6 @@ class ERROR_MESSAGES(str, Enum): ...@@ -26,5 +26,6 @@ class ERROR_MESSAGES(str, Enum):
ACTION_PROHIBITED = ( ACTION_PROHIBITED = (
"The requested action has been restricted as a security measure." "The requested action has been restricted as a security measure."
) )
NOT_FOUND = "We could not find what you're looking for :/"
USER_NOT_FOUND = "We could not find what you're looking for :/" USER_NOT_FOUND = "We could not find what you're looking for :/"
MALICIOUS = "Unusual activities detected, please try again in a few minutes." MALICIOUS = "Unusual activities detected, please try again in a few minutes."
...@@ -71,40 +71,45 @@ ...@@ -71,40 +71,45 @@
const loadChat = async () => { const loadChat = async () => {
await chatId.set($page.params.id); await chatId.set($page.params.id);
chat = await getChatById(localStorage.token, $chatId); chat = await getChatById(localStorage.token, $chatId).catch(async (error) => {
await goto('/');
const chatContent = chat.chat; return null;
});
if (chatContent) {
console.log(chatContent); if (chat) {
const chatContent = chat.chat;
selectedModels =
(chatContent?.models ?? undefined) !== undefined if (chatContent) {
? chatContent.models console.log(chatContent);
: [chatContent.model ?? ''];
history = selectedModels =
(chatContent?.history ?? undefined) !== undefined (chatContent?.models ?? undefined) !== undefined
? chatContent.history ? chatContent.models
: convertMessagesToHistory(chatContent.messages); : [chatContent.model ?? ''];
title = chatContent.title; history =
(chatContent?.history ?? undefined) !== undefined
let _settings = JSON.parse(localStorage.getItem('settings') ?? '{}'); ? chatContent.history
await settings.set({ : convertMessagesToHistory(chatContent.messages);
..._settings, title = chatContent.title;
system: chatContent.system ?? _settings.system,
options: chatContent.options ?? _settings.options let _settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
}); await settings.set({
autoScroll = true; ..._settings,
await tick(); system: chatContent.system ?? _settings.system,
options: chatContent.options ?? _settings.options
});
autoScroll = true;
await tick();
if (messages.length > 0) { if (messages.length > 0) {
history.messages[messages.at(-1).id].done = true; history.messages[messages.at(-1).id].done = true;
} }
await tick(); await tick();
return true; return true;
} else { } else {
return null; return null;
}
} }
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment