Give priority to local uploads when playing a track

environments/review-docs-devel-1399dq/deployments/6607
Agate 2020-08-06 16:21:55 +02:00
rodzic 2074234acb
commit 95ba6e1b22
3 zmienionych plików z 10 dodań i 2 usunięć

Wyświetl plik

@ -255,6 +255,7 @@ def serialize_upload(upload):
"bitrate": upload.bitrate,
"mimetype": upload.mimetype,
"extension": upload.extension,
"is_local": federation_utils.is_local(upload.fid),
}
@ -305,7 +306,10 @@ class TrackSerializer(OptionalDescriptionMixin, serializers.Serializer):
def get_uploads(self, obj):
uploads = getattr(obj, "playable_uploads", [])
return [serialize_upload(u) for u in sort_uploads_for_listen(uploads)]
# we put local uploads first
uploads = [serialize_upload(u) for u in sort_uploads_for_listen(uploads)]
uploads = sorted(uploads, key=lambda u: u["is_local"], reverse=True)
return list(uploads)
def get_tags(self, obj):
tagged_items = getattr(obj, "_prefetched_tagged_items", [])

Wyświetl plik

@ -354,6 +354,7 @@ def test_serialize_upload(factories):
"mimetype": upload.mimetype,
"extension": upload.extension,
"duration": upload.duration,
"is_local": False,
}
data = serializers.serialize_upload(upload)

Wyświetl plik

@ -513,7 +513,7 @@ Upload:
uuid:
type: string
format: uuid
size:size:
size:
type: "integer"
format: "int64"
example: 278987000
@ -541,6 +541,9 @@ Upload:
type: "string"
format: "uri"
description: "URL to stream the upload"
is_local:
type: "boolean"
description: "Indicates if the object was initally created locally or on another server"
OwnedLibraryCreate:
type: "object"