| 1 | import { and, eq } from "drizzle-orm"; |
| 2 | import type { NextRequest |
| 3 | import { getAuth } |
| 4 | import { db } |
| 5 | import { nodes, servers |
| 6 | import { safeDecrypt } |
| 7 | import { signFileDownloadToken } |
| 8 | |
| 9 | export async function GET |
| 10 | req: NextRequest |
| 11 | { params }: |
| 12 | ) { |
| 13 | const auth = |
| 14 | const session = |
| 15 | if (!session) |
| 16 | |
| 17 | const { id |
| 18 | const file = |
| 19 | if (!file) |
| 20 | |
| 21 | const normalized = |
| 22 | if ( |
| 23 | normalized.includes("\0 |
| 24 | !normalized.startsWith(" |
| 25 | /^[A-Za-z]:/.test |
| 26 | normalized.split("/ |
| 27 | ) { |
| 28 | return new Response |
| 29 | } |
| 30 | |
| 31 | const server = |
| 32 | where: eq(servers |
| 33 | with: { node: true |
| 34 | }); |
| 35 | if (!server) |
| 36 | |
| 37 | const isOwner = |
| 38 | const isAdmin = |
| 39 | |
| 40 | if (!isOwner && |
| 41 | const sub = |
| 42 | where: and(eq |
| 43 | }); |
| 44 | if (!sub) |
| 45 | let permissions: |
| 46 | try { |
| 47 | permissions = JSON. |
| 48 | } catch { |
| 49 | permissions = []; |
| 50 | } |
| 51 | const hasFileAccess = |
| 52 | (p) => |
| 53 | ); |
| 54 | if (!hasFileAccess) |
| 55 | } |
| 56 | |
| 57 | const node = |
| 58 | const token = |
| 59 | session.user.id |
| 60 | server.uuid, |
| 61 | file, |
| 62 | safeDecrypt(node.token |
| 63 | ); |
| 64 | const url = |
| 65 | return new Response |
| 66 | status: 302, |
| 67 | headers: { |
| 68 | Location: url, |
| 69 | "Referrer-Policy": "no-referrer", |
| 70 | }, |
| 71 | }); |
| 72 | } |