Add PDF translation API, utilities, docs, and config

Introduces core backend and frontend infrastructure for a PDF translation interface. Adds API endpoints for translation, PDF testing, and AI provider testing; implements PDF text extraction, cost tracking, and pricing logic in the lib directory; adds reusable UI components; and provides comprehensive documentation (SDD, environment setup, Claude instructions). Updates Tailwind and global styles, and includes a sample test PDF and configuration files.
This commit is contained in:
2025-10-15 23:34:44 +08:00
parent c899702d51
commit 39a4788cc4
21 changed files with 11041 additions and 251 deletions

42
app/api/test-pdf/route.ts Normal file
View File

@@ -0,0 +1,42 @@
import { NextRequest, NextResponse } from "next/server"
import { extractTextFromPDF } from "@/lib/pdf-processor"
export async function POST(request: NextRequest) {
try {
const formData = await request.formData()
const file = formData.get("file") as File
if (!file) {
return NextResponse.json({ error: "No file provided" }, { status: 400 })
}
if (file.type !== "application/pdf") {
return NextResponse.json({ error: "File must be PDF" }, { status: 400 })
}
console.log(`Testing PDF: ${file.name}, size: ${file.size} bytes`)
const arrayBuffer = await file.arrayBuffer()
const buffer = Buffer.from(arrayBuffer)
const result = await extractTextFromPDF(buffer)
return NextResponse.json({
success: true,
result: {
text: result.text,
textLength: result.text.length,
pageCount: result.pageCount,
isScanned: result.isScanned,
metadata: result.metadata
}
})
} catch (error) {
console.error("PDF test error:", error)
return NextResponse.json({
error: `PDF test failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
details: error instanceof Error ? error.stack : undefined
}, { status: 500 })
}
}