summaryrefslogtreecommitdiff
path: root/frontend/app
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2025-08-13 11:33:51 +0100
committerdiogo464 <[email protected]>2025-08-13 11:33:51 +0100
commitca703fd5de303d2101fe2b2a5c0e3037b7507156 (patch)
tree7078378ea380b1cfdf502aa62f2e1ada5708ccac /frontend/app
parent74069a896a3b831a19baefc0d9487060b34760b3 (diff)
Implement path-based downloads with blob redirect system
- Add fctdrive stat command to get blob IDs from paths - Add Drive_stat function to drive_server.ts for backend integration - Create /download/[...path] endpoint that redirects to /blob/{blobId} - Update UI file links to use /download/ paths instead of direct blob links - Update permalinks to use immutable /blob/{blobId} URLs - Fix host preservation in redirects for remote access 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Diffstat (limited to 'frontend/app')
-rw-r--r--frontend/app/download/[...path]/route.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/frontend/app/download/[...path]/route.ts b/frontend/app/download/[...path]/route.ts
new file mode 100644
index 0000000..966a89e
--- /dev/null
+++ b/frontend/app/download/[...path]/route.ts
@@ -0,0 +1,37 @@
1import { NextRequest, NextResponse } from 'next/server'
2import { Drive_stat } from '@/lib/drive_server'
3
4// GET /download/[...path] - Download file by path (redirects to blob endpoint)
5export async function GET(
6 request: NextRequest,
7 { params }: { params: Promise<{ path: string[] }> }
8) {
9 try {
10 const { path } = await params
11
12 // Reconstruct the full path
13 const fullPath = '/' + path.join('/')
14
15 // Get filename from path for the download
16 const filename = path[path.length - 1] || 'download'
17
18 // Get blob ID using Drive_stat
19 const blobId = await Drive_stat(fullPath)
20
21 // Redirect to blob endpoint with filename - preserve original host
22 // Use X-Forwarded-Host or Host header to get the correct host
23 const forwardedHost = request.headers.get('x-forwarded-host')
24 const host = forwardedHost || request.headers.get('host') || new URL(request.url).host
25 const protocol = request.headers.get('x-forwarded-proto') || (new URL(request.url).protocol.replace(':', ''))
26 const redirectUrl = `${protocol}://${host}/blob/${blobId}?filename=${encodeURIComponent(filename)}`
27
28 return NextResponse.redirect(redirectUrl)
29
30 } catch (error) {
31 console.error('Download error:', error)
32 return new NextResponse(
33 error instanceof Error ? error.message : 'File not found',
34 { status: 404 }
35 )
36 }
37} \ No newline at end of file