feat: analyze all button, support for UTF8 filenames

This commit is contained in:
vas3k
2025-05-22 19:22:30 +02:00
parent feb56fa3ac
commit 347cf2a0e8
7 changed files with 40 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
import { getCurrentUser } from "@/lib/auth"
import { fileExists, fullPathForFile } from "@/lib/files"
import { encodeFilename } from "@/lib/utils"
import { getFileById } from "@/models/files"
import fs from "fs/promises"
import { NextResponse } from "next/server"
@@ -30,12 +31,12 @@ export async function GET(request: Request, { params }: { params: Promise<{ file
// Read file
const fileBuffer = await fs.readFile(fullFilePath)
// Return file with proper content type
// Return file with proper content type and encoded filename
return new NextResponse(fileBuffer, {
headers: {
"Content-Type": file.mimetype,
"Content-Disposition": `attachment; filename="${file.filename}"`,
},
"Content-Disposition": `attachment; filename*=${encodeFilename(file.filename)}`,
},
})
} catch (error) {
console.error("Error serving file:", error)

View File

@@ -5,6 +5,7 @@ import { getFileById } from "@/models/files"
import fs from "fs/promises"
import { NextResponse } from "next/server"
import path from "path"
import { encodeFilename } from "@/lib/utils"
export async function GET(request: Request, { params }: { params: Promise<{ fileId: string }> }) {
const { fileId } = await params
@@ -46,7 +47,7 @@ export async function GET(request: Request, { params }: { params: Promise<{ file
return new NextResponse(fileBuffer, {
headers: {
"Content-Type": contentType,
"Content-Disposition": `inline; filename="${path.basename(previewPath)}"`,
"Content-Disposition": `inline; filename*=${encodeFilename(path.basename(previewPath))}`,
},
})
} catch (error) {