From fb7409947cf022c864fdbb07be6c2ba6cba296c1 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Sun, 3 Sep 2023 13:41:45 +1000 Subject: Fix bug in embed handler where getMeta would not return undefined --- src/api/util/utility/EmbedHandlers.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/api/util/utility/EmbedHandlers.ts b/src/api/util/utility/EmbedHandlers.ts index e8f39407..af01a32f 100644 --- a/src/api/util/utility/EmbedHandlers.ts +++ b/src/api/util/utility/EmbedHandlers.ts @@ -78,7 +78,8 @@ export const getProxyUrl = ( const getMeta = ($: cheerio.CheerioAPI, name: string): string | undefined => { let elem = $(`meta[property="${name}"]`); if (!elem.length) elem = $(`meta[name="${name}"]`); - return elem.attr("content") || elem.text(); + const ret = elem.attr("content") || elem.text(); + return ret.trim().length == 0 ? undefined : ret; }; export const getMetaDescriptions = (text: string) => { @@ -168,7 +169,8 @@ export const EmbedHandlers: { const response = await doFetch(url); if (!response) return null; - const metas = getMetaDescriptions(await response.text()); + const text = await response.text(); + const metas = getMetaDescriptions(text); // TODO: handle video @@ -189,7 +191,7 @@ export const EmbedHandlers: { if (metas.type == "object") embedType = EmbedType.article; // github if (metas.type == "rich") embedType = EmbedType.rich; - if (metas.width < 400) embedType = EmbedType.link; + if (metas.width && metas.width < 400) embedType = EmbedType.link; return { url: url.href, -- cgit 1.4.1