Kantoor. Chat. Storage behaviour
(Kantoor v1.0.0)
Where the bytes of chat files live. A small boundary with two adapters: Local (a
directory: development, tests, a single node with a volume) and S3 (any S3-compatible
store: the company runs Garage). Keys are made by Kantoor (chat/<domain>/<room>/<file>)
and never contain a name a person chose.
Configuration, config :kantoor, Kantoor.Chat.Files: adapter: :local | :s3, path
(local), s3: [endpoint:, bucket:, region:, access_key_id:, secret_access_key:].
Summary
Functions
The adapter module in use.
Removes key (removing what is not there is fine).
Removes every object whose key starts with prefix: chat/<domain id>/ or
chat/<domain id>/<room id>/, and nothing else. Every segment after chat must be a
canonical (lowercase) UUID, so ., .., empty parts and words are refused before any
adapter is called: {:error, :invalid_prefix}.
Sends the bytes under key as the response (status 200, headers already set on conn),
without holding the file in memory: send_file for a directory, a chunked stream from S3.
{:error, :not_found} before anything is sent when the key does not exist.
{:partial, conn, reason} when the store failed after the response had started: conn
is the response in progress, which cannot be replaced by an error page.
The bytes under key.
The first bytes bytes under key (a ranged read, never the whole file).
Stores the file at path under key.
Callbacks
@callback deliver(conn :: Plug.Conn.t(), key :: String.t()) :: {:ok, Plug.Conn.t()} | {:error, :not_found | term()} | {:partial, Plug.Conn.t(), term()}
@callback head(key :: String.t(), bytes :: pos_integer()) :: {:ok, binary()} | {:error, term()}
Functions
The adapter module in use.
Removes key (removing what is not there is fine).
Removes every object whose key starts with prefix: chat/<domain id>/ or
chat/<domain id>/<room id>/, and nothing else. Every segment after chat must be a
canonical (lowercase) UUID, so ., .., empty parts and words are refused before any
adapter is called: {:error, :invalid_prefix}.
Sends the bytes under key as the response (status 200, headers already set on conn),
without holding the file in memory: send_file for a directory, a chunked stream from S3.
{:error, :not_found} before anything is sent when the key does not exist.
{:partial, conn, reason} when the store failed after the response had started: conn
is the response in progress, which cannot be replaced by an error page.
The bytes under key.
The first bytes bytes under key (a ranged read, never the whole file).
Stores the file at path under key.