-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for `blob/get` as defined in storacha/specs#126 --------- Co-authored-by: Vasco Santos <santos.vasco10@gmail.com> Co-authored-by: Irakli Gozalishvili <contact@gozala.io>
- Loading branch information
1 parent
695af8b
commit 328039d
Showing
13 changed files
with
314 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as Server from '@ucanto/server' | ||
import * as Blob from '@web3-storage/capabilities/blob' | ||
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 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 res | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.