mirror of
https://github.com/open-webui/open-webui
synced 2024-11-16 13:40:55 +00:00
feat: update shared chat
This commit is contained in:
parent
0b823f90e6
commit
9975cb17a9
@ -98,7 +98,7 @@ class ChatTable:
|
|||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def insert_shared_chat(self, chat_id: str) -> Optional[ChatModel]:
|
def insert_shared_chat_by_chat_id(self, chat_id: str) -> Optional[ChatModel]:
|
||||||
# Get the existing chat to share
|
# Get the existing chat to share
|
||||||
chat = Chat.get(Chat.id == chat_id)
|
chat = Chat.get(Chat.id == chat_id)
|
||||||
# Check if the chat is already shared
|
# Check if the chat is already shared
|
||||||
@ -122,6 +122,24 @@ class ChatTable:
|
|||||||
|
|
||||||
return shared_chat if (shared_result and result) else None
|
return shared_chat if (shared_result and result) else None
|
||||||
|
|
||||||
|
def update_shared_chat_by_chat_id(self, chat_id: str) -> Optional[ChatModel]:
|
||||||
|
try:
|
||||||
|
print("update_shared_chat_by_id")
|
||||||
|
chat = Chat.get(Chat.id == chat_id)
|
||||||
|
print(chat)
|
||||||
|
|
||||||
|
query = Chat.update(
|
||||||
|
title=chat.title,
|
||||||
|
chat=chat.chat,
|
||||||
|
).where(Chat.id == chat.share_id)
|
||||||
|
|
||||||
|
query.execute()
|
||||||
|
|
||||||
|
chat = Chat.get(Chat.id == chat.share_id)
|
||||||
|
return ChatModel(**model_to_dict(chat))
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
def delete_shared_chat_by_chat_id(self, chat_id: str) -> bool:
|
def delete_shared_chat_by_chat_id(self, chat_id: str) -> bool:
|
||||||
try:
|
try:
|
||||||
query = Chat.delete().where(Chat.user_id == f"shared-{chat_id}")
|
query = Chat.delete().where(Chat.user_id == f"shared-{chat_id}")
|
||||||
|
@ -199,12 +199,12 @@ async def share_chat_by_id(id: str, user=Depends(get_current_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)
|
||||||
if chat:
|
if chat:
|
||||||
if chat.share_id:
|
if chat.share_id:
|
||||||
shared_chat = Chats.get_chat_by_id_and_user_id(chat.share_id, "shared")
|
shared_chat = Chats.update_shared_chat_by_chat_id(chat.id)
|
||||||
return ChatResponse(
|
return ChatResponse(
|
||||||
**{**shared_chat.model_dump(), "chat": json.loads(shared_chat.chat)}
|
**{**shared_chat.model_dump(), "chat": json.loads(shared_chat.chat)}
|
||||||
)
|
)
|
||||||
|
|
||||||
shared_chat = Chats.insert_shared_chat(chat.id)
|
shared_chat = Chats.insert_shared_chat_by_chat_id(chat.id)
|
||||||
if not shared_chat:
|
if not shared_chat:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
|
@ -18,13 +18,8 @@
|
|||||||
const shareLocalChat = async () => {
|
const shareLocalChat = async () => {
|
||||||
const _chat = chat;
|
const _chat = chat;
|
||||||
|
|
||||||
let chatShareUrl = '';
|
const sharedChat = await shareChatById(localStorage.token, $chatId);
|
||||||
if (_chat.share_id) {
|
const chatShareUrl = `${window.location.origin}/s/${sharedChat.id}`;
|
||||||
chatShareUrl = `${window.location.origin}/s/${_chat.share_id}`;
|
|
||||||
} else {
|
|
||||||
const sharedChat = await shareChatById(localStorage.token, $chatId);
|
|
||||||
chatShareUrl = `${window.location.origin}/s/${sharedChat.id}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
toast.success($i18n.t('Copied shared conversation URL to clipboard!'));
|
toast.success($i18n.t('Copied shared conversation URL to clipboard!'));
|
||||||
copyToClipboard(chatShareUrl);
|
copyToClipboard(chatShareUrl);
|
||||||
|
Loading…
Reference in New Issue
Block a user