Explorer

definy.upload-content

description
The RPC UploadContent: store items (contentHash and contentBytes) in the CAS. Nothing is stored if a contentHash is not the SHA-256 of its contentBytes
type
Fn(request: @definy.json) -> @definy.service-io
expression
fn(request$1027) =>
  match match @definy.json-get(value: $1027, key: "items") {
      #none(_) =>
        #some([]),
      #some(value$1028) =>
        match $1028 {
          #array(items$1029) =>
            @definy.json-content-items(items: $1029, index: 0, accum: []),
          #null(_) =>
            #some([]),
          _ =>
            #none
        }
    } {
    #none(_) =>
      @definy.rpc-error(code: "invalid_argument", message: "items must be a list of {contentHash, contentBytes}"),
    #some(items$1030) =>
      #hash_contents<@definy.service-io>({
        contents_bytes: @definy.content-items-bytes(items: $1030, index: 0, accum: []),
        then: fn(hashes$1031) =>
          match @definy.content-hash-mismatch(items: $1030, hashes: $1031, index: 0) {
            #some(message$1032) =>
              @definy.rpc-error(code: "invalid_argument", message: $1032),
            #none(_) =>
              @definy.store-write-contents(
                items: $1030,
                then: fn(stored$1033) =>
                  @definy.json-response(
                    status: 200,
                    body: #object<@definy.json>([
                      {
                        key: "storedContentHashes",
                        value: #array<@definy.json>(@definy.json-string-array(items: $1033, index: 0))
                      }
                    ])
                  )
              )
          }
      })
  }
visibility
public
definy.upload-content (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: suZMsY_JSb17Nl1NYX2HRqWOaXEJENSuzx8l43EUfIc
content hash: LFdC-uJI0lNtJZ3o_9a3qDhPCa9szGkORI2yq-dQX5c