Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@bp_core.route("//low-level", methods=["POST"])
@ratelimit()
def submit_low_level(mbid):
"""Submit low-level data to AcousticBrainz.
:reqheader Content-Type: *application/json*
:resheader Content-Type: *application/json*
"""
raw_data = request.get_data()
try:
data = json.loads(raw_data.decode("utf-8"))
except ValueError as e:
raise webserver.views.api.exceptions.APIBadRequest("Cannot parse JSON document: %s" % e)
try:
submit_low_level_data(str(mbid), data, 'mbid')
except BadDataException as e:
raise webserver.views.api.exceptions.APIBadRequest("%s" % e)
return jsonify({"message": "ok"})
If an offset is not specified or is invalid, 0 is used as a default.
If an mbid is not valid, an APIBadRequest Exception is
raised listing the bad MBID and no further processing is done.
Returns a list of tuples (mbid, offset). MBIDs are converted to lower-case
"""
ret = []
for recording in params.split(";"):
parts = str(recording).split(":")
recording_id = parts[0]
try:
uuid.UUID(recording_id)
except ValueError:
raise webserver.views.api.exceptions.APIBadRequest("'%s' is not a valid UUID" % recording_id)
if len(parts) > 2:
raise webserver.views.api.exceptions.APIBadRequest("More than 1 : in '%s'" % recording)
elif len(parts) == 2:
try:
offset = int(parts[1])
# Don't allow negative offsets
offset = max(offset, 0)
except ValueError:
offset = 0
else:
offset = 0
ret.append((recording_id.lower(), offset))
# Remove duplicates, preserving order
seen = set()
def submit_low_level(mbid):
"""Endpoint for submitting low-level information to AcousticBrainz."""
raw_data = request.get_data()
try:
data = json.loads(raw_data.decode("utf-8"))
except ValueError as e:
raise exceptions.APIBadRequest("Cannot parse JSON document: %s" % e)
try:
submit_low_level_data(mbid, data, 'mbid')
except BadDataException as e:
raise exceptions.APIBadRequest("%s" % e)
return jsonify({"message": "ok"})
def _validate_data_arguments(mbid, offset):
"""Validate the mbid and offset. If the mbid is not a valid uuid, raise 404.
If the offset is None, return 0, otherwise interpret it as a number. If it is
not a number, raise 400."""
try:
uuid.UUID(mbid)
except ValueError:
# an invalid uuid is 404
raise exceptions.APINotFound("Not found")
if offset:
try:
offset = int(offset)
except ValueError:
raise exceptions.APIBadRequest("Offset must be an integer value")
else:
offset = 0
return mbid, offset
'job_id': '0fc553b6-f3a8-4e24-af39-56ac02276ed9'
}
]
}
:reqheader Content-Type: *application/json*
:
try:
ds = db.dataset.get(dataset_id)
except db.exceptions.NoDataFoundException as e:
raise api_exceptions.APINotFound("Can't find this dataset.")
if not write:
if ds["public"] or (current_user.is_authenticated and
ds["author"] == current_user.id):
return ds
else:
raise api_exceptions.APINotFound("Can't find this dataset.")
else:
if (current_user.is_authenticated and
ds["author"] == current_user.id):
return ds
else:
raise api_exceptions.APIUnauthorized("Only the author can modify the dataset.")