fixes and improvements

This commit is contained in:
daniel31x13
2023-12-04 10:24:45 -05:00
parent ee05975e10
commit 1f20180a51
15 changed files with 75 additions and 35 deletions
+21 -9
View File
@@ -89,8 +89,6 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {
});
form.parse(req, async (err, fields, files) => {
console.log(files);
const allowedMIMETypes = [
"application/pdf",
"image/png",
@@ -109,17 +107,31 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {
response: `Sorry, we couldn't process your file. Please ensure it's a PDF, PNG, or JPG format and doesn't exceed ${MAX_UPLOAD_SIZE}MB.`,
});
} else {
console.log(files.file[0].mimetype);
const fileBuffer = fs.readFileSync(files.file[0].filepath);
console.log(fileBuffer);
await createFile({
filePath: `archives/${collectionPermissions?.id}/${linkId + suffix}`,
data: fileBuffer,
const linkStillExists = await prisma.link.findUnique({
where: { id: linkId },
});
if (linkStillExists) {
await createFile({
filePath: `archives/${collectionPermissions?.id}/${
linkId + suffix
}`,
data: fileBuffer,
});
await prisma.link.update({
where: { id: linkId },
data: {
screenshotPath: `archives/${collectionPermissions?.id}/${
linkId + suffix
}`,
lastPreserved: new Date().toISOString(),
},
});
}
fs.unlinkSync(files.file[0].filepath);
}