Skip to content

Commit

Permalink
fix: blob get
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed Jun 6, 2024
1 parent d9bd509 commit 08c1695
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/upload-api/src/blob/get.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import * as Server from '@ucanto/server'
import * as Blob from '@web3-storage/capabilities/blob'
import * as Digest from 'multiformats/hashes/digest'
import * as API from '../types.js'
import { BlobNotFound } from './lib.js'
import { decode } from 'multiformats/hashes/digest'

/**
* @param {API.BlobServiceContext} context
* @returns {API.ServiceMethod<API.BlobGet, API.BlobGetSuccess, API.BlobGetFailure>}
*/
export function blobGetProvider(context) {
return Server.provide(Blob.get, async ({ capability }) => {
const { digest } = capability.nb
const digest = Digest.decode(capability.nb.digest)
const space = Server.DID.parse(capability.with).did()
const res = await context.allocationsStorage.get(space, digest)
if (res.error && res.error.name === 'RecordNotFound') {
return Server.error(new BlobNotFound(decode(digest)))
return Server.error(new BlobNotFound(digest))
}
return res
})
Expand Down

0 comments on commit 08c1695

Please sign in to comment.