2024-06-27 11:39:03 -05:00
|
|
|
import { execSync } from "child_process";
|
|
|
|
import createFile from "../storage/createFile";
|
|
|
|
import { prisma } from "../db";
|
|
|
|
import { Link } from "@prisma/client";
|
|
|
|
|
|
|
|
const handleMonolith = async (link: Link, content: string) => {
|
|
|
|
if (!link.url) return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
let html = execSync(
|
|
|
|
`monolith - -I -b ${link.url} ${
|
2024-06-28 11:12:16 -05:00
|
|
|
process.env.MONOLITH_CUSTOM_OPTIONS || "-j -F -s"
|
2024-06-27 11:39:03 -05:00
|
|
|
} -o -`,
|
|
|
|
{
|
|
|
|
timeout: 120000,
|
|
|
|
maxBuffer: 1024 * 1024 * Number(process.env.MONOLITH_MAX_BUFFER || 5),
|
|
|
|
input: content,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2024-06-28 11:12:16 -05:00
|
|
|
if (!html?.length)
|
|
|
|
return console.error("Error archiving as Monolith: Empty buffer");
|
|
|
|
|
|
|
|
if (
|
|
|
|
Buffer.byteLength(html) >
|
|
|
|
1024 * 1024 * Number(process.env.MONOLITH_MAX_BUFFER || 6)
|
|
|
|
)
|
|
|
|
return console.error("Error archiving as Monolith: Buffer size exceeded");
|
2024-06-27 11:39:03 -05:00
|
|
|
|
|
|
|
await createFile({
|
|
|
|
data: html,
|
|
|
|
filePath: `archives/${link.collectionId}/${link.id}.html`,
|
|
|
|
}).then(async () => {
|
|
|
|
await prisma.link.update({
|
|
|
|
where: { id: link.id },
|
|
|
|
data: {
|
2024-06-27 20:58:07 -05:00
|
|
|
monolith: `archives/${link.collectionId}/${link.id}.html`,
|
2024-06-27 11:39:03 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch (err) {
|
2024-06-28 11:12:16 -05:00
|
|
|
console.log("Error running MONOLITH:", err);
|
2024-06-27 11:39:03 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default handleMonolith;
|