Kantoor. Chat. Files
(Kantoor v1.0.0)
The rules and the plumbing of chat file attachments: what is taken (size, kind, name,
virus scan), where it goes (Kantoor.Chat.Storage) and how much a domain may keep.
Settings, config :kantoor, Kantoor.Chat.Files (from KANTOOR_CHAT_* in
config/runtime.exs): adapter, path, s3, max_bytes (25 MB), quota_bytes
(5 GB per mail domain), clamav ({host, port}), clamav_required.
Summary
Functions
The cheap checks of one upload without the virus scan (size, name, kind against name),
for telling people at once, before anything is consumed or stored: {:ok, prepared} or
{:error, reason} (:empty, :too_large, :type, :mismatch).
The settings.
Removes every stored file of a mail domain from the store (by key prefix
chat/<domain id>/). The database rows are not touched. Nothing calls this yet when a
domain is deleted: see Kantoor.Release.delete_chat_files/2.
Removes the stored bytes of files (stored maps or Kantoor.Chat.File rows); failures are only logged.
Like delete_domain_files/1 for one room (chat/<domain id>/<room id>/).
The query of a message's files that still exist, oldest first.
The largest file, in bytes.
How many files one message may carry.
Checks every upload (size, name, kind against name, virus scan) and gives each an id.
{:error, {:file, name, reason}} for the first that is refused, reasons :empty,
:too_large, :type, :mismatch, :infected, :scan_unavailable; :too_many_files.
What a mail domain may keep in all, in bytes.
Puts the prepared files in storage under keys made here (chat/<domain>/<room>/<id>).
When one fails, those already put are removed again.
Bytes kept by a domain (files that were not deleted).
Types
@type prepared() :: %{ id: Ecto.UUID.t(), name: String.t(), content_type: String.t(), size: non_neg_integer(), path: Path.t() }
@type stored() :: %{ id: Ecto.UUID.t(), name: String.t(), content_type: String.t(), size: non_neg_integer(), storage_key: String.t() }
Functions
The cheap checks of one upload without the virus scan (size, name, kind against name),
for telling people at once, before anything is consumed or stored: {:ok, prepared} or
{:error, reason} (:empty, :too_large, :type, :mismatch).
The settings.
@spec delete_domain_files(Ecto.UUID.t()) :: :ok | {:error, term()}
Removes every stored file of a mail domain from the store (by key prefix
chat/<domain id>/). The database rows are not touched. Nothing calls this yet when a
domain is deleted: see Kantoor.Release.delete_chat_files/2.
Removes the stored bytes of files (stored maps or Kantoor.Chat.File rows); failures are only logged.
@spec delete_room_files(Ecto.UUID.t(), Ecto.UUID.t()) :: :ok | {:error, term()}
Like delete_domain_files/1 for one room (chat/<domain id>/<room id>/).
The query of a message's files that still exist, oldest first.
The largest file, in bytes.
How many files one message may carry.
Checks every upload (size, name, kind against name, virus scan) and gives each an id.
{:error, {:file, name, reason}} for the first that is refused, reasons :empty,
:too_large, :type, :mismatch, :infected, :scan_unavailable; :too_many_files.
What a mail domain may keep in all, in bytes.
Puts the prepared files in storage under keys made here (chat/<domain>/<room>/<id>).
When one fails, those already put are removed again.
@spec usage(Ecto.UUID.t()) :: non_neg_integer()
Bytes kept by a domain (files that were not deleted).