diff --git a/built/general.js b/built/general.js index 0a51385..a973672 100644 --- a/built/general.js +++ b/built/general.js @@ -10,7 +10,7 @@ import * as cheerio from 'cheerio'; * * Width should always be 100%. */ -async function getOEmbedRich($, pageUrl) { +async function getOEmbedPlayer($, pageUrl) { const href = $('link[type="application/json+oembed"]').attr('href'); if (!href) { return null; @@ -24,7 +24,7 @@ async function getOEmbedRich($, pageUrl) { } catch { } })(); - if (!body || body.version !== '1.0' || body.type !== 'rich') { + if (!body || body.version !== '1.0' || !['rich', 'video'].includes(body.type)) { // Not a well formed rich oEmbed return null; } @@ -42,14 +42,13 @@ async function getOEmbedRich($, pageUrl) { // Should only have the body and html elements as the parents return null; } - const src = iframe.attr('src'); - if (!src) { + const url = iframe.attr('src'); + if (!url) { // No src? return null; } // XXX: Use global URL object instead of the deprecated `node:url` - const url = URL.parse(src); - if (url.protocol !== 'https:') { + if (URL.parse(url).protocol !== 'https:') { // Allow only HTTPS for best security return null; } @@ -73,7 +72,8 @@ async function getOEmbedRich($, pageUrl) { return null; } return { - src, + url, + width: null, height, allow: allowedFeatures }; @@ -156,8 +156,7 @@ export default async (url, lang = null) => { }; const [icon, oEmbed] = await Promise.all([ getIcon(), - // playerあるならoEmbedは必要ない - !playerUrl ? getOEmbedRich($, url.href) : null, + getOEmbedPlayer($, url.href), ]); // Clean up the title title = cleanupTitle(title, siteName); @@ -169,13 +168,13 @@ export default async (url, lang = null) => { icon: icon || null, description: description || null, thumbnail: image || null, - player: { + player: oEmbed ?? { url: playerUrl || null, width: Number.isNaN(playerWidth) ? null : playerWidth, - height: Number.isNaN(playerHeight) ? null : playerHeight + height: Number.isNaN(playerHeight) ? null : playerHeight, + allow: ['fullscreen', 'encrypted-media'], }, sitename: siteName || null, sensitive, - oEmbed, }; }; diff --git a/built/plugins/amazon.js b/built/plugins/amazon.js index de2e135..08796d4 100644 --- a/built/plugins/amazon.js +++ b/built/plugins/amazon.js @@ -36,9 +36,9 @@ export async function summarize(url) { player: { url: playerUrl || null, width: playerWidth ? parseInt(playerWidth) : null, - height: playerHeight ? parseInt(playerHeight) : null + height: playerHeight ? parseInt(playerHeight) : null, + allow: playerUrl ? ['fullscreen', 'encrypted-media'] : [], }, sitename: 'Amazon', - oEmbed: null, }; } diff --git a/built/plugins/wikipedia.js b/built/plugins/wikipedia.js index 86b6ea9..4c85dfd 100644 --- a/built/plugins/wikipedia.js +++ b/built/plugins/wikipedia.js @@ -29,9 +29,9 @@ export async function summarize(url) { player: { url: null, width: null, - height: null + height: null, + allow: [], }, sitename: 'Wikipedia', - oEmbed: null, }; } diff --git a/built/summary.d.ts b/built/summary.d.ts index 1054c4f..7a93ca7 100644 --- a/built/summary.d.ts +++ b/built/summary.d.ts @@ -27,10 +27,6 @@ declare type Summary = { * Possibly sensitive */ sensitive?: boolean; - /** - * The iframe information of oEmbed data from that web page - */ - oEmbed: OEmbedRichIframe | null; }; export default Summary; export declare type Player = { @@ -46,22 +42,8 @@ export declare type Player = { * The height of the player */ height: number | null; -}; -/** - * Extracted iframe information from OEmbed html field. - * `width` is omitted here as it should always be 100%. - */ -export declare type OEmbedRichIframe = { /** - * The src of the iframe - */ - src: string; - /** - * The height of the iframe - */ - height: number; - /** - * The allowed feature list of the iframe + * The allowed permissions of the iframe */ allow: string[]; };