archivebox.core.views

Module Contents

Classes

SnapshotReplayAuthView

Admin-only handoff that lets a snap host mint its own replay cookie.

HomepageView

SnapshotView

SnapshotPathView

Serve snapshots by the new URL scheme: /////…

SnapshotHostView

Serve snapshot directory contents on .<listen_host>/.

SnapshotReplayView

Serve snapshot directory contents on a one-domain replay path.

OriginalDomainHostView

Serve responses from the most recent snapshot when using .<listen_host>/.

OriginalDomainReplayView

Serve original-domain replay content on a one-domain replay path.

PublicIndexView

Keep browsing responsive while the same small server is archiving.

AddView

WebAddView

HealthCheckView

A Django view that renders plain text “OK” for service discovery tools

Functions

_files_index_target

_find_snapshot_by_ref

_admin_login_redirect_or_forbidden

_replay_cookie_name

_clean_replay_next

Only allow same-snap relative replay paths; grants must never redirect off-host.

_replay_payload_is_valid

A replay cookie is not its own auth source; it must point at a live admin session.

_has_replay_cookie

_private_snapshot_auth_redirect

_replay_auth_response

_safe_archive_relpath

_resolve_archiveresult_relpath

Resolve a declared output path and its exact historical fallbacks.

_plugin_full_preview_response

Render an explicit plugin full template as a trusted preview wrapper.

_trusted_snapshot_frame_csp

_plugin_card_document_response

Serve the existing card template from the snapshot origin, not web.*.

_visible_response_snapshots_for_domain

_latest_response_match

_latest_responses_root

_original_request_url

_serve_responses_path

_build_snapshot_replay_response

_serve_snapshot_replay

_serve_original_domain_replay

live_config_list_view

live_config_value_view

Data

REPLAY_AUTH_SALT

REPLAY_COOKIE_PREFIX

REPLAY_GRANT_MAX_AGE

API

archivebox.core.views._files_index_target(snapshot: archivebox.core.models.Snapshot, archivefile: str | None) → str[source]
archivebox.core.views._find_snapshot_by_ref(snapshot_ref: str) → archivebox.core.models.Snapshot | None[source]
archivebox.core.views._admin_login_redirect_or_forbidden(request: django.http.HttpRequest)[source]
archivebox.core.views.REPLAY_AUTH_SALT[source]

‘archivebox.private-snapshot-replay’

None

archivebox.core.views.REPLAY_GRANT_MAX_AGE[source]

60

archivebox.core.views._clean_replay_next(path: str | None) → str[source]

Only allow same-snap relative replay paths; grants must never redirect off-host.

archivebox.core.views._replay_payload_is_valid(payload: dict, snapshot: archivebox.core.models.Snapshot) → bool[source]

A replay cookie is not its own auth source; it must point at a live admin session.

Replayed pages can execute hostile JS, so admin cookies stay host-only on admin.. The snap host gets only this host-only HttpOnly cookie, and every request checks that the original Django session still exists and still belongs to an active staff user. Logout, session expiry, user deletion/deactivation, or password auth-hash rotation all make the replay cookie inert without needing admin. to delete a cookie on snap-*.

archivebox.core.views._private_snapshot_auth_redirect(request: django.http.HttpRequest, snapshot: archivebox.core.models.Snapshot, path: str = '', *, preserve_query: bool = True)[source]
archivebox.core.views._replay_auth_response(request: django.http.HttpRequest, snapshot: archivebox.core.models.Snapshot)[source]
class archivebox.core.views.SnapshotReplayAuthView[source]

Bases: django.views.View

Admin-only handoff that lets a snap host mint its own replay cookie.

admin.* cannot set a host-only cookie for snap-* (browsers forbid that), and widening the real Django session cookie to .archivebox.localhost would let XSS in replayed pages hit the admin UI. Instead admin. proves the user is logged in with a short URL grant, then snap-* validates it and sets a snap-host-only cookie.

get(request: django.http.HttpRequest)[source]
class archivebox.core.views.HomepageView[source]

Bases: django.views.View

get(request)[source]
class archivebox.core.views.SnapshotView[source]

Bases: django.views.View

static find_snapshots_for_url(path: str, *, allow_fallback: bool = True)[source]

Return a queryset of snapshots matching a URL-ish path. URL only — never tries ID matching.

Use find_snapshots_for_id separately if you also want to match by snapshot UUID.

static find_snapshots_for_id(slug: str)[source]

Return a queryset of snapshots matching a (possibly truncated) UUID via prefix or suffix.

Strips non-hex characters from slug (so input with or without hyphens both work). Requires at least 8 hex chars — shorter inputs return an empty queryset to avoid scanning the entire snapshots table on too-broad matches.

static render_live_index(request, snapshot)[source]
get(request, path)[source]
class archivebox.core.views.SnapshotPathView[source]

Bases: django.views.View

Serve snapshots by the new URL scheme: /////…

get(request, username: str, date: str | None = None, domain: str | None = None, snapshot_id: str | None = None, path: str = '', url: str | None = None)[source]
archivebox.core.views._safe_archive_relpath(path: str) → str | None[source]
archivebox.core.views._resolve_archiveresult_relpath(snapshot: archivebox.core.models.Snapshot, rel_path: str) → tuple[str, archivebox.core.models.ArchiveResult | None, tuple[str, ...]][source]

Resolve a declared output path and its exact historical fallbacks.

archivebox.core.views._plugin_full_preview_response(request: django.http.HttpRequest, snapshot: archivebox.core.models.Snapshot, rel_path: str, result: archivebox.core.models.ArchiveResult | None) → django.http.HttpResponse | None[source]

Render an explicit plugin full template as a trusted preview wrapper.

archivebox.core.views._trusted_snapshot_frame_csp(request: django.http.HttpRequest) → str[source]
archivebox.core.views._plugin_card_document_response(request: django.http.HttpRequest, snapshot: archivebox.core.models.Snapshot, result_id: str) → django.http.HttpResponse[source]

Serve the existing card template from the snapshot origin, not web.*.

srcdoc and inline card scripts inherit the containing page’s origin. This frame route gives them same-origin access to this snapshot’s saved files without opening CORS on raw archives or sharing the admin session cookie. The parent web page receives only the one-bit login hint; delete buttons navigate to admin.* for a real authenticated confirmation.

archivebox.core.views._visible_response_snapshots_for_domain(request: django.http.HttpRequest, domain: str) → list[archivebox.core.models.Snapshot][source]
archivebox.core.views._latest_response_match(snapshots: list[archivebox.core.models.Snapshot], domain: str, rel_path: str) → tuple[archivebox.core.models.Snapshot, pathlib.Path, pathlib.Path] | None[source]
archivebox.core.views._latest_responses_root(snapshots: list[archivebox.core.models.Snapshot], domain: str) → tuple[archivebox.core.models.Snapshot, pathlib.Path] | None[source]
archivebox.core.views._original_request_url(domain: str, path: str = '', query_string: str = '') → str[source]
archivebox.core.views._serve_responses_path(request, responses_root: pathlib.Path, rel_path: str, show_indexes: bool)[source]
archivebox.core.views._build_snapshot_replay_response(request: django.http.HttpRequest, snapshot: archivebox.core.models.Snapshot, path: str = '')[source]
archivebox.core.views._serve_snapshot_replay(request: django.http.HttpRequest, snapshot: archivebox.core.models.Snapshot, path: str = '')[source]
archivebox.core.views._serve_original_domain_replay(request: django.http.HttpRequest, domain: str, path: str = '')[source]
class archivebox.core.views.SnapshotHostView[source]

Bases: django.views.View

Serve snapshot directory contents on .<listen_host>/.

get(request, snapshot_id: str, path: str = '')[source]
class archivebox.core.views.SnapshotReplayView[source]

Bases: django.views.View

Serve snapshot directory contents on a one-domain replay path.

get(request, snapshot_id: str, path: str = '')[source]
class archivebox.core.views.OriginalDomainHostView[source]

Bases: django.views.View

Serve responses from the most recent snapshot when using .<listen_host>/.

get(request, domain: str, path: str = '')[source]
class archivebox.core.views.OriginalDomainReplayView[source]

Bases: django.views.View

Serve original-domain replay content on a one-domain replay path.

get(request, domain: str, path: str = '')[source]
class archivebox.core.views.PublicIndexView[source]

Bases: django.views.generic.list.ListView

Keep browsing responsive while the same small server is archiving.

Performance takes priority over perfect initial totals: on a 1 vCPU / 1 GB host with hundreds of thousands of snapshots, even an indexed count can consume the entire roughly 0.5-0.7 second page-load budget. Benchmark with the runner active, since it shares the CPU, memory, and SQLite database.

The unfiltered list therefore renders rows first and accepts missing/stale display totals. A later ordinary reload can show the background-cached count; do not restore a synchronous COUNT or add polling just to fill it in.

template_name[source]

‘public_index.html’

model[source]

None

ordering: ClassVar[list[str]][source]

[‘-bookmarked_at’, ‘-created_at’]

paginator_class[source]

None

public_page_scan_chunk_size[source]

50

get_paginate_by(queryset)[source]
_base_public_snapshot_fields() → tuple[str, ...][source]
_ordered_public_page_from_order_index(*, page_number: int, page_size: int) → list[archivebox.core.models.Snapshot][source]
paginate_queryset(queryset, page_size)[source]
get_context_data(**kwargs)[source]
get_queryset(**kwargs)[source]
get(*args, **kwargs)[source]
class archivebox.core.views.AddView[source]

Bases: django.contrib.auth.mixins.UserPassesTestMixin, django.views.generic.FormView

template_name[source]

‘add.html’

form_class[source]

None

get_initial()[source]

Prefill the AddLinkForm with the ‘url’ GET parameter

get_form_kwargs()[source]
test_func()[source]
post(request: django.http.HttpRequest, *args: object, **kwargs: object)[source]
_can_override_crawl_config() → bool[source]
_get_custom_config_overrides(form: archivebox.core.forms.AddLinkForm) → dict[source]
get_context_data(**kwargs)[source]
_create_crawl_from_form(form, *, created_by_id=None) → archivebox.crawls.models.Crawl[source]
form_valid(form)[source]
class archivebox.core.views.WebAddView[source]

Bases: archivebox.core.views.AddView

_latest_snapshot_for_url(requested_url: str)[source]
_normalize_add_url(requested_url: str) → str[source]
dispatch(request, *args, **kwargs)[source]
get(request: django.http.HttpRequest, *args: object, **kwargs: object)[source]
class archivebox.core.views.HealthCheckView[source]

Bases: django.views.View

A Django view that renders plain text “OK” for service discovery tools

get(request)[source]

Handle a GET request

archivebox.core.views.live_config_list_view(request: django.http.HttpRequest, **kwargs) → admin_data_views.typing.TableContext[source]
archivebox.core.views.live_config_value_view(request: django.http.HttpRequest, key: str, **kwargs) → admin_data_views.typing.ItemContext[source]