Imports API: upload exports, pull from Last.fm, follow progress
CI / validate-monitoring (push) Successful in 9s
CI / lint (push) Successful in 13s
CI / test (push) Successful in 47s
CI / python-package (push) Skipped
CI / assets (push) Successful in 8s
CI / images (push) Successful in 31s
CI / notify (push) Successful in 6s

- /api/v1/imports/options lists the available sources; `lastfm` only
  appears when the server has a Last.fm API key
- POST /imports/file (multipart; format detected or forced with
  ?format=), POST /imports/lastfm, GET /imports, GET /imports/{id},
  POST /imports/{id}/cancel
- Upload size limit (IMPORT_MAX_BYTES, default 200 MB) with a 413
- Documented in OpenAPI under the Imports tag

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
mattandClaude Opus 5.5 committed 2026-09-25 15:04:15 +01:00
1 parent 6fc9d91fa2
commit eebd7b8730
5 files changed
+759 -1

No files matched your search

+53
View File
@@ -1,6 +1,7 @@
"""Marshmallow schemas for the /api/v1 JSON API. They drive both request
validation and the generated OpenAPI document."""
from flask_smorest.fields import Upload
from marshmallow import Schema, fields, validate
@@ -143,3 +144,55 @@ class SummarySchema(Schema):
artists = fields.Integer()
tracks = fields.Integer()
first_scrobble_at = fields.DateTime(allow_none=True)
IMPORT_SOURCES = ["csv", "json", "lastfm"]
IMPORT_STATUSES = ["pending", "running", "completed", "failed", "cancelled"]
class ImportOptionsSchema(Schema):
sources = fields.List(
fields.String(validate=validate.OneOf(IMPORT_SOURCES)),
metadata={"description": "`lastfm` is only listed when the server has a Last.fm API key"},
)
max_upload_bytes = fields.Integer()
class ImportJobSchema(Schema):
id = fields.Integer()
source = fields.String(validate=validate.OneOf(IMPORT_SOURCES))
status = fields.String(validate=validate.OneOf(IMPORT_STATUSES))
filename = fields.String(allow_none=True)
lastfm_username = fields.String(allow_none=True)
total = fields.Integer(
allow_none=True, metadata={"description": "Rows or tracks to process, once known"}
)
processed = fields.Integer()
imported = fields.Integer(metadata={"description": "New scrobbles added"})
duplicates = fields.Integer(metadata={"description": "Already in your history"})
skipped = fields.Integer(metadata={"description": "No artist/track, bad date, or future"})
error = fields.String(allow_none=True)
created_at = fields.DateTime()
started_at = fields.DateTime(allow_none=True)
finished_at = fields.DateTime(allow_none=True)
class ImportFileSchema(Schema):
file = Upload(
required=True,
metadata={"description": "CSV or JSON export, optionally gzipped"},
)
class ImportFormatSchema(Schema):
format = fields.String(
load_default="auto",
validate=validate.OneOf(["auto", "csv", "json"]),
metadata={"description": "Detected from the file name and contents when `auto`"},
)
class LastfmImportSchema(Schema):
username = fields.String(
required=True, validate=validate.Length(min=1, max=64), metadata={"example": "rj"}
)