lightspeed/upload

LiveView-style upload compatibility model.

Types

Upload entry lifecycle status.

pub type EntryStatus {
  Selected
  ExternalPrepared(upload_url: String)
  Uploading(progress: Int)
  Completed(location: String)
  Cancelled(reason: String)
  Failed(reason: String)
}

Constructors

  • Selected
  • ExternalPrepared(upload_url: String)
  • Uploading(progress: Int)
  • Completed(location: String)
  • Cancelled(reason: String)
  • Failed(reason: String)

Upload

opaque

Upload runtime state.

pub opaque type Upload

One upload entry.

pub type UploadEntry {
  UploadEntry(
    ref: String,
    client_name: String,
    client_size: Int,
    client_type: String,
    status: EntryStatus,
  )
}

Constructors

  • UploadEntry(
      ref: String,
      client_name: String,
      client_size: Int,
      client_type: String,
      status: EntryStatus,
    )

Upload-level validation and transition errors.

pub type UploadError {
  TooManyFiles(max_entries: Int)
  TooLarge(ref: String, size_bytes: Int, max_bytes: Int)
  NotAccepted(ref: String, accept: List(String))
  DuplicateRef(ref: String)
  UnknownRef(ref: String)
  InvalidProgress(ref: String, progress: Int)
  InvalidTransition(ref: String, status: String, action: String)
}

Constructors

  • TooManyFiles(max_entries: Int)
  • TooLarge(ref: String, size_bytes: Int, max_bytes: Int)
  • NotAccepted(ref: String, accept: List(String))
  • DuplicateRef(ref: String)
  • UnknownRef(ref: String)
  • InvalidProgress(ref: String, progress: Int)
  • InvalidTransition(ref: String, status: String, action: String)

Upload transport mode.

pub type UploadMode {
  DirectServer
  ExternalClient(provider: String)
}

Constructors

  • DirectServer
  • ExternalClient(provider: String)

Values

pub fn add_entry(
  upload: Upload,
  ref: String,
  client_name: String,
  client_size: Int,
  client_type: String,
) -> #(Upload, Result(UploadEntry, UploadError))

Add one selected file entry with validation.

pub fn allow(
  name: String,
  mode: UploadMode,
  accept: List(String),
  max_entries: Int,
  max_file_size: Int,
) -> Upload

Build one upload configuration.

pub fn cancel(
  upload: Upload,
  ref: String,
  reason: String,
) -> #(Upload, Result(UploadEntry, UploadError))

Cancel one upload entry.

pub fn complete(
  upload: Upload,
  ref: String,
  location: String,
) -> #(Upload, Result(UploadEntry, UploadError))

Complete one upload entry.

pub fn entries(upload: Upload) -> List(UploadEntry)

Entries in selection order.

pub fn entry_status_label(status: EntryStatus) -> String

Stable status label for assertions and logs.

pub fn error_to_string(error: UploadError) -> String

Stable error label for assertions and logs.

pub fn errors(upload: Upload) -> List(UploadError)

Errors in occurrence order.

pub fn fail(
  upload: Upload,
  ref: String,
  reason: String,
) -> #(Upload, Result(UploadEntry, UploadError))

Mark one upload entry as failed.

pub fn mode(upload: Upload) -> UploadMode

Upload mode.

pub fn name(upload: Upload) -> String

Upload name.

pub fn prepare_external(
  upload: Upload,
  ref: String,
  upload_url: String,
) -> #(Upload, Result(UploadEntry, UploadError))

Prepare one external upload entry with a preflight URL.

pub fn progress(
  upload: Upload,
  ref: String,
  progress: Int,
) -> #(Upload, Result(UploadEntry, UploadError))

Update upload progress.

pub fn start_upload(
  upload: Upload,
  ref: String,
) -> #(Upload, Result(UploadEntry, UploadError))

Start uploading one entry.

Search Document