glyde/payload/file

Files going up with a message, and the attachments already on one that an edit should keep.

Discord pairs an uploaded part with its metadata through an attachments array whose id is the n in the files[n] part name. The array and parts number the same list.

On an edit that array is the complete resulting set: anything left out is deleted, so kept attachments and new files go together.

Types

What a message’s attachments should look like after an edit. Every route that edits a message takes one of these: the rule is the same wherever the field appears.

pub type EditAttachments {
  KeepAttachments
  SetAttachments(keep: List(KeptAttachment), add: List(File))
}

Constructors

  • KeepAttachments

    Leave them exactly as they are, and upload nothing.

  • SetAttachments(keep: List(KeptAttachment), add: List(File))

    The complete resulting set: keep plus add. Anything not listed is removed, so SetAttachments(keep: [], add: []) strips them all.

A file to upload.

pub type File {
  File(
    filename: String,
    content_type: String,
    data: BitArray,
    description: option.Option(String),
    title: option.Option(String),
    spoiler: Bool,
    voice: option.Option(Voice),
  )
}

Constructors

  • File(
      filename: String,
      content_type: String,
      data: BitArray,
      description: option.Option(String),
      title: option.Option(String),
      spoiler: Bool,
      voice: option.Option(Voice),
    )

    Arguments

    content_type

    Discord answers 500 on some endpoints when a part carries no content type. Use application/octet-stream when you do not know.

    description

    Alt text, max 1024 characters.

    spoiler

    The one place the spoiler lives. filename never carries the prefix: file moves it here and wire_filename puts it back.

    voice

    Set by voice_message. Discord needs both halves or neither, so they are one value.

pub type KeptAttachment {
  KeptAttachment(
    id: id.Id(id.Attachment),
    description: option.Option(String),
    title: option.Option(String),
  )
}

Constructors

What makes an upload a voice message rather than an audio file.

pub type Voice {
  Voice(duration_secs: Float, waveform: String)
}

Constructors

  • Voice(duration_secs: Float, waveform: String)

    Arguments

    waveform

    Base64 of the sampled amplitudes.

Values

pub fn added_files(edit: EditAttachments) -> List(File)

The files an edit uploads, in files[n] order.

pub fn attachments_field(
  edit: EditAttachments,
) -> field.Field(json.Json)

The attachments field of an edit. An empty array removes every attachment, so SetAttachments always writes the key.

pub fn described(a_file: File, alt: String) -> File

Alt text, read out by screen readers.

pub fn file(
  filename filename: String,
  content_type content_type: String,
  data data: BitArray,
) -> File

A SPOILER_ prefix on filename is read as asking for a spoiler and moved onto the boolean, so the two never say different things.

pub fn new_attachments_field(
  files: List(File),
) -> field.Field(json.Json)

The attachments field of a create, where the array is only the uploads and no array at all means no uploads.

pub fn parts(files: List(File)) -> List(body.File)

In files[n] order, the same order the attachments array numbers, so part n points at entry n.

pub fn spoilered(a_file: File) -> File

Deliver it blurred, behind a click.

pub fn voice_message(
  a_file: File,
  duration_secs duration_secs: Float,
  waveform waveform: String,
) -> File

Send it as a voice message. Discord also wants the IS_VOICE_MESSAGE flag on the message and an audio content type on the part.

pub fn wire_filename(a_file: File) -> String

The filename as it goes on the wire, spoiler prefix included. spoiler decides, not the name: a record built by hand with a prefixed filename gets stripped rather than prefixed twice.

Search Document