mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-29 17:27:17 +00:00
New API Endpoint:
Return Item Content in base64 in non JSON format
This commit is contained in:
parent
86f8997473
commit
ddd2c81a97
2 changed files with 13 additions and 15 deletions
|
@ -220,24 +220,19 @@ def get_item(request_dict):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_item_content_encoded_text(request_dict):
|
||||||
|
|
||||||
def get_item_as_txt(request_dict):
|
|
||||||
item_id = request_dict.get('id', None)
|
item_id = request_dict.get('id', None)
|
||||||
|
|
||||||
if not request_dict:
|
if not request_dict:
|
||||||
return {'status': 'error', 'reason': 'Malformed JSON'}, 400
|
return {'status': 'error', 'reason': 'Malformed JSON'}, 400, 1
|
||||||
if not item_id:
|
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):
|
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)
|
item_content = get_item_content(item_id)
|
||||||
base64_output = base64.b64encode((item_content.encode('utf-8')).decode())
|
base64_output = base64.b64encode((item_content.encode('utf-8')))
|
||||||
dict_item = {'id': item_id, 'content': base64_output}
|
|
||||||
|
|
||||||
return dict_item, 200
|
|
||||||
|
|
||||||
|
return base64_output, 200, 0
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
|
@ -312,14 +312,17 @@ def get_item_content():
|
||||||
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
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')
|
@token_required('read_only')
|
||||||
def get_item_content_text():
|
def get_item_content_encoded_text():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
item_id = data.get('id', None)
|
item_id = data.get('id', None)
|
||||||
req_data = {'id': item_id}
|
req_data = {'id': item_id}
|
||||||
res = Item.get_item_as_txt(req_data)
|
res = Item.get_item_content_encoded_text(req_data)
|
||||||
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
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]
|
||||||
|
|
||||||
|
|
||||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
|
Loading…
Reference in a new issue