diff --git a/backend/apps/web/routers/chats.py b/backend/apps/web/routers/chats.py index 14b97db88..2b8e85284 100644 --- a/backend/apps/web/routers/chats.py +++ b/backend/apps/web/routers/chats.py @@ -226,16 +226,17 @@ async def share_chat_by_id(id: str, user=Depends(get_current_user)): ############################ -@router.delete("/{share_id}/share", response_model=Optional[bool]) -async def delete_shared_chat_by_id(share_id: str, user=Depends(get_current_user)): - chat = Chats.get_chat_by_id_and_user_id(share_id, user.id) +@router.delete("/{id}/share", response_model=Optional[bool]) +async def delete_shared_chat_by_id(id: str, user=Depends(get_current_user)): + chat = Chats.get_chat_by_id_and_user_id(id, user.id) if chat: if not chat.share_id: return False - result = Chats.delete_shared_chat_by_chat_id(chat.id) - update_result = Chats.update_chat_share_id_by_id(chat.id, None) - return result and update_result + result = Chats.delete_shared_chat_by_chat_id(id) + update_result = Chats.update_chat_share_id_by_id(id, None) + + return result and update_result != None else: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, diff --git a/src/lib/components/chat/ShareChatModal.svelte b/src/lib/components/chat/ShareChatModal.svelte index df0510e62..286592eb5 100644 --- a/src/lib/components/chat/ShareChatModal.svelte +++ b/src/lib/components/chat/ShareChatModal.svelte @@ -5,7 +5,7 @@ const { saveAs } = fileSaver; import { toast } from 'svelte-sonner'; - import { getChatById, shareChatById } from '$lib/apis/chats'; + import { deleteSharedChatById, getChatById, shareChatById } from '$lib/apis/chats'; import { chatId, modelfiles } from '$lib/stores'; import { copyToClipboard } from '$lib/utils'; @@ -28,6 +28,7 @@ toast.success($i18n.t('Copied shared conversation URL to clipboard!')); copyToClipboard(chatShareUrl); + chat = await getChatById(localStorage.token, $chatId); }; const shareChat = async () => { @@ -78,6 +79,7 @@ onMount(async () => { chat = await getChatById(localStorage.token, $chatId); + console.log(chat); }); @@ -105,53 +107,77 @@
-
-
- Messages you send after creating your link won't be shared. Anyone with the URL will be able - to view the shared chat. -
+ {#if chat} +
+
+ {#if chat.share_id} + You have shared this chat before. + Click here to + + if (res) { + chat = await getChatById(localStorage.token, $chatId); + } + }}>delete this link and create a new shared link. + {:else} + Messages you send after creating your link won't be shared. Anyone with the URL will be + able to view the shared chat. + {/if} +
- -
-
-
{$i18n.t('or')}
- +
+
+
+ + + +
+
+
{$i18n.t('or')}
+ +
-
+ {/if}