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