Skip to content

Commit

Permalink
fix: add format specifier to blob location claim URL (#1445)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw authored May 13, 2024
1 parent f8132ca commit 9982d12
Show file tree
Hide file tree
Showing 3 changed files with 543 additions and 538 deletions.
15 changes: 6 additions & 9 deletions packages/upload-api/src/blob/accept.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import * as DID from '@ipld/dag-ucan/did'
import * as W3sBlob from '@web3-storage/capabilities/web3.storage/blob'
import { Assert } from '@web3-storage/content-claims/capability'
import { create as createLink } from 'multiformats/link'
import { Digest } from 'multiformats/hashes/digest'
import { sha256 } from 'multiformats/hashes/sha2'
import * as Digest from 'multiformats/hashes/digest'
import { code as rawCode } from 'multiformats/codecs/raw'
import * as API from '../types.js'
import { AllocatedMemoryHadNotBeenWrittenTo } from './lib.js'
Expand All @@ -31,21 +30,19 @@ export function blobAcceptProvider(context) {
}
}

// TODO: we need to support multihash in claims, or specify hardcoded codec
const digest = new Digest(sha256.code, 32, blob.digest, blob.digest)
const digest = Digest.decode(blob.digest)
const content = createLink(rawCode, digest)
const w3link = `https://w3s.link/ipfs/${content.toString()}?origin=r2://${R2_REGION}/${R2_BUCKET}`
const url =
/** @type {API.URI<'https:'>} */
(`https://w3s.link/ipfs/${content}?format=raw&origin=r2://${R2_REGION}/${R2_BUCKET}`)

const locationClaim = await Assert.location.delegate({
issuer: context.id,
audience: DID.parse(space),
with: context.id.toDIDKey(),
nb: {
content,
location: [
// @ts-expect-error Type 'string' is not assignable to type '`${string}:${string}`'
w3link,
],
location: [url],
},
expiration: Infinity,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/upload-api/test/handlers/web3.storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ export const test = {
assert.equal(locations.length, 1)
assert.ok(
locations[0].includes(
`https://w3s.link/ipfs/${content.toString()}?origin`
`https://w3s.link/ipfs/${content}?format=raw&origin=`
)
)
},
Expand Down
Loading

0 comments on commit 9982d12

Please sign in to comment.