Skip to main content

Module uploads

Module uploads 

Source
Expand description

Chunked, resumable uploads for large files (CAD assemblies, simulation results of several GB).

A client announces an upload (revision, file name, size, optionally the SHA-256 and the base version), then sends the content in chunks, each one at the offset the server confirmed last (like the tus protocol: a chunk at any other offset is refused with 409, and the client asks the session for the offset to resume from). The chunks are appended to a staging file in the vault (uploads/<id>), never kept in memory beyond one chunk.

When all bytes are there, the content is hashed from disk, checked against the announced size and SHA-256 and moved into the content-addressed vault. The file version is then created by the same code as every other upload (files::attach or files::check_in): check-out required, base-version guard, audit log, notifications.

Sessions expire SESSION_HOURS after their last chunk; expired ones are removed at start-up and every hour (purge_expired).

Structs§

Finished
A finished upload: the stored version and, for a check-in, the revision after the lock was released.
NewSession
What a client announces when it starts an upload.
UploadSession
An upload in progress.

Enums§

Scope
Where a finished upload may be used.

Constants§

MAX_OPEN_PER_USER
Most unfinished sessions one user may hold – each reserves up to TEAMCRAFT_MAX_UPLOAD_MB of disk space in the vault.
SESSION_HOURS
A session lives this long after its last chunk.

Functions§

abort
Cancels an upload and deletes what was received.
append
Appends a chunk at offset (see check_chunk) and returns the updated session. The chunk is on disk before the new offset is confirmed, so an interruption at any point loses at most this chunk.
check_chunk
Checks a chunk against the session state and returns the new offset. offset must be exactly the bytes received so far (409 otherwise – the client resumes from the server’s offset), and the chunk must not go beyond the announced size.
complete
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.
complete_in
complete with the Scope the caller will store the file in; the invariants are those of complete.
create
Starts an upload into a revision the actor has checked out. Refuses it early when the file cannot be stored anyway: too large, not checked out, or a stated base that the server file has moved on from.
finish
Completes an upload and stores it as a new file or version of its revision – with check_in also releasing the check-out, in one transaction (like a multipart check-in).
forget
Removes sessions whose content became file versions. Best effort: the versions are stored at this point, and a session left behind expires.
get
The state of one of the actor’s uploads (its offset to resume from).
parse_ids
Parses the uploads field of a multipart check-in or upload: the ids of completed chunked uploads, as a JSON array or separated by commas.
purge_expired
Removes expired sessions with their data, and staging files that have no session any more (e.g. after a crash between the two). Content that was verified and moved into the vault but never became a file version goes too – unless something else refers to it or it was stored again within retention::IN_FLIGHT_GRACE; such a session stays (expired, unusable) until the next run. Returns the number of sessions removed.
verify_content
Checks the received content against what the client announced.