Skip to content

Commit

Permalink
api context tries to construct a w3up-client
Browse files Browse the repository at this point in the history
  • Loading branch information
gobengo committed Mar 21, 2024
1 parent 1532a09 commit f18264c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/api/src/routes/nfts-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ export async function nftUpload(event, ctx) {
W3_NFTSTORAGE_PROOF: ctx.W3_NFTSTORAGE_PROOF,
W3_NFTSTORAGE_SPACE: ctx.W3_NFTSTORAGE_SPACE,
}
console.log('in nfts-upload handler w/ w3up', w3upConfig)

console.log('in nfts-upload handler w/ w3up', {
...w3upConfig,
w3up: ctx.w3up,
})
if (ctx.W3UP_URL) {
const w3upResponse = await fetch(ctx.W3UP_URL)
}
Expand Down
19 changes: 18 additions & 1 deletion packages/api/src/utils/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Logging } from './logs.js'
import pkg from '../../package.json'
import { Service } from 'ucan-storage/service'
import { LinkdexApi } from './linkdex.js'
import { createW3upClientFromConfig } from './w3up.js'

/**
* Obtains a route context object.
Expand Down Expand Up @@ -69,7 +70,22 @@ export async function getContext(event, params) {
W3_NFTSTORAGE_PROOF: config.W3_NFTSTORAGE_PROOF,
W3_NFTSTORAGE_SPACE: config.W3_NFTSTORAGE_SPACE,
}
console.log('in getContext', w3upConfig)
let w3up
if (
config.W3UP_URL &&
config.W3_NFTSTORAGE_PRINCIPAL &&
config.W3_NFTSTORAGE_PROOF
) {
try {
w3up = await createW3upClientFromConfig({
url: config.W3UP_URL,
principal: config.W3_NFTSTORAGE_PRINCIPAL,
proof: config.W3_NFTSTORAGE_PROOF,
})
} catch (error) {
console.error(`error creatong w3up-client from config`, error)
}
}
return {
...w3upConfig,
params,
Expand All @@ -79,5 +95,6 @@ export async function getContext(event, params) {
r2Uploader,
log,
ucanService,
w3up,
}
}

0 comments on commit f18264c

Please sign in to comment.