This commit is contained in:
parent
bdfdd03c54
commit
81e96b4162
@ -35,33 +35,31 @@ class SampleResource(Resource):
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
if 'file' not in request.files:
|
if 'file' not in request.files:
|
||||||
return {"status": "error", "message": "no file found"}, 469
|
return {"err_msg": "no file found"}, 469
|
||||||
else:
|
else:
|
||||||
soundfile = request.files['file']
|
soundfile = request.files['file']
|
||||||
|
|
||||||
if 'description' not in request.form:
|
if 'description' not in request.form:
|
||||||
return {"status": "error", "message": "no description found"}, 470
|
return {"err_msg": "no description found"}, 470
|
||||||
else:
|
else:
|
||||||
description = request.form.get("description")
|
description = request.form.get("description")
|
||||||
|
|
||||||
if soundfile.content_type != 'audio/wave':
|
if soundfile.content_type != 'audio/wave':
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
f"Input file was not WAV.")
|
f"Input file was not WAV.")
|
||||||
return {'status': 'error', 'message': 'Input file not a wave file.'}, 415
|
return {'err_msg': 'Input file not a wave file.'}, 415
|
||||||
|
|
||||||
try:
|
try:
|
||||||
desc = json.loads(description)
|
desc = json.loads(description)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOGGER.exception(e)
|
LOGGER.exception(e)
|
||||||
return {'status': 'error',
|
return {'err_msg': 'Input JSON could not be parsed'}, 400
|
||||||
'message': 'Input JSON could not be parsed'}, 400
|
|
||||||
|
|
||||||
validate_errors = SampleSchema().validate(desc)
|
validate_errors = SampleSchema().validate(desc)
|
||||||
if validate_errors:
|
if validate_errors:
|
||||||
LOGGER.error(
|
LOGGER.error(
|
||||||
"Input JSON did not conform to schema. It was: {}", desc)
|
"Input JSON did not conform to schema. It was: {}", desc)
|
||||||
return {'status': 'error',
|
return {'err_msg': 'Input JSON schema invalid'}, 417
|
||||||
'message': 'Input JSON schema invalid'}, 417
|
|
||||||
|
|
||||||
xeger = Xeger(limit=30)
|
xeger = Xeger(limit=30)
|
||||||
generated_tag = xeger.xeger(r'^[a-zA-Z]+[0-9a-zA-Z_]*$')
|
generated_tag = xeger.xeger(r'^[a-zA-Z]+[0-9a-zA-Z_]*$')
|
||||||
@ -87,11 +85,11 @@ class SampleResource(Resource):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOGGER.exception(e)
|
LOGGER.exception(e)
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
return {"status": "exception", "message": str(
|
return {"err_msg": str(
|
||||||
e), "hint": "DB or downstream service error"}, 569
|
e), "hint": "DB or downstream service error"}, 569
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return {"status": "ok", "message": generated_tag}, 200
|
return {"tag": generated_tag}, 200
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
"""
|
"""
|
||||||
@ -99,7 +97,7 @@ class SampleResource(Resource):
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
samples = SampleMetadata.query.all()
|
samples = SampleMetadata.query.all()
|
||||||
return jsonify({"status": "ok", "message": list(samples)}), 200
|
return list(samples), 200
|
||||||
|
|
||||||
|
|
||||||
class SampleParameterResource(Resource):
|
class SampleParameterResource(Resource):
|
||||||
@ -114,4 +112,4 @@ class SampleParameterResource(Resource):
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
sample = SampleMetadata.query.filter_by(tag=tag).first_or_404()
|
sample = SampleMetadata.query.filter_by(tag=tag).first_or_404()
|
||||||
return jsonify({"status": "ok", "message": sample}), 200
|
return sample, 200
|
||||||
|
Loading…
Reference in New Issue
Block a user