Handle unarchived static snapshot details

This commit is contained in:
Nick Sweeting 2026-08-30 13:01:34 -07:00
parent 6d564c14ee
commit a1b763974e
No known key found for this signature in database
4 changed files with 23 additions and 2 deletions

View File

@ -3669,6 +3669,7 @@ class Snapshot(ModelWithDeleteAfter, ModelWithOutputDir, ModelWithConfig, ModelW
from django.template.loader import render_to_string from django.template.loader import render_to_string
output_dir = Path(out_dir) if out_dir is not None else self.output_dir output_dir = Path(out_dir) if out_dir is not None else self.output_dir
output_dir.mkdir(parents=True, exist_ok=True)
context = self.get_html_details_context(static_export_dir=output_dir) context = self.get_html_details_context(static_export_dir=output_dir)
rendered_html = render_to_string("core/snapshot.html", context) rendered_html = render_to_string("core/snapshot.html", context)
atomic_write(str(output_dir / CONSTANTS.HTML_INDEX_FILENAME), rendered_html) atomic_write(str(output_dir / CONSTANTS.HTML_INDEX_FILENAME), rendered_html)

View File

@ -1515,7 +1515,9 @@
<div class="snapshot-empty-actions"> <div class="snapshot-empty-actions">
<button type="button" id="snapshot-empty-refresh" class="snapshot-empty-btn">🔄 Refresh page</button> <button type="button" id="snapshot-empty-refresh" class="snapshot-empty-btn">🔄 Refresh page</button>
<a href="{{ url }}" target="_blank" rel="noopener noreferrer" class="snapshot-empty-btn">🌐 Open original URL</a> <a href="{{ url }}" target="_blank" rel="noopener noreferrer" class="snapshot-empty-btn">🌐 Open original URL</a>
{% if not STATIC_EXPORT %}
<a href="{% admin_base_url %}/admin/core/snapshot/{{ snapshot_id }}/change/" class="snapshot-empty-btn">✏️ Edit in admin</a> <a href="{% admin_base_url %}/admin/core/snapshot/{{ snapshot_id }}/change/" class="snapshot-empty-btn">✏️ Edit in admin</a>
{% endif %}
</div> </div>
</div> </div>
</div> </div>

View File

@ -20,6 +20,26 @@ from archivebox.tests.test_orm_helpers import use_archivebox_db
pytestmark = pytest.mark.django_db(transaction=True) pytestmark = pytest.mark.django_db(transaction=True)
def test_static_export_creates_detail_page_for_unarchived_snapshot(snapshot):
from archivebox.config import CONSTANTS
snapshot_dir = Path(snapshot.output_dir)
assert snapshot_dir.is_dir()
assert not any(snapshot_dir.iterdir())
snapshot_dir.rmdir()
assert not snapshot_dir.exists()
html = Snapshot.objects.filter(pk=snapshot.pk).to_html(with_headers=True)
static_path = snapshot_dir.relative_to(CONSTANTS.DATA_DIR).as_posix()
detail_path = snapshot_dir / "index.html"
assert f"./{static_path}/index.html" in html
assert detail_path.exists()
detail_html = detail_path.read_text()
assert f"/snapshot/{snapshot.id.hex}" not in detail_html
assert "/admin/" not in detail_html
def test_static_exports_use_filesystem_paths_not_live_django_routes(snapshot): def test_static_exports_use_filesystem_paths_not_live_django_routes(snapshot):
from archivebox.config import CONSTANTS from archivebox.config import CONSTANTS
from archivebox.core.models import ArchiveResult from archivebox.core.models import ArchiveResult

View File

@ -15,8 +15,6 @@ pytestmark = pytest.mark.django_db
def test_crawl_runner_creates_progress_reporter_without_a_tty(crawl): def test_crawl_runner_creates_progress_reporter_without_a_tty(crawl):
from archivebox.services.runner import CrawlRunner from archivebox.services.runner import CrawlRunner
assert not sys.stdout.isatty()
assert not sys.stderr.isatty()
runner = CrawlRunner(crawl) runner = CrawlRunner(crawl)
runner.load_run_state() runner.load_run_state()