Skip to content

Commit

Permalink
chore: expose simple route to debug (#2546)
Browse files Browse the repository at this point in the history
I was thinking to try something along these lines
  • Loading branch information
Gozala authored Apr 1, 2024
1 parent 654cde7 commit 8a9aef5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ 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) {
Expand All @@ -47,6 +48,10 @@ const checkHasDeleteRestriction = true
const checkHasPsaAccess = true
const checkUcan = true

// Debugging

r.add('get', '/repl', repl)

// Monitoring
r.add('get', '/metrics', withMode(metrics, RO))
r.add('get', '/stats', withMode(getStats, RO), [postCors])
Expand Down
27 changes: 27 additions & 0 deletions packages/api/src/repl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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 result = await w3up.uploadCAR(blob, {
onShardStored: ({ cid }) => {
console.log(`SHARD ${cid}`)
},
// @ts-expect-error TODO adjust upstream type
pieceHasher: null,
})
console.log('UPLOADED CAR')

return new JSONResponse({ ok: true, value: result })
} else {
throw new HTTPError(`No w3up client`, 500)
}
}

0 comments on commit 8a9aef5

Please sign in to comment.