diff --git a/packages/api/src/routes/nfts-upload.js b/packages/api/src/routes/nfts-upload.js index c9c2c31c05..e970c4717c 100644 --- a/packages/api/src/routes/nfts-upload.js +++ b/packages/api/src/routes/nfts-upload.js @@ -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) } diff --git a/packages/api/src/utils/context.js b/packages/api/src/utils/context.js index 58aff37beb..e06d32eb15 100644 --- a/packages/api/src/utils/context.js +++ b/packages/api/src/utils/context.js @@ -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. @@ -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, @@ -79,5 +95,6 @@ export async function getContext(event, params) { r2Uploader, log, ucanService, + w3up, } }