mirror of
https://github.com/wahyd4/links.git
synced 2026-08-09 05:06:16 +10:00
Update
This commit is contained in:
@@ -27,6 +27,21 @@ def _pdf():
|
||||
return SimpleUploadedFile("document.pdf", data, content_type="application/pdf")
|
||||
|
||||
|
||||
def _mp4_generic_content_type():
|
||||
"""An .mp4 upload whose client sent a generic Content-Type.
|
||||
|
||||
Reproduces the iOS-uploader behaviour that caused mb4 files to be
|
||||
persisted as "application/octet-stream" and therefore un-previewable
|
||||
in the UI. The server must infer "video/mp4" from the filename instead.
|
||||
"""
|
||||
# minimal mp4 box header — content is irrelevant, only the extension
|
||||
# and Content-Type matter for the mime-type inference path.
|
||||
data = b"\x00\x00\x00\x20ftypisom\x00\x00\x02\x00isomiso2avc1mp41"
|
||||
return SimpleUploadedFile(
|
||||
"clip.mp4", data, content_type="application/octet-stream"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestFilesAPI:
|
||||
BASE = "/api/files"
|
||||
@@ -171,3 +186,21 @@ class TestFilesAPI:
|
||||
).json()[0]
|
||||
assert "formatted_size" in uploaded
|
||||
assert "B" in uploaded["formatted_size"]
|
||||
|
||||
def test_upload_infers_mime_from_filename_when_client_sends_generic(self, api_client):
|
||||
"""An .mp4 uploaded with Content-Type=application/octet-stream must
|
||||
still be persisted as video/mp4 so the UI can render a <video>."""
|
||||
uploaded = api_client.post(
|
||||
f"{self.BASE}", {"files": _mp4_generic_content_type()}, format="multipart"
|
||||
).json()[0]
|
||||
assert uploaded["mime_type"] == "video/mp4"
|
||||
|
||||
def test_download_serves_inline_for_generic_content_type_mp4(self, client, api_client):
|
||||
uploaded = api_client.post(
|
||||
f"{self.BASE}", {"files": _mp4_generic_content_type()}, format="multipart"
|
||||
).json()[0]
|
||||
pk, name = uploaded["id"], uploaded["name"]
|
||||
r = client.get(f"/ui/files/{pk}-{name}")
|
||||
assert r.status_code == 200
|
||||
assert r["Content-Type"] == "video/mp4"
|
||||
assert (r["Content-Disposition"] or "").startswith("inline"), r["Content-Disposition"]
|
||||
|
||||
Reference in New Issue
Block a user