Linkhut.Archiving (linkhut v0.1.8)

View Source

Link archiving context. Handles creating snapshots of bookmarked pages and storing them.

Summary

Functions

Returns the list of content types accepted for snapshot uploads.

Returns true while an Archiver job for link is live or one of its snapshots is pending or crawling.

Returns true if the user can create new archives.

Returns true if the user can view/download existing archives. Any active user can view when archiving isn't disabled.

Deletes a single snapshot's storage and database record. Returns :ok on success, {:error, reason} on failure.

Returns the list of users eligible for archiving based on the current mode.

Enqueues a SnapshotDeleter job for each snapshot in pending_deletion state.

Enqueues a re-crawl of link.

Returns a complete snapshot by ID, or {:error, :not_found}.

Returns all complete snapshots for a link.

Returns all crawl runs for a link.

Returns all non-deleted snapshots for a link, ordered by format locality then recency.

Returns the latest complete snapshot of a link in format, for a given source (when given).

Gets a snapshot by its ID.

Records that a crawler's snapshot reached a terminal state.

Marks all snapshots for a link as pending deletion.

Returns the archiving mode.

Marks a single snapshot as pending deletion.

Stores the file at path as snapshot's content, if and only if it is within max_file_size.

Updates a snapshot's attributes.

Uploads a user-provided snapshot for a link.

Functions

accepted_upload_types()

Returns the list of content types accepted for snapshot uploads.

archiving?(link)

@spec archiving?(Linkhut.Links.Link.t()) :: boolean()

Returns true while an Archiver job for link is live or one of its snapshots is pending or crawling.

can_create_archives?(user)

@spec can_create_archives?(Linkhut.Accounts.User.t()) :: boolean()

Returns true if the user can create new archives.

can_view_archives?(arg1)

@spec can_view_archives?(Linkhut.Accounts.User.t()) :: boolean()

Returns true if the user can view/download existing archives. Any active user can view when archiving isn't disabled.

delete_snapshot(snapshot_id)

Deletes a single snapshot's storage and database record. Returns :ok on success, {:error, reason} on failure.

eligible_users()

Returns the list of users eligible for archiving based on the current mode.

  • :disabled → empty list
  • :limited → users with an active supporter subscription
  • :enabled → all active users

enqueue_pending_deletions()

Enqueues a SnapshotDeleter job for each snapshot in pending_deletion state.

enqueue_recrawl(link, opts \\ [])

Enqueues a re-crawl of link.

get_complete_snapshot(id)

Returns a complete snapshot by ID, or {:error, :not_found}.

get_complete_snapshots_by_link(link_id)

Returns all complete snapshots for a link.

get_crawl_runs_by_link(link_id)

Returns all crawl runs for a link.

get_current_snapshots_by_link(link_id)

Returns all non-deleted snapshots for a link, ordered by format locality then recency.

get_latest_complete_snapshot(link_id, format, source)

Returns the latest complete snapshot of a link in format, for a given source (when given).

get_snapshot_by_id(id)

Gets a snapshot by its ID.

mark_snapshot(snapshot, state, attrs)

@spec mark_snapshot(
  Linkhut.Archiving.Snapshot.t(),
  :complete | :not_available | :failed,
  map()
) ::
  {:ok, Linkhut.Archiving.Snapshot.t()}
  | {:error, Ecto.Changeset.t() | :not_found}

Records that a crawler's snapshot reached a terminal state.

If the state of this snapshot is as good or better than the state of a prior snapshot for the same link and format, then it marks those older snapshots for deletion:

  • :complete trumps :complete, :not_available and :failed
  • :not_available trumps :not_available and :failed
  • :failed trumps :failed

Note: A crawler's snapshot never replaces an upload.

mark_snapshots_for_deletion(link_id)

Marks all snapshots for a link as pending deletion.

mode()

Returns the archiving mode.

  • :disabled: no archiving features
  • :enabled: archiving for all active users
  • :limited: archiving only for active paying users

request_snapshot_deletion(snapshot_id, user_id)

Marks a single snapshot as pending deletion.

store_file(snapshot, path, content_type)

@spec store_file(Linkhut.Archiving.Snapshot.t(), Path.t(), String.t()) ::
  {:ok, map()}
  | {:error, {:file_too_large, non_neg_integer(), non_neg_integer()}}
  | {:error, term()}

Stores the file at path as snapshot's content, if and only if it is within max_file_size.

update_snapshot(snapshot, attrs)

Updates a snapshot's attributes.

upload_snapshot(link_id, user_id, upload)

Uploads a user-provided snapshot for a link.

Detects the format from the content type and supersedes older snapshots of the same format (meaning that uploads always trump prior uploads and any snapshots produced by crawlers).