| 1 | import { eq } from "drizzle-orm"; |
| 2 | import type { NextRequest |
| 3 | import { revalidateTag } |
| 4 | import { getAuth } |
| 5 | import { db, settings |
| 6 | import { uploadObject, deleteObject |
| 7 | import { INSTANCE_SETTINGS_TAG } |
| 8 | |
| 9 | export const maxRequestBodySize = |
| 10 | |
| 11 | const ALLOWED_TYPES: Record |
| 12 | "image/jpeg": "jpg", |
| 13 | "image/png": "png", |
| 14 | "image/webp": "webp", |
| 15 | "image/gif": "gif", |
| 16 | "image/svg+xml": "svg", |
| 17 | }; |
| 18 | |
| 19 | const MAX_BYTES = 5 |
| 20 | |
| 21 | export async function POST |
| 22 | const auth = |
| 23 | const session = |
| 24 | if (!session || |
| 25 | return new Response |
| 26 | } |
| 27 | |
| 28 | const formData = |
| 29 | const file = |
| 30 | |
| 31 | if (!(file |
| 32 | return Response.json |
| 33 | } |
| 34 | |
| 35 | const ext = |
| 36 | if (!ext) |
| 37 | return Response.json |
| 38 | } |
| 39 | |
| 40 | if (file.size |
| 41 | return Response.json |
| 42 | } |
| 43 | |
| 44 | const newKey = |
| 45 | |
| 46 | const existing = |
| 47 | if (existing?.value |
| 48 | const oldKey = |
| 49 | if (oldKey !== |
| 50 | } |
| 51 | |
| 52 | const buffer = |
| 53 | await uploadObject(newKey |
| 54 | |
| 55 | const proxyUrl = |
| 56 | await db |
| 57 | .insert(settings) |
| 58 | .values({ key: |
| 59 | .onDuplicateKeyUpdate({ set: |
| 60 | |
| 61 | revalidateTag(INSTANCE_SETTINGS_TAG, {} |
| 62 | |
| 63 | return Response.json |
| 64 | } |