// The Vercel Blob side of the relay (store igneum-relay): the only module that imports @vercel/blob, so everything // else loads without node_modules. api/relay.mjs hands these three to lib/handler.mjs; the tests hand it fakes. import { put, del } from '@vercel/blob'; import { generateClientTokenFromReadWriteToken } from '@vercel/blob/client'; import { blobPath, MAX_BLOB } from './relay.mjs'; export async function storeBuffer(name, buf, contentType) { const r = await put(blobPath(name), buf, { access: 'public', addRandomSuffix: true, contentType: contentType || 'application/octet-stream', }); return { url: r.url, size: buf.length }; } export async function clientUploadToken(name, size) { const pathname = blobPath(name); const token = await generateClientTokenFromReadWriteToken({ pathname, addRandomSuffix: true, allowOverwrite: false, maximumSizeInBytes: MAX_BLOB, validUntil: Date.now() + 60 * 60 * 1000, }); return { token, pathname, put_url: `https://vercel.com/api/blob/?pathname=${encodeURIComponent(pathname)}`, api_version: '11', max: MAX_BLOB, size }; } /** Deletes the blobs behind the given URLs (X26: a deleted or expired row takes its file with it). Never throws. */ export async function deleteBlobs(urls) { const list = [...new Set(urls.filter(Boolean))]; if (!list.length) return 0; try { await del(list); return list.length; } catch { return 0; } }