| 31 | |
| 32 | // GET /7d/<id>.html 或 /30d/<id>.html —— 从 R2 读,返回 text/html |
| 33 | async function handleGet(url: URL, env: Env): Promise<Response> { |
| 34 | const match = GET_PATH_PATTERN.exec(url.pathname) |
| 35 | if (!match) { |
| 36 | return json({ error: 'not_found' }, 404) |
| 37 | } |
| 38 | const [, prefix, id] = match |
| 39 | const obj = await env.BUCKET.get(`${prefix}/${id}.html`) |
| 40 | if (obj === null) { |
| 41 | return new Response('Not Found', { status: 404 }) |
| 42 | } |
| 43 | const headers = new Headers() |
| 44 | obj.writeHttpMetadata(headers) |
| 45 | headers.set('content-type', HTML_CONTENT_TYPE) |
| 46 | headers.set('cache-control', 'public, max-age=86400') |
| 47 | return new Response(obj.body, { headers, status: 200 }) |
| 48 | } |
| 49 | |
| 50 | async function handleUpload( |
| 51 | req: Request, |