Browse Source

Fix API key validation api/conversation (#2100)

### What problem does this PR solve?

#2081 

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
tags/v0.11.0
H 1 year ago
parent
commit
13785edaae
No account linked to committer's email address
1 changed files with 11 additions and 1 deletions
  1. 11
    1
      api/apps/api_app.py

+ 11
- 1
api/apps/api_app.py View File

@manager.route('/conversation/<conversation_id>', methods=['GET']) @manager.route('/conversation/<conversation_id>', methods=['GET'])
# @login_required # @login_required
def get(conversation_id): def get(conversation_id):
token = request.headers.get('Authorization').split()[1]
objs = APIToken.query(token=token)
if not objs:
return get_json_result(
data=False, retmsg='Token is not valid!"', retcode=RetCode.AUTHENTICATION_ERROR)
try: try:
e, conv = API4ConversationService.get_by_id(conversation_id) e, conv = API4ConversationService.get_by_id(conversation_id)
if not e: if not e:
return get_data_error_result(retmsg="Conversation not found!") return get_data_error_result(retmsg="Conversation not found!")


conv = conv.to_dict() conv = conv.to_dict()
if token != APIToken.query(dialog_id=conv['dialog_id'])[0].token:
return get_json_result(data=False, retmsg='Token is not valid for this conversation_id!"',
retcode=RetCode.AUTHENTICATION_ERROR)
for referenct_i in conv['reference']: for referenct_i in conv['reference']:
if referenct_i is None or len(referenct_i) == 0: if referenct_i is None or len(referenct_i) == 0:
continue continue
if str(e).find("not_found") > 0: if str(e).find("not_found") > 0:
return get_json_result(data=False, retmsg=f'No chunk found! Check the chunk status please!', return get_json_result(data=False, retmsg=f'No chunk found! Check the chunk status please!',
retcode=RetCode.DATA_ERROR) retcode=RetCode.DATA_ERROR)
return server_error_response(e)
return server_error_response(e)

Loading…
Cancel
Save