Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

feat(web): add option to upload html archive

Kha Nguyen65f0075a6f6b
diff --git a/apps/web/components/PreserverdFormatRow.tsx b/apps/web/components/PreserverdFormatRow.tsx
index fc296d9d..73931c28 100644
--- a/apps/web/components/PreserverdFormatRow.tsx
+++ b/apps/web/components/PreserverdFormatRow.tsx
@@ -5,6 +5,7 @@ import {
import Link from "next/link";
import { useRouter } from "next/router";
import { Button } from "@/components/ui/button";
+import toast from "react-hot-toast";
type Props = {
name: string;
@@ -62,6 +63,42 @@ export default function PreservedFormatRow({
</Button>
) : undefined}
+ {!isPublic && format === ArchivedFormat.monolith ? (
+ <Button asChild variant="ghost" size="icon">
+ <label className="cursor-pointer">
+ <i className="bi-cloud-arrow-up text-xl text-neutral" />
+ <input
+ type="file"
+ accept="text/html,.html"
+ className="hidden"
+ onChange={async (e) => {
+ const file = e.target.files?.[0];
+ if (!file) return;
+ const formBody = new FormData();
+ formBody.append("file", file);
+
+ const res = await fetch(
+ `/api/v1/archives/${link?.id}?format=${format}`,
+ {
+ method: "POST",
+ body: formBody,
+ }
+ );
+
+ if (res.ok) {
+ toast.success("Replaced webpage HTML");
+ // refresh page data
+ router.replace(router.asPath);
+ } else {
+ const data = await res.json().catch(() => ({}));
+ toast.error(data?.response || "Failed to replace HTML");
+ }
+ }}
+ />
+ </label>
+ </Button>
+ ) : undefined}
+
<Button asChild variant="ghost" size="icon">
<Link
href={`${
diff --git a/apps/web/pages/api/v1/archives/[linkId].ts b/apps/web/pages/api/v1/archives/[linkId].ts
index 7a37be84..c9b6a44c 100644
--- a/apps/web/pages/api/v1/archives/[linkId].ts
+++ b/apps/web/pages/api/v1/archives/[linkId].ts
@@ -227,6 +227,7 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse) {
"image/png",
"image/jpg",
"image/jpeg",
+ "text/html",
];
const fileBuffer = validateFile(
files.file[0],
@@ -246,6 +247,7 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse) {
const { mimetype } = files.file[0];
const isPDF = mimetype?.includes("pdf");
const isImage = mimetype?.includes("image");
+ const isHTML = mimetype === "text/html";
console.log("isPDF", isPDF);
@@ -275,6 +277,9 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse) {
pdf: isPDF
? `archives/${collectionPermissions.id}/${linkId + suffix}`
: undefined,
+ monolith: isHTML && !isPreview
+ ? `archives/${collectionPermissions.id}/${linkId + suffix}`
+ : undefined,
updatedAt: new Date().toISOString(),
},
});
diff --git a/packages/lib/schemaValidation.ts b/packages/lib/schemaValidation.ts
index 7a3d22bd..664c21b6 100644
--- a/packages/lib/schemaValidation.ts
+++ b/packages/lib/schemaValidation.ts
@@ -184,6 +184,7 @@ const ACCEPTED_TYPES = [
"image/png",
"application/pdf",
"text/plain",
+ "text/html",
];
const NEXT_PUBLIC_MAX_FILE_BUFFER = Number(
process.env.NEXT_PUBLIC_MAX_FILE_BUFFER || 10