Files
TaxHacker_s23/lib/previews/generate.ts
2025-04-03 13:07:54 +02:00

20 lines
697 B
TypeScript

import { resizeImage } from "@/lib/previews/images"
import { pdfToImages } from "@/lib/previews/pdf"
import { User } from "@prisma/client"
export async function generateFilePreviews(
user: User,
filePath: string,
mimetype: string
): Promise<{ contentType: string; previews: string[] }> {
if (mimetype === "application/pdf") {
const { contentType, pages } = await pdfToImages(user, filePath)
return { contentType, previews: pages }
} else if (mimetype.startsWith("image/")) {
const { contentType, resizedPath } = await resizeImage(user, filePath)
return { contentType, previews: [resizedPath] }
} else {
return { contentType: mimetype, previews: [filePath] }
}
}