This commit is contained in:
@@ -1,13 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
import tempfile
|
||||
|
||||
from flask import jsonify, request, abort, current_app, Response
|
||||
from flask_classful import FlaskView
|
||||
from utils import json_required
|
||||
import opentracing
|
||||
from schemas import SampleSchema
|
||||
import json
|
||||
import uwsgi
|
||||
|
||||
|
||||
class FilterView(FlaskView):
|
||||
sampleschema = SampleSchema(many=False)
|
||||
|
||||
@json_required
|
||||
def post(self):
|
||||
data = request.json
|
||||
if current_app.config.get('DROPALL'):
|
||||
return Response(status=200)
|
||||
|
||||
return Response(status=201)
|
||||
with opentracing.tracer.start_active_span('parseAndValidate'):
|
||||
if 'file' not in request.files:
|
||||
return abort(400, "no file found")
|
||||
else:
|
||||
soundfile = request.files['file']
|
||||
|
||||
if 'description' not in request.form:
|
||||
return abort(400, "no description found")
|
||||
else:
|
||||
description_raw = request.form.get("description")
|
||||
|
||||
if soundfile.content_type != 'audio/wave':
|
||||
current_app.logger.info(f"Input file was not WAV.")
|
||||
return abort(415, 'Input file not a wave file.')
|
||||
try:
|
||||
desc = self.sampleschema.loads(description_raw)
|
||||
except Exception as e:
|
||||
current_app.logger.exception(e)
|
||||
return abort(417, 'Input JSON schema invalid')
|
||||
|
||||
soundfile_handle, soundfile_path = tempfile.mkstemp()
|
||||
soundfile.save(open(soundfile_handle, "wb+"))
|
||||
|
||||
task = {
|
||||
"audio_file_path": soundfile_path,
|
||||
"description": desc
|
||||
}
|
||||
|
||||
uwsgi.mule_msg(json.dumps(task))
|
||||
|
||||
return Response(status=200)
|
||||
|
||||
Reference in New Issue
Block a user