fix: support using monolith content for other archives

This commit is contained in:
Spy
2025-10-10 21:39:08 -07:00
parent b21e2c6ffd
commit 7d45249e8f

View File

@@ -3,7 +3,7 @@ import { prisma } from "@linkwarden/prisma";
import sendToWayback from "./preservationScheme/sendToWayback";
import { AiTaggingMethod } from "@linkwarden/prisma/client";
import fetchHeaders from "./fetchHeaders";
import { createFolder, removeFiles } from "@linkwarden/filesystem";
import { createFolder, readFile, removeFiles } from "@linkwarden/filesystem";
import handleMonolith from "./preservationScheme/handleMonolith";
import handleReadability from "./preservationScheme/handleReadability";
import handleArchivePreview from "./preservationScheme/handleArchivePreview";
@@ -119,6 +119,22 @@ export default async function archiveHandler(
} else if (link.url) {
await page.goto(link.url, { waitUntil: "domcontentloaded" });
// Handle Monolith being sent in beforehand while making sure other values line up
if (link.monolith) {
// Use Monolith content instead of page
const file = await readFile(link.monolith);
if (file.contentType == "text/html") {
const fileContent = file.file;
if (typeof fileContent === "string") {
await page.setContent(fileContent, { waitUntil: "domcontentloaded" });
} else {
await page.setContent(fileContent.toString("utf-8"), { waitUntil: "domcontentloaded" });
}
}
}
const metaDescription = await page.evaluate(() => {
const description = document.querySelector(
'meta[name="description"]'