mirror of
https://github.com/marcogll/TaxHacker_s23.git
synced 2026-01-13 21:35:19 +00:00
20 lines
698 B
TypeScript
20 lines
698 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] }
|
|
}
|
|
}
|