New API Endpoint:

Return Item Content in base64 in non JSON format
This commit is contained in:
TonyJabbour 2021-10-05 14:17:39 +02:00
parent 86f8997473
commit ddd2c81a97
2 changed files with 13 additions and 15 deletions

View file

@ -220,24 +220,19 @@ def get_item(request_dict):
def get_item_as_txt(request_dict):
def get_item_content_encoded_text(request_dict):
item_id = request_dict.get('id', None)
if not request_dict:
return {'status': 'error', 'reason': 'Malformed JSON'}, 400
return {'status': 'error', 'reason': 'Malformed JSON'}, 400, 1
if not item_id:
return {'status': 'error', 'reason': 'Mandatory parameter(s) not provided'}, 400
return {'status': 'error', 'reason': 'Mandatory parameter(s) not provided'}, 400, 1
if not exist_item(item_id):
return {'status': 'error', 'reason': 'Item not found'}, 404
return {'status': 'error', 'reason': 'Item not found'}, 404, 1
item_content = get_item_content(item_id)
base64_output = base64.b64encode((item_content.encode('utf-8')).decode())
dict_item = {'id': item_id, 'content': base64_output}
return dict_item, 200
base64_output = base64.b64encode((item_content.encode('utf-8')))
return base64_output, 200, 0
###

View file

@ -312,14 +312,17 @@ def get_item_content():
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
@restApi.route("api/v1/get/item/content/text", methods=['POST'])
@restApi.route("api/v1/get/item/content/encoded/text", methods=['POST'])
@token_required('read_only')
def get_item_content_text():
def get_item_content_encoded_text():
data = request.get_json()
item_id = data.get('id', None)
req_data = {'id': item_id}
res = Item.get_item_as_txt(req_data)
res = Item.get_item_content_encoded_text(req_data)
if res[2] == 1:
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
else:
return res[0], res[1]
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #