Explorer

definy.get-content

description
The RPC GetContent: the CAS content with contentHash (item; not_found if missing), or else the found contents with contentHashes (items). invalid_argument without either
type
Fn(request: @definy.json) -> @definy.service-io
expression
fn(request$0) =>
  let hash$1 = @definy.string-trim(
      value: match @definy.json-get-string(value: $0, key: "contentHash") {
        #some(text$2) =>
          $2,
        #none(_) =>
          ""
      }
    );
  match @core.equal(left: $1, right: "") {
    true =>
      match @definy.json-get-strings(value: $0, key: "contentHashes") {
        #none(_) =>
          @definy.rpc-error(code: "invalid_argument", message: "contentHash or contentHashes is required"),
        #some(hashes$3) =>
          @definy.store-read-contents(
            content_hashes: $3,
            then: fn(items$4) =>
              @definy.json-response(
                status: 200,
                body: #object<@definy.json>([
                  {key: "items", value: #array<@definy.json>(@definy.found-content-items-json(items: $4, index: 0))}
                ])
              )
          )
      },
    false =>
      @definy.store-read-contents(
        content_hashes: [$1],
        then: fn(items$5) =>
          match @core.list-get(list: $5, index: 0) {
            #none(_) =>
              @definy.rpc-error(
                code: "not_found",
                message: @core.string-concat(left: @core.string-concat(left: "Content '", right: $1), right: "' not found")
              ),
            #some(element$97001) =>
              match $97001 {
                #none(_) =>
                  @definy.rpc-error(
                    code: "not_found",
                    message: @core.string-concat(left: @core.string-concat(left: "Content '", right: $1), right: "' not found")
                  ),
                #some(item$6) =>
                  @definy.json-response(
                    status: 200,
                    body: #object<@definy.json>([{key: "item", value: @definy.content-item-json(item: $6)}])
                  )
              }
          }
      )
  }
visibility
public
definy.get-content (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: OxTpVOu0EimNuy0hPnwE9ckU1WpghzS0o8aUwhnrYGk
content hash: FUSU0fX_3rh7P0rAAXPQj2ncpnQqm5EDT8F1TN8HB-o