| 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 | }; |
| 16 | |
| 17 | const MAX_BYTES = 8 |
| 18 | |
| 19 | export async function POST |
| 20 | const auth = |
| 21 | const session = |
| 22 | if (!session || |
| 23 | return new Response |
| 24 | } |
| 25 | |
| 26 | const formData = |
| 27 | const file = |
| 28 | |
| 29 | if (!(file |
| 30 | return Response.json |
| 31 | } |
| 32 | |
| 33 | const ext = |
| 34 | if (!ext) |
| 35 | return Response.json |
| 36 | } |
| 37 | |
| 38 | if (file.size |
| 39 | return Response.json |
| 40 | } |
| 41 | |
| 42 | const newKey = |
| 43 | |
| 44 | const existing = |
| 45 | if (existing?.value |
| 46 | const oldKey = |
| 47 | if (oldKey !== |
| 48 | } |
| 49 | |
| 50 | const buffer = |
| 51 | await uploadObject(newKey |
| 52 | |
| 53 | const proxyUrl = |
| 54 | await db |
| 55 | .insert(settings) |
| 56 | .values({ key: |
| 57 | .onDuplicateKeyUpdate({ set: |
| 58 | |
| 59 | revalidateTag(INSTANCE_SETTINGS_TAG, {} |
| 60 | |
| 61 | return Response.json |
| 62 | } |