small changes

This commit is contained in:
daniel31x13 2024-06-18 12:27:29 -04:00
parent 359d22e61b
commit c68f9d68ad
3 changed files with 99 additions and 133 deletions

View File

@ -5,7 +5,10 @@ import TextInput from "@/components/TextInput";
import unescapeString from "@/lib/client/unescapeString"; import unescapeString from "@/lib/client/unescapeString";
import useCollectionStore from "@/store/collections"; import useCollectionStore from "@/store/collections";
import useLinkStore from "@/store/links"; import useLinkStore from "@/store/links";
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global"; import {
LinkIncludingShortenedCollectionAndTags,
ArchivedFormat,
} from "@/types/global";
import { useSession } from "next-auth/react"; import { useSession } from "next-auth/react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import toast from "react-hot-toast"; import toast from "react-hot-toast";
@ -110,11 +113,7 @@ export default function UploadFileModal({ onClose }: Props) {
linkType = "pdf"; linkType = "pdf";
} }
if (fileType !== null && linkType !== null) {
setSubmitLoader(true); setSubmitLoader(true);
let response;
const load = toast.loading(t("creating")); const load = toast.loading(t("creating"));
const response = await uploadFile(link, file); const response = await uploadFile(link, file);

View File

@ -50,18 +50,6 @@ export default async function archiveHandler(link: LinksAndCollectionAndOwner) {
const page = await context.newPage(); const page = await context.newPage();
const timeoutPromise = new Promise((_, reject) => {
setTimeout(
() =>
reject(
new Error(
`Browser has been open for more than ${BROWSER_TIMEOUT} minutes.`
)
),
BROWSER_TIMEOUT * 60000
);
});
createFolder({ createFolder({
filePath: `archives/preview/${link.collectionId}`, filePath: `archives/preview/${link.collectionId}`,
}); });
@ -178,35 +166,6 @@ export default async function archiveHandler(link: LinksAndCollectionAndOwner) {
if (imageResponse && !link.preview?.startsWith("archive")) { if (imageResponse && !link.preview?.startsWith("archive")) {
const buffer = await imageResponse.body(); const buffer = await imageResponse.body();
await generatePreview(buffer, link.collectionId, link.id); await generatePreview(buffer, link.collectionId, link.id);
// Check if buffer is not null
if (buffer) {
// Load the image using Jimp
Jimp.read(buffer, async (err, image) => {
if (image && !err) {
image?.resize(1280, Jimp.AUTO).quality(20);
const processedBuffer = await image?.getBufferAsync(
Jimp.MIME_JPEG
);
createFile({
data: processedBuffer,
filePath: `archives/preview/${link.collectionId}/${link.id}.jpeg`,
}).then(() => {
return prisma.link.update({
where: { id: link.id },
data: {
preview: `archives/preview/${link.collectionId}/${link.id}.jpeg`,
},
});
});
}
}).catch((err) => {
console.error("Error processing the image:", err);
});
} else {
console.log("No image data found.");
}
} }
await page.goBack(); await page.goBack();
@ -301,7 +260,6 @@ export default async function archiveHandler(link: LinksAndCollectionAndOwner) {
}); });
} }
} }
}
})(), })(),
timeoutPromise, timeoutPromise,
]); ]);

View File

@ -16,6 +16,10 @@ const removeFiles = async (linkId: number, collectionId: number) => {
await removeFile({ await removeFile({
filePath: `archives/${collectionId}/${linkId}.jpg`, filePath: `archives/${collectionId}/${linkId}.jpg`,
}); });
// HTML
await removeFile({
filePath: `archives/${collectionId}/${linkId}.html`,
});
// Preview // Preview
await removeFile({ await removeFile({
filePath: `archives/preview/${collectionId}/${linkId}.jpeg`, filePath: `archives/preview/${collectionId}/${linkId}.jpeg`,
@ -47,6 +51,11 @@ const moveFiles = async (linkId: number, from: number, to: number) => {
`archives/${to}/${linkId}.jpg` `archives/${to}/${linkId}.jpg`
); );
await moveFile(
`archives/${from}/${linkId}.html`,
`archives/${to}/${linkId}.html`
);
await moveFile( await moveFile(
`archives/preview/${from}/${linkId}.jpeg`, `archives/preview/${from}/${linkId}.jpeg`,
`archives/preview/${to}/${linkId}.jpeg` `archives/preview/${to}/${linkId}.jpeg`