pub async fn complete(
pool: &PgPool,
vault: &Vault,
actor: &Actor,
id: Uuid,
revision_id: Option<Uuid>,
) -> AppResult<Upload>Expand description
Verifies a fully received upload (size, announced SHA-256), moves it into
the vault and classifies it like a regular upload, with the session’s
base and folder. Nothing is registered in the database yet – pass the result to
files::attach / files::check_in and then call forget.
Calling it again after a failed attach (e.g. the database was briefly unavailable) reuses the stored content – nothing has to be re-sent. Content that fails verification resets the session to offset 0.
§Invariants
- Permission: the actor’s own session (404 otherwise);
revision_id, when given, must be the session’s revision (400).complete_inapplies theScoperules:NewItemaccepts only sessions without a revision,Revision(id)only that revision,Anywhatever the session allows. - Locks: the session row (
FOR UPDATE). - Data: all bytes must have arrived (409 otherwise). Size and announced SHA-256 are verified; a mismatch (400) or lost staging data (409) resets the session to offset 0 and commits that reset. The verified hash is recorded on the session, so a repeated call reuses the stored content.
- Steps: the staged file moves into the vault before the transaction
commits; a crash in between is recovered when the announced SHA-256 is in
the vault. The session row stays until
forgetorabort. - Audit, notifications, webhooks: none; nothing is registered in the database as a file.