mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-14 07:04:27 -04:00
tweak snapshot asset serving logic to show multiple choices in case of conflict
This commit is contained in:
parent
a6c64f2560
commit
28e50c5e49
1 changed files with 62 additions and 61 deletions
|
@ -62,19 +62,21 @@ class SnapshotView(View):
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
snapshot = Snapshot.objects.get(timestamp=slug)
|
snapshot = Snapshot.objects.get(timestamp=slug)
|
||||||
except Snapshot.DoesNotExist:
|
|
||||||
if Snapshot.objects.filter(timestamp__startswith=slug).exists():
|
|
||||||
raise Snapshot.MultipleObjectsReturned
|
|
||||||
response = static.serve(request, archivefile, document_root=snapshot.link_dir, show_indexes=True)
|
response = static.serve(request, archivefile, document_root=snapshot.link_dir, show_indexes=True)
|
||||||
response["Link"] = f'<{snapshot.url}>; rel="canonical"'
|
response["Link"] = f'<{snapshot.url}>; rel="canonical"'
|
||||||
return response
|
return response
|
||||||
|
except Snapshot.DoesNotExist:
|
||||||
|
if Snapshot.objects.filter(timestamp__startswith=slug).exists():
|
||||||
|
raise Snapshot.MultipleObjectsReturned
|
||||||
|
else:
|
||||||
|
raise
|
||||||
except Snapshot.DoesNotExist:
|
except Snapshot.DoesNotExist:
|
||||||
# Snapshot does not exist
|
# Snapshot does not exist
|
||||||
return HttpResponse(
|
return HttpResponse(
|
||||||
format_html(
|
format_html(
|
||||||
(
|
(
|
||||||
'<center><br/><br/><br/>'
|
'<center><br/><br/><br/>'
|
||||||
'No Snapshots match the given timestamp: <code>{}</code><br/><br/>'
|
'No Snapshots match the given timestamp or UUID: <code>{}</code><br/><br/>'
|
||||||
'You can <a href="/add/" target="_top">add a new Snapshot</a>, or return to the <a href="/" target="_top">Main Index</a>'
|
'You can <a href="/add/" target="_top">add a new Snapshot</a>, or return to the <a href="/" target="_top">Main Index</a>'
|
||||||
'</center>'
|
'</center>'
|
||||||
),
|
),
|
||||||
|
@ -99,7 +101,7 @@ class SnapshotView(View):
|
||||||
return HttpResponse(
|
return HttpResponse(
|
||||||
format_html(
|
format_html(
|
||||||
(
|
(
|
||||||
'Multiple Snapshots match the given timestamp <code>{}</code><br/><pre>'
|
'Multiple Snapshots match the given timestamp/UUID <code>{}</code><br/><pre>'
|
||||||
),
|
),
|
||||||
slug,
|
slug,
|
||||||
) + snapshot_hrefs + format_html(
|
) + snapshot_hrefs + format_html(
|
||||||
|
@ -134,7 +136,6 @@ class SnapshotView(View):
|
||||||
status=404,
|
status=404,
|
||||||
)
|
)
|
||||||
# slug is a URL
|
# slug is a URL
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
# try exact match on full url first
|
# try exact match on full url first
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue