Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
96d75dfc
Commit
96d75dfc
authored
Apr 02, 2024
by
Timothy J. Baek
Browse files
refac: share chat routes
parent
49428eb7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
6 deletions
+13
-6
backend/apps/web/models/chats.py
backend/apps/web/models/chats.py
+7
-0
backend/apps/web/routers/chats.py
backend/apps/web/routers/chats.py
+6
-6
No files found.
backend/apps/web/models/chats.py
View file @
96d75dfc
...
@@ -181,6 +181,13 @@ class ChatTable:
...
@@ -181,6 +181,13 @@ class ChatTable:
.
order_by
(
Chat
.
timestamp
.
desc
())
.
order_by
(
Chat
.
timestamp
.
desc
())
]
]
def
get_chat_by_id
(
self
,
id
:
str
)
->
Optional
[
ChatModel
]:
try
:
chat
=
Chat
.
get
(
Chat
.
id
==
id
)
return
ChatModel
(
**
model_to_dict
(
chat
))
except
:
return
None
def
get_chat_by_id_and_user_id
(
self
,
id
:
str
,
user_id
:
str
)
->
Optional
[
ChatModel
]:
def
get_chat_by_id_and_user_id
(
self
,
id
:
str
,
user_id
:
str
)
->
Optional
[
ChatModel
]:
try
:
try
:
chat
=
Chat
.
get
(
Chat
.
id
==
id
,
Chat
.
user_id
==
user_id
)
chat
=
Chat
.
get
(
Chat
.
id
==
id
,
Chat
.
user_id
==
user_id
)
...
...
backend/apps/web/routers/chats.py
View file @
96d75dfc
...
@@ -226,9 +226,9 @@ async def share_chat_by_id(id: str, user=Depends(get_current_user)):
...
@@ -226,9 +226,9 @@ async def share_chat_by_id(id: str, user=Depends(get_current_user)):
############################
############################
@
router
.
delete
(
"/{id}/share"
,
response_model
=
Optional
[
bool
])
@
router
.
delete
(
"/{
share_
id}/share"
,
response_model
=
Optional
[
bool
])
async
def
delete_shared_chat_by_id
(
id
:
str
,
user
=
Depends
(
get_current_user
)):
async
def
delete_shared_chat_by_id
(
share_
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
(
share_
id
,
user
.
id
)
if
chat
:
if
chat
:
if
not
chat
.
share_id
:
if
not
chat
.
share_id
:
return
False
return
False
...
@@ -248,9 +248,9 @@ async def delete_shared_chat_by_id(id: str, user=Depends(get_current_user)):
...
@@ -248,9 +248,9 @@ async def delete_shared_chat_by_id(id: str, user=Depends(get_current_user)):
############################
############################
@
router
.
get
(
"/share/{id}"
,
response_model
=
Optional
[
ChatResponse
])
@
router
.
get
(
"/share/{
share_
id}"
,
response_model
=
Optional
[
ChatResponse
])
async
def
get_shared_chat_by_id
(
id
:
str
,
user
=
Depends
(
get_current_user
)):
async
def
get_shared_chat_by_id
(
share_
id
:
str
,
user
=
Depends
(
get_current_user
)):
chat
=
Chats
.
get_chat_by_id
_and_user_id
(
id
,
"
shared
"
)
chat
=
Chats
.
get_chat_by_id
(
share
_i
d
)
if
chat
:
if
chat
:
return
ChatResponse
(
**
{
**
chat
.
model_dump
(),
"chat"
:
json
.
loads
(
chat
.
chat
)})
return
ChatResponse
(
**
{
**
chat
.
model_dump
(),
"chat"
:
json
.
loads
(
chat
.
chat
)})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment