mirror of
https://github.com/sissbruecker/linkding.git
synced 2026-02-28 06:53:12 +08:00
Allow viewing video assets (#1259)
This commit is contained in:
@@ -27,14 +27,14 @@ class BookmarkAssetViewTestCase(TestCase, BookmarkFactoryMixin):
|
||||
)
|
||||
return asset
|
||||
|
||||
def setup_asset_with_uploaded_file(self, bookmark):
|
||||
def setup_asset_with_uploaded_file(self, bookmark, content_type="image/png"):
|
||||
filename = f"temp_{bookmark.id}.png.gzip"
|
||||
self.setup_asset_file(filename)
|
||||
asset = self.setup_asset(
|
||||
bookmark=bookmark,
|
||||
file=filename,
|
||||
asset_type=BookmarkAsset.TYPE_UPLOAD,
|
||||
content_type="image/png",
|
||||
content_type=content_type,
|
||||
display_name=f"Uploaded file {bookmark.id}.png",
|
||||
)
|
||||
return asset
|
||||
@@ -164,3 +164,17 @@ class BookmarkAssetViewTestCase(TestCase, BookmarkFactoryMixin):
|
||||
f'inline; filename="{asset.display_name}"',
|
||||
)
|
||||
self.assertEqual(response["Content-Security-Policy"], "sandbox allow-scripts")
|
||||
|
||||
def test_uploaded_video_download_headers(self):
|
||||
bookmark = self.setup_bookmark()
|
||||
asset = self.setup_asset_with_uploaded_file(bookmark, content_type="video/mp4")
|
||||
response = self.client.get(reverse("linkding:assets.view", args=[asset.id]))
|
||||
|
||||
self.assertEqual(response["Content-Type"], asset.content_type)
|
||||
self.assertEqual(
|
||||
response["Content-Disposition"],
|
||||
f'inline; filename="{asset.display_name}"',
|
||||
)
|
||||
self.assertEqual(
|
||||
response["Content-Security-Policy"], "default-src 'none'; media-src 'self';"
|
||||
)
|
||||
|
||||
@@ -33,7 +33,10 @@ def view(request, asset_id: int):
|
||||
|
||||
response = HttpResponse(content, content_type=asset.content_type)
|
||||
response["Content-Disposition"] = f'inline; filename="{asset.download_name}"'
|
||||
response["Content-Security-Policy"] = "sandbox allow-scripts"
|
||||
if asset.content_type and asset.content_type.startswith("video/"):
|
||||
response["Content-Security-Policy"] = "default-src 'none'; media-src 'self';"
|
||||
else:
|
||||
response["Content-Security-Policy"] = "sandbox allow-scripts"
|
||||
return response
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user