mirror of
https://github.com/marcogll/TaxHacker_s23.git
synced 2026-01-13 13:25:18 +00:00
BREAKING: postgres + saas
This commit is contained in:
19
lib/previews/generate.ts
Normal file
19
lib/previews/generate.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
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] }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user