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
4ea2eb79
Commit
4ea2eb79
authored
Apr 27, 2024
by
Timothy J. Baek
Browse files
refac
parent
10f27eba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
60 deletions
+60
-60
backend/apps/web/routers/chats.py
backend/apps/web/routers/chats.py
+60
-60
No files found.
backend/apps/web/routers/chats.py
View file @
4ea2eb79
...
...
@@ -48,6 +48,27 @@ async def get_session_user_chat_list(
return
Chats
.
get_chat_list_by_user_id
(
user
.
id
,
skip
,
limit
)
############################
# DeleteAllChats
############################
@
router
.
delete
(
"/"
,
response_model
=
bool
)
async
def
delete_all_user_chats
(
request
:
Request
,
user
=
Depends
(
get_current_user
)):
if
(
user
.
role
==
"user"
and
not
request
.
app
.
state
.
USER_PERMISSIONS
[
"chat"
][
"deletion"
]
):
raise
HTTPException
(
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
detail
=
ERROR_MESSAGES
.
ACCESS_PROHIBITED
,
)
result
=
Chats
.
delete_chats_by_user_id
(
user
.
id
)
return
result
############################
# GetUserChatList
############################
...
...
@@ -120,45 +141,6 @@ async def create_new_chat(form_data: ChatForm, user=Depends(get_current_user)):
)
############################
# GetAllTags
############################
@
router
.
get
(
"/tags/all"
,
response_model
=
List
[
TagModel
])
async
def
get_all_tags
(
user
=
Depends
(
get_current_user
)):
try
:
tags
=
Tags
.
get_tags_by_user_id
(
user
.
id
)
return
tags
except
Exception
as
e
:
log
.
exception
(
e
)
raise
HTTPException
(
status_code
=
status
.
HTTP_400_BAD_REQUEST
,
detail
=
ERROR_MESSAGES
.
DEFAULT
()
)
############################
# GetChatsByTags
############################
@
router
.
get
(
"/tags/tag/{tag_name}"
,
response_model
=
List
[
ChatTitleIdResponse
])
async
def
get_user_chats_by_tag_name
(
tag_name
:
str
,
user
=
Depends
(
get_current_user
),
skip
:
int
=
0
,
limit
:
int
=
50
):
chat_ids
=
[
chat_id_tag
.
chat_id
for
chat_id_tag
in
Tags
.
get_chat_ids_by_tag_name_and_user_id
(
tag_name
,
user
.
id
)
]
chats
=
Chats
.
get_chat_list_by_chat_ids
(
chat_ids
,
skip
,
limit
)
if
len
(
chats
)
==
0
:
Tags
.
delete_tag_by_tag_name_and_user_id
(
tag_name
,
user
.
id
)
return
chats
############################
# GetChatById
############################
...
...
@@ -316,6 +298,45 @@ async def get_shared_chat_by_id(share_id: str, user=Depends(get_current_user)):
)
############################
# GetAllTags
############################
@
router
.
get
(
"/tags/all"
,
response_model
=
List
[
TagModel
])
async
def
get_all_tags
(
user
=
Depends
(
get_current_user
)):
try
:
tags
=
Tags
.
get_tags_by_user_id
(
user
.
id
)
return
tags
except
Exception
as
e
:
log
.
exception
(
e
)
raise
HTTPException
(
status_code
=
status
.
HTTP_400_BAD_REQUEST
,
detail
=
ERROR_MESSAGES
.
DEFAULT
()
)
############################
# GetChatsByTags
############################
@
router
.
get
(
"/tags/tag/{tag_name}"
,
response_model
=
List
[
ChatTitleIdResponse
])
async
def
get_user_chats_by_tag_name
(
tag_name
:
str
,
user
=
Depends
(
get_current_user
),
skip
:
int
=
0
,
limit
:
int
=
50
):
chat_ids
=
[
chat_id_tag
.
chat_id
for
chat_id_tag
in
Tags
.
get_chat_ids_by_tag_name_and_user_id
(
tag_name
,
user
.
id
)
]
chats
=
Chats
.
get_chat_list_by_chat_ids
(
chat_ids
,
skip
,
limit
)
if
len
(
chats
)
==
0
:
Tags
.
delete_tag_by_tag_name_and_user_id
(
tag_name
,
user
.
id
)
return
chats
############################
# GetChatTagsById
############################
...
...
@@ -396,24 +417,3 @@ async def delete_all_chat_tags_by_id(id: str, user=Depends(get_current_user)):
raise
HTTPException
(
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
detail
=
ERROR_MESSAGES
.
NOT_FOUND
)
############################
# DeleteAllChats
############################
@
router
.
delete
(
"/"
,
response_model
=
bool
)
async
def
delete_all_user_chats
(
request
:
Request
,
user
=
Depends
(
get_current_user
)):
if
(
user
.
role
==
"user"
and
not
request
.
app
.
state
.
USER_PERMISSIONS
[
"chat"
][
"deletion"
]
):
raise
HTTPException
(
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
detail
=
ERROR_MESSAGES
.
ACCESS_PROHIBITED
,
)
result
=
Chats
.
delete_chats_by_user_id
(
user
.
id
)
return
result
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