Merge pull request #1448 from supercoolspy/fix/singlefile-view

fix: support using monolith content for other archive formats
This commit is contained in:
Daniel
2025-10-15 14:21:03 +03:30
committed by GitHub
2 changed files with 30 additions and 1 deletions

View File

@@ -162,6 +162,11 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse) {
},
},
url,
// temporarily prevent archiveHandler and other processes from overwriting the file while we're uploading it
lastPreserved: new Date(0).toISOString(),
aiTagged: true,
indexVersion: 1,
},
});
@@ -203,6 +208,10 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse) {
: undefined,
clientSide: true,
updatedAt: new Date().toISOString(),
lastPreserved: null,
aiTagged: false,
indexVersion: null,
},
});

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";
@@ -120,6 +120,26 @@ 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?.endsWith(".html")) {
// 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"]'