diff --git a/README.md b/README.md index 63d83e0..aaf9012 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ interface IPlugin { A Promise of an Object that contains properties below: -※ Almost all values are nullable. player shoud not be null. +※ Almost all values are nullable. player should not be null. #### Root @@ -77,18 +77,11 @@ A Promise of an Object that contains properties below: #### Player -| Property | Type | Description | -| :-------------- | :------- | :--------------------------------------- | -| **url** | *string* | The url of the player | -| **width** | *number* | The width of the player | -| **height** | *number* | The height of the player | - -#### oEmbed - | Property | Type | Description | | :-------------- | :--------- | :---------------------------------------------- | -| **src** | *string* | The source for the iframe | -| **height** | *number* | The height of the iframe | +| **url** | *string* | The url of the player | +| **width** | *number* | The width of the player | +| **height** | *number* | The height of the player | | **allow** | *string[]* | The names of the allowed permissions for iframe | Currently the possible items in `allow` are: diff --git a/src/general.ts b/src/general.ts index c352498..495998c 100644 --- a/src/general.ts +++ b/src/general.ts @@ -5,7 +5,7 @@ import cleanupTitle from './utils/cleanup-title.js'; import { decode as decodeHtml } from 'html-entities'; import { get, head, scpaping } from './utils/got.js'; -import type { default as Summary, OEmbedRichIframe } from './summary.js'; +import type { default as Summary, Player } from './summary.js'; import * as cheerio from 'cheerio'; /** @@ -14,7 +14,7 @@ import * as cheerio from 'cheerio'; * * Width should always be 100%. */ -async function getOEmbedRich($: cheerio.CheerioAPI, pageUrl: string): Promise { +async function getOEmbedPlayer($: cheerio.CheerioAPI, pageUrl: string): Promise { const href = $('link[type="application/json+oembed"]').attr('href'); if (!href) { return null; @@ -29,7 +29,7 @@ async function getOEmbedRich($: cheerio.CheerioAPI, pageUrl: string): Promise { const summary = await summaly(host); expect(summary.player.url).toBe('https://example.com/embedurl'); + expect(summary.player.allow).toStrictEqual(['fullscreen', 'encrypted-media']); }); test('Player detection - Pleroma:video => video', async () => { @@ -224,6 +225,7 @@ describe('TwitterCard', () => { const summary = await summaly(host); expect(summary.player.url).toBe('https://example.com/embedurl'); + expect(summary.player.allow).toStrictEqual(['fullscreen', 'encrypted-media']); }); test('Player detection - Pleroma:image => image', async () => { @@ -256,44 +258,44 @@ describe("oEmbed", () => { test(`Invalidity test: ${filename}`, async () => { await setUpFastify(`invalid/${filename}`); const summary = await summaly(host); - expect(summary.oEmbed).toBe(null); + expect(summary.player.url).toBe(null); }); } test('src', async () => { await setUpFastify('oembed.json'); const summary = await summaly(host); - expect(summary.oEmbed?.src).toBe('https://example.com/'); + expect(summary.player.url).toBe('https://example.com/'); }); test('max height', async () => { await setUpFastify('oembed-too-tall.json'); const summary = await summaly(host); - expect(summary.oEmbed?.height).toBe(1024); + expect(summary.player.height).toBe(1024); }); test('children are ignored', async () => { await setUpFastify('oembed-iframe-child.json'); const summary = await summaly(host); - expect(summary.oEmbed?.src).toBe('https://example.com/'); + expect(summary.player.url).toBe('https://example.com/'); }); test('allows fullscreen', async () => { await setUpFastify('oembed-allow-fullscreen.json'); const summary = await summaly(host); - expect(summary.oEmbed?.src).toBe('https://example.com/'); + expect(summary.player.url).toBe('https://example.com/'); }); test('allows safelisted features', async () => { await setUpFastify('oembed-allow-safelisted-features.json'); const summary = await summaly(host); - expect(summary.oEmbed?.src).toBe('https://example.com/'); + expect(summary.player.url).toBe('https://example.com/'); }); test('oEmbed with relative path', async () => { await setUpFastify('oembed.json', 'htmls/oembed-relative.html'); const summary = await summaly(host); - expect(summary.oEmbed?.src).toBe('https://example.com/'); + expect(summary.player.url).toBe('https://example.com/'); }); test('oEmbed with nonexistent path', async () => { @@ -309,21 +311,21 @@ describe("oEmbed", () => { test('oEmbed with OpenGraph', async () => { await setUpFastify('oembed.json', 'htmls/oembed-and-og.html'); const summary = await summaly(host); - expect(summary.oEmbed?.src).toBe('https://example.com/'); + expect(summary.player.url).toBe('https://example.com/'); expect(summary.description).toBe('blobcats rule the world'); }); test('Invalid oEmbed with valid OpenGraph', async () => { await setUpFastify('invalid/oembed-insecure.json', 'htmls/oembed-and-og.html'); const summary = await summaly(host); - expect(summary.oEmbed).toBe(null); + expect(summary.player.url).toBe(null); expect(summary.description).toBe('blobcats rule the world'); }); test('oEmbed with og:video', async () => { await setUpFastify('oembed.json', 'htmls/oembed-and-og-video.html'); const summary = await summaly(host); - expect(summary.oEmbed).toBe(null); - expect(summary.player.url).toBe('https://example.com/embedurl'); + expect(summary.player.url).toBe('https://example.com/'); + expect(summary.player.allow).toStrictEqual([]); }); });