Fix bug in embed handler where getMeta would not return undefined
This commit is contained in:
parent
c64a115729
commit
fb7409947c
@ -78,7 +78,8 @@ export const getProxyUrl = (
|
|||||||
const getMeta = ($: cheerio.CheerioAPI, name: string): string | undefined => {
|
const getMeta = ($: cheerio.CheerioAPI, name: string): string | undefined => {
|
||||||
let elem = $(`meta[property="${name}"]`);
|
let elem = $(`meta[property="${name}"]`);
|
||||||
if (!elem.length) elem = $(`meta[name="${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) => {
|
export const getMetaDescriptions = (text: string) => {
|
||||||
@ -168,7 +169,8 @@ export const EmbedHandlers: {
|
|||||||
const response = await doFetch(url);
|
const response = await doFetch(url);
|
||||||
if (!response) return null;
|
if (!response) return null;
|
||||||
|
|
||||||
const metas = getMetaDescriptions(await response.text());
|
const text = await response.text();
|
||||||
|
const metas = getMetaDescriptions(text);
|
||||||
|
|
||||||
// TODO: handle video
|
// TODO: handle video
|
||||||
|
|
||||||
@ -189,7 +191,7 @@ export const EmbedHandlers: {
|
|||||||
if (metas.type == "object") embedType = EmbedType.article; // github
|
if (metas.type == "object") embedType = EmbedType.article; // github
|
||||||
if (metas.type == "rich") embedType = EmbedType.rich;
|
if (metas.type == "rich") embedType = EmbedType.rich;
|
||||||
|
|
||||||
if (metas.width < 400) embedType = EmbedType.link;
|
if (metas.width && metas.width < 400) embedType = EmbedType.link;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url: url.href,
|
url: url.href,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user