From b4ff5719a5031c51cffa80803e946300d4af131c Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Tue, 2 Apr 2024 14:52:43 -0700 Subject: [PATCH] fix: avoid car repack (#2552) Adds call to upload/add to record uploads in web3.storage --- packages/api/src/index.js | 5 ----- packages/api/src/repl.js | 22 ---------------------- packages/api/src/routes/nfts-upload.js | 11 ++++++++++- 3 files changed, 10 insertions(+), 28 deletions(-) delete mode 100644 packages/api/src/repl.js diff --git a/packages/api/src/index.js b/packages/api/src/index.js index 1c33415b02..1ef0931dfa 100644 --- a/packages/api/src/index.js +++ b/packages/api/src/index.js @@ -35,7 +35,6 @@ import { } from './middleware/maintenance.js' import { getContext } from './utils/context.js' import { withAuth } from './middleware/auth.js' -import { repl } from './repl.js' const r = new Router(getContext, { onError(req, err, ctx) { @@ -48,10 +47,6 @@ const checkHasDeleteRestriction = true const checkHasPsaAccess = true const checkUcan = true -// Debugging - -r.add('post', '/repl', repl) - // Monitoring r.add('get', '/metrics', withMode(metrics, RO)) r.add('get', '/stats', withMode(getStats, RO), [postCors]) diff --git a/packages/api/src/repl.js b/packages/api/src/repl.js deleted file mode 100644 index e41db28c43..0000000000 --- a/packages/api/src/repl.js +++ /dev/null @@ -1,22 +0,0 @@ -import { JSONResponse } from './utils/json-response.js' -import { HTTPError } from './errors.js' - -/** @type {import('./bindings').Handler} */ -export const repl = async (event, ctx) => { - const { w3up } = ctx - - if (w3up) { - const blob = await event.request.blob() - if (blob.size === 0) { - throw new HTTPError('empty payload', 400) - } - - const car = await w3up.capability.store.add(blob) - - console.log('UPLOADED CAR') - - return new JSONResponse({ ok: true, value: car }) - } else { - throw new HTTPError(`No w3up client`, 500) - } -} diff --git a/packages/api/src/routes/nfts-upload.js b/packages/api/src/routes/nfts-upload.js index c2ab074709..b8bac04214 100644 --- a/packages/api/src/routes/nfts-upload.js +++ b/packages/api/src/routes/nfts-upload.js @@ -181,7 +181,16 @@ export async function uploadCarWithStat( const { w3up } = ctx console.log('UPLOADING CAR') - await w3up.capability.store.add(car) + + // we perform store/add and upload/add concurrently to save time. + await Promise.all([ + w3up.capability.store.add(car), + // We create an upload for each CAR and use it's CID as a shard, which + // will work as expected because `upload/add` merges all shards. + // @ts-expect-error Link types mismatch + w3up.capability.upload.add(stat.rootCid, [stat.cid]), + ]) + console.log('UPLOADED CAR') // register as gateway links to record the CAR CID - we don't have another // way to know the location right now.