| 1 | import { and, eq } from 'drizzle-orm' |
| 2 | import { alias } |
| 3 | import type { NextRequest |
| 4 | import { NextResponse } |
| 5 | import { getSession } |
| 6 | import { db } |
| 7 | import { media, members |
| 8 | import { s3Service } |
| 9 | |
| 10 | export async function GET |
| 11 | request: NextRequest |
| 12 | { params }: |
| 13 | ) { |
| 14 | const session = |
| 15 | if (!session) |
| 16 | return NextResponse.json |
| 17 | } |
| 18 | |
| 19 | const { id |
| 20 | |
| 21 | const [mediaRecord] |
| 22 | if (!mediaRecord) |
| 23 | return NextResponse.json |
| 24 | } |
| 25 | |
| 26 | if (mediaRecord.userId |
| 27 | const authorMembers = |
| 28 | const viewerMembers = |
| 29 | |
| 30 | const [link] |
| 31 | .select({ organizationId: |
| 32 | .from(authorMembers) |
| 33 | .innerJoin( |
| 34 | viewerMembers, |
| 35 | eq(authorMembers.organizationId |
| 36 | ) |
| 37 | .where( |
| 38 | and( |
| 39 | eq(authorMembers.userId |
| 40 | eq(viewerMembers.userId |
| 41 | ) |
| 42 | ) |
| 43 | .limit(1) |
| 44 | |
| 45 | if (!link) |
| 46 | return NextResponse.json |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | const signedUrl = |
| 51 | |
| 52 | return NextResponse.redirect |
| 53 | status: 302, |
| 54 | headers: { |
| 55 | 'Cache-Control': 'private, max-age=3500', |
| 56 | }, |
| 57 | }) |
| 58 | } |