Storehouse.Tus.State behaviour (Storehouse v0.2.0)

Copy Markdown View Source

Where Storehouse.Tus.Plug keeps each upload between requests: its key, size, offset, metadata and, on a store of multipart uploads, its parts and the bytes not yet a part. Storehouse.Tus.State.ETS is the default, one node's.

An upload is a map with an :id (upload/0). Every field of it must be kept as it is: in a database, as an Erlang term (:erlang.term_to_binary/1, in a bytea column) beside the id and expires_at.

Summary

Types

An upload in progress, as the plug keeps it.

Callbacks

Forgets the upload with id.

The uploads whose :expires_at is before now.

The upload with id, or nil.

The uploads in progress of owner (an upload's :owner): with it, the plug limits how many one owner has at once (:max_uploads), and counts their sizes against its :room.

Keeps upload, in place of the one with its id.

Types

upload()

@type upload() :: %{
  :id => String.t(),
  :expires_at => DateTime.t(),
  optional(atom()) => term()
}

An upload in progress, as the plug keeps it.

Callbacks

delete(t)

@callback delete(String.t()) :: :ok

Forgets the upload with id.

expired(now)

@callback expired(now :: DateTime.t()) :: [upload()]

The uploads whose :expires_at is before now.

get(t)

@callback get(String.t()) :: upload() | nil

The upload with id, or nil.

owned(owner)

(optional)
@callback owned(owner :: String.t()) :: [upload()]

The uploads in progress of owner (an upload's :owner): with it, the plug limits how many one owner has at once (:max_uploads), and counts their sizes against its :room.

put(upload)

@callback put(upload()) :: :ok

Keeps upload, in place of the one with its id.