Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/danielroe/roe.dev. This is the code and content for my personal website, built in Nuxt. roe.dev
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021import { createError, defineEventHandler, getRequestHeader } from 'nuxt/server'
import { requireAdminAirspace } from '../../utils/airspace'
/** * Upload bytes to the PDS and return `{ blob, aspectRatio? }`. Dimensions come * from the image header, so a caller that has already measured the image does * not have to send them. */export default defineEventHandler(async event => { const contentType = getRequestHeader(event, 'content-type') || 'application/octet-stream' const bytes = new Uint8Array(await event.req.arrayBuffer()) if (!bytes.length) { throw createError({ status: 400, statusText: 'Empty body.' }) }
const airspace = await requireAdminAirspace(event) const { blob, aspectRatio } = await airspace.blobs.upload(bytes, { mimeType: contentType }) return { blob, ...(aspectRatio ? { aspectRatio } : {}) }})