mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-13 21:49:26 +02:00
Add reader mode (#703)
* Add reader mode view * Show link for latest snapshot instead
This commit is contained in:
@@ -6,11 +6,12 @@ from django.http import (
|
||||
HttpResponse,
|
||||
Http404,
|
||||
)
|
||||
from django.shortcuts import render
|
||||
|
||||
from bookmarks.models import BookmarkAsset
|
||||
|
||||
|
||||
def view(request, asset_id: int):
|
||||
def _access_asset(request, asset_id: int):
|
||||
try:
|
||||
asset = BookmarkAsset.objects.get(pk=asset_id)
|
||||
except BookmarkAsset.DoesNotExist:
|
||||
@@ -28,6 +29,10 @@ def view(request, asset_id: int):
|
||||
if not is_owner and not is_shared and not is_public_shared:
|
||||
raise Http404("Bookmark does not exist")
|
||||
|
||||
return asset
|
||||
|
||||
|
||||
def _get_asset_content(asset):
|
||||
filepath = os.path.join(settings.LD_ASSET_FOLDER, asset.file)
|
||||
|
||||
if not os.path.exists(filepath):
|
||||
@@ -40,4 +45,25 @@ def view(request, asset_id: int):
|
||||
with open(filepath, "rb") as f:
|
||||
content = f.read()
|
||||
|
||||
return content
|
||||
|
||||
|
||||
def view(request, asset_id: int):
|
||||
asset = _access_asset(request, asset_id)
|
||||
content = _get_asset_content(asset)
|
||||
|
||||
return HttpResponse(content, content_type=asset.content_type)
|
||||
|
||||
|
||||
def read(request, asset_id: int):
|
||||
asset = _access_asset(request, asset_id)
|
||||
content = _get_asset_content(asset)
|
||||
content = content.decode("utf-8")
|
||||
|
||||
return render(
|
||||
request,
|
||||
"bookmarks/read.html",
|
||||
{
|
||||
"content": content,
|
||||
},
|
||||
)
|
||||
|
@@ -346,6 +346,7 @@ class BookmarkAssetItem:
|
||||
|
||||
self.id = asset.id
|
||||
self.display_name = asset.display_name
|
||||
self.asset_type = asset.asset_type
|
||||
self.content_type = asset.content_type
|
||||
self.file = asset.file
|
||||
self.file_size = asset.file_size
|
||||
@@ -393,3 +394,12 @@ class BookmarkDetailsContext:
|
||||
self.has_pending_assets = any(
|
||||
asset.status == BookmarkAsset.STATUS_PENDING for asset in self.assets
|
||||
)
|
||||
self.latest_snapshot = next(
|
||||
(
|
||||
asset
|
||||
for asset in self.assets
|
||||
if asset.asset.asset_type == BookmarkAsset.TYPE_SNAPSHOT
|
||||
and asset.status == BookmarkAsset.STATUS_COMPLETE
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
Reference in New Issue
Block a user