This commit is contained in:
parent
dfa848b1d8
commit
7ef991912c
@ -5,6 +5,7 @@ from minio.error import BucketAlreadyExists, BucketAlreadyOwnedByYou, ResponseEr
|
||||
from marshmallow import ValidationError
|
||||
from utils import storage
|
||||
from schemas import DescriptionSchema
|
||||
import opentracing
|
||||
|
||||
|
||||
class ObjectView(FlaskView):
|
||||
@ -23,40 +24,51 @@ class ObjectView(FlaskView):
|
||||
|
||||
def post(self):
|
||||
# get important data from the request
|
||||
try:
|
||||
description = self.description_schema.loads(request.form.get('description'))
|
||||
except ValidationError as e:
|
||||
return abort(400, str(e))
|
||||
with opentracing.tracer.start_active_span('parseAndValidate'):
|
||||
try:
|
||||
description = self.description_schema.loads(request.form.get('description'))
|
||||
except ValidationError as e:
|
||||
return abort(400, str(e))
|
||||
|
||||
# get and validate file
|
||||
file = request.files['soundFile']
|
||||
# get and validate file
|
||||
file = request.files['soundFile']
|
||||
|
||||
if file.content_type != 'audio/wave':
|
||||
return abort(400, f"{file.content_type} is not audio/wave")
|
||||
if file.content_type != 'audio/wave':
|
||||
return abort(400, f"{file.content_type} is not audio/wave")
|
||||
|
||||
if file.content_length <= 0:
|
||||
return abort(411, f"Content length for soundFile is not a positive integer or missing.")
|
||||
if file.content_length <= 0:
|
||||
return abort(411, f"Content length for soundFile is not a positive integer or missing.")
|
||||
|
||||
# create bucket if necessary
|
||||
try:
|
||||
storage.connection.make_bucket(current_app.config['MINIO_BUCKET_NAME'])
|
||||
with opentracing.tracer.start_active_span('ensureBuckets'):
|
||||
# create bucket if necessary
|
||||
try:
|
||||
storage.connection.make_bucket(current_app.config['MINIO_BUCKET_NAME'])
|
||||
|
||||
except BucketAlreadyOwnedByYou as err:
|
||||
pass
|
||||
except BucketAlreadyExists as err:
|
||||
pass
|
||||
# Everything else should be raised
|
||||
except BucketAlreadyOwnedByYou as err:
|
||||
pass
|
||||
except BucketAlreadyExists as err:
|
||||
pass
|
||||
# Everything else should be raised
|
||||
|
||||
# check for conflict
|
||||
if self._check_existance(description['tag']):
|
||||
return abort(409)
|
||||
with opentracing.tracer.start_active_span('checkExistence'):
|
||||
# check for conflict
|
||||
if self._check_existance(description['tag']):
|
||||
return abort(409)
|
||||
|
||||
# poot file into bucket
|
||||
try:
|
||||
storage.connection.put_object(current_app.config['MINIO_BUCKET_NAME'], description['tag'], file,
|
||||
file.content_length, content_type=file.content_type)
|
||||
except ResponseError: # TODO: Check if object already exists... somehow
|
||||
raise
|
||||
with opentracing.tracer.start_active_span(
|
||||
'minio.putObject',
|
||||
tags={
|
||||
"bucket": current_app.config['MINIO_BUCKET_NAME'],
|
||||
"object_name": description['tag'],
|
||||
"length": file.content_length
|
||||
}
|
||||
):
|
||||
# poot file into bucket
|
||||
try:
|
||||
storage.connection.put_object(current_app.config['MINIO_BUCKET_NAME'], description['tag'], file,
|
||||
file.content_length, content_type=file.content_type)
|
||||
except ResponseError: # TODO: Check if object already exists... somehow
|
||||
raise
|
||||
|
||||
return jsonify({"status": "200"}), 200 # TODO: 200 should be OK but that would be inconsistent with the errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user