diff --git a/server/api/cdn/[...path].get.ts b/server/api/cdn/[...path].get.ts new file mode 100644 index 0000000..2f8b5e6 --- /dev/null +++ b/server/api/cdn/[...path].get.ts @@ -0,0 +1,16 @@ +import type { R2Bucket } from '@cloudflare/workers-types' + +export default defineCachedEventHandler(async (event) => { + const bucket: R2Bucket = event.context.cloudflare.env.R2_SSTAA + const file = await bucket.get(event.context.params!.path) + if (!file) { + throw createError({ + statusCode: 404, + statusMessage: 'Not found', + }) + } + + return sendStream(event, file.body as any) +}, { + maxAge: 60, +})