QutEcoacoustics / baw-server

The acoustic workbench server for storing and managing ecoacoustic data. Manages the structure and audio data. Provides an API for clients access.
Apache License 2.0
9 stars 4 forks source link

Changes to annotation upload api #664

Open hudson-newey opened 10 months ago

hudson-newey commented 10 months ago

As previously discussed, we should make some changes to the annotation upload api

Improved returned errors

Errors should change from

"errors": [
    {
        "start_time": ["must be a float"]
    },
    {
        "audio_recording_id": ["must be a float", "must be greater than one"]
    }
]

to

"errors": ["'start_time' must be a float", "'audio_recording_id' must be a float", "'audio_recording_id' must be greater than one"]

Splitting annotation read and write annotation imports into separate routes

At the moment we have two models import and audio_event_import.

Both are accessed from the /audio_event_imports/:id route, but use separate models for reading and writing (audio_event_import for GET and PATCH, and import for formData PUT)

To make the event import API more in line with restful practices, we should split both models over two separate routes.

Move imported annotation files to the paginated route

Since some event imports such as analysis jobs will produce tens of thousands of imported files, this would place a lot of strain on the API.

We should therefore create a new paginated route to get files from audio_event_import models


In short, we should remove sub-models and move them to their own models, return an array of id's so that we can use client-side associations to fetch sub-models

Edit: We may want to move imported_events on audio_event_import model to return an array of id's instead

hudson-newey commented 9 months ago

In addition to this issue, we should improve errors emitted by annotation imports

e.g. uploading a file with an audio_recording_id that you do not have access to

PUT https://api.staging.ecosounds.org/audio_event_imports/116

audio_recording_id,start_time_seconds,end_time_seconds,low_frequency_hertz,high_frequency_hertz,tag
1,123,456,100,500,Bird

returns a HTTP status 401 with the response body:

Collapsed Reponse Body {"meta":{"status":401,"message":"Unauthorized","error":{"details":"You need to log in or register before continuing.","links":{"Log in":"/my_account/sign_in","Register":"/my_account/sign_up","Confirm account":"/my_account/confirmation/new"},"info":null}},"data":null}

This should instead by emitted in the imported audio event's error property coupled with the other file import errors

image

hudson-newey commented 9 months ago

Additional bug: there seems to be a race condition if we upload multiple files (in multiple requests) in quick succession.

e.g.

Additional bug: there are no errors for audio recordings that do not exist. It just returns an "internal server error" (not in the error object array)