H
commited on
Commit
·
d8ce288
1
Parent(s):
6d672a7
Fix API key validation api/conversation (#2100)
Browse files### What problem does this PR solve?
#2081
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
- api/apps/api_app.py +11 -1
api/apps/api_app.py
CHANGED
@@ -344,12 +344,22 @@ def completion():
|
|
344 |
@manager.route('/conversation/<conversation_id>', methods=['GET'])
|
345 |
# @login_required
|
346 |
def get(conversation_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
347 |
try:
|
348 |
e, conv = API4ConversationService.get_by_id(conversation_id)
|
349 |
if not e:
|
350 |
return get_data_error_result(retmsg="Conversation not found!")
|
351 |
|
352 |
conv = conv.to_dict()
|
|
|
|
|
|
|
|
|
353 |
for referenct_i in conv['reference']:
|
354 |
if referenct_i is None or len(referenct_i) == 0:
|
355 |
continue
|
@@ -769,4 +779,4 @@ def retrieval():
|
|
769 |
if str(e).find("not_found") > 0:
|
770 |
return get_json_result(data=False, retmsg=f'No chunk found! Check the chunk status please!',
|
771 |
retcode=RetCode.DATA_ERROR)
|
772 |
-
return server_error_response(e)
|
|
|
344 |
@manager.route('/conversation/<conversation_id>', methods=['GET'])
|
345 |
# @login_required
|
346 |
def get(conversation_id):
|
347 |
+
token = request.headers.get('Authorization').split()[1]
|
348 |
+
objs = APIToken.query(token=token)
|
349 |
+
if not objs:
|
350 |
+
return get_json_result(
|
351 |
+
data=False, retmsg='Token is not valid!"', retcode=RetCode.AUTHENTICATION_ERROR)
|
352 |
+
|
353 |
try:
|
354 |
e, conv = API4ConversationService.get_by_id(conversation_id)
|
355 |
if not e:
|
356 |
return get_data_error_result(retmsg="Conversation not found!")
|
357 |
|
358 |
conv = conv.to_dict()
|
359 |
+
if token != APIToken.query(dialog_id=conv['dialog_id'])[0].token:
|
360 |
+
return get_json_result(data=False, retmsg='Token is not valid for this conversation_id!"',
|
361 |
+
retcode=RetCode.AUTHENTICATION_ERROR)
|
362 |
+
|
363 |
for referenct_i in conv['reference']:
|
364 |
if referenct_i is None or len(referenct_i) == 0:
|
365 |
continue
|
|
|
779 |
if str(e).find("not_found") > 0:
|
780 |
return get_json_result(data=False, retmsg=f'No chunk found! Check the chunk status please!',
|
781 |
retcode=RetCode.DATA_ERROR)
|
782 |
+
return server_error_response(e)
|