Skip to content

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

bug fixed

daniel31x13476a9d78a452
diff --git a/apps/web/lib/api/controllers/links/postLink.ts b/apps/web/lib/api/controllers/links/postLink.ts
index c9cff768..044c091b 100644
--- a/apps/web/lib/api/controllers/links/postLink.ts
+++ b/apps/web/lib/api/controllers/links/postLink.ts
@@ -72,7 +72,7 @@ export default async function postLink(
}
const { title = "", headers = new Headers() } = link.url
- ? await fetchTitleAndHeaders(link.url, null)
+ ? await fetchTitleAndHeaders(link.url)
: {};
const name =
diff --git a/apps/web/lib/shared/fetchTitleAndHeaders.ts b/apps/web/lib/shared/fetchTitleAndHeaders.ts
index d0662591..5b181654 100644
--- a/apps/web/lib/shared/fetchTitleAndHeaders.ts
+++ b/apps/web/lib/shared/fetchTitleAndHeaders.ts
@@ -3,7 +3,10 @@ import https from "https";
import { HttpsProxyAgent } from "https-proxy-agent";
import { SocksProxyAgent } from "socks-proxy-agent";
-export default async function fetchTitleAndHeaders(url: string, content: string | null) {
+export default async function fetchTitleAndHeaders(
+ url: string,
+ content?: string
+) {
if (!url?.startsWith("http://") && !url?.startsWith("https://"))
return { title: "", headers: null };
@@ -48,14 +51,19 @@ export default async function fetchTitleAndHeaders(url: string, content: string
let text: string;
if (content) {
- text = content
+ text = content;
} else {
- text = await (response as any).text()
+ text = await (response as any).text();
}
const headers = (response as Response)?.headers || null;
- return await fetchTitleAndHeadersFromContent(text, headers);
+ // regular expression to find the <title> tag
+ let match = text.match(/<title.*>([^<]*)<\/title>/);
+
+ const title = match?.[1] || "";
+
+ return { title, headers };
} else {
return { title: "", headers: null };
}
@@ -64,12 +72,3 @@ export default async function fetchTitleAndHeaders(url: string, content: string
return { title: "", headers: null };
}
}
-
-export async function fetchTitleAndHeadersFromContent(content: string, headers: Headers) {
- // regular expression to find the <title> tag
- let match = content.match(/<title.*>([^<]*)<\/title>/);
-
- const title = match?.[1] || "";
-
- return { title, headers };
-}
\ No newline at end of file
diff --git a/apps/web/pages/api/v1/archives/index.ts b/apps/web/pages/api/v1/archives/index.ts
index ba00cd93..e18f21c5 100644
--- a/apps/web/pages/api/v1/archives/index.ts
+++ b/apps/web/pages/api/v1/archives/index.ts
@@ -153,7 +153,12 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse) {
const isImage = mimetype?.includes("image");
const isHTML = mimetype === "text/html";
- const { title = "" } = url ? await fetchTitleAndHeaders(url, isHTML && !isPreview ? fileBuffer.toString("utf-8") : null) : {};
+ const { title = "" } = url
+ ? await fetchTitleAndHeaders(
+ url,
+ isHTML && !isPreview ? fileBuffer.toString("utf-8") : undefined
+ )
+ : {};
const link = await prisma.link.create({
data: {