From 2fdad915d2d8cfe57bca1a513a888da9f85dd5ab Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sat, 11 Mar 2023 17:52:42 +0100 Subject: [PATCH 1/5] Update README.md --- README.md | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 21c6f3d..6a7c141 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ import { summaly } from 'summaly'; summaly(url[, opts]) ``` -As Fastify plugin: +As Fastify plugin: (will listen `GET` of `/`) ```javascript @@ -64,15 +64,16 @@ A Promise of an Object that contains properties below: #### Root -| Property | Type | Description | -| :-------------- | :------- | :--------------------------------------- | -| **description** | *string* | The description of the web page | -| **icon** | *string* | The url of the icon of the web page | -| **sitename** | *string* | The name of the web site | -| **thumbnail** | *string* | The url of the thumbnail of the web page | -| **player** | *Player* | The player of the web page | -| **title** | *string* | The title of the web page | -| **url** | *string* | The url of the web page | +| Property | Type | Description | +| :-------------- | :------- | :------------------------------------------ | +| **description** | *string* | The description of the web page | +| **icon** | *string* | The url of the icon of the web page | +| **sitename** | *string* | The name of the web site | +| **thumbnail** | *string* | The url of the thumbnail of the web page | +| **oEmbed** | *OEmbedRichIframe* | The oEmbed rich iframe info of the web page | +| **player** | *Player* | The player of the web page | +| **title** | *string* | The title of the web page | +| **url** | *string* | The url of the web page | #### Player @@ -82,6 +83,24 @@ A Promise of an Object that contains properties below: | **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 | +| **allow** | *string[]* | The name of the `allow`ed features for iframe | + +Currently the possible items in `allow` are: + +* `autoplay` +* `clipboard-write` +* `fullscreen` +* `encrypted-media` +* `picture-in-picture` + +See [Permissions Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Permissions_Policy) in MDN for details of them. + ### Example ``` javascript From 61a4a17a02964ef4b7b62ddc54f25cc4d6b8d613 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sat, 11 Mar 2023 17:53:12 +0100 Subject: [PATCH 2/5] permissions --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6a7c141..1ca6c37 100644 --- a/README.md +++ b/README.md @@ -85,11 +85,11 @@ A Promise of an Object that contains properties below: #### oEmbed -| Property | Type | Description | -| :-------------- | :--------- | :-------------------------------------------- | -| **src** | *string* | The source for the iframe | -| **height** | *number* | The height of the iframe | -| **allow** | *string[]* | The name of the `allow`ed features for iframe | +| Property | Type | Description | +| :-------------- | :--------- | :----------------------------------------------- | +| **src** | *string* | The source for the iframe | +| **height** | *number* | The height of the iframe | +| **allow** | *string[]* | The name of the `allow`ed permissions for iframe | Currently the possible items in `allow` are: From 84f96c39614b440bc6bad68392b1e9c669574dd6 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sat, 11 Mar 2023 17:53:30 +0100 Subject: [PATCH 3/5] names --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1ca6c37..63d83e0 100644 --- a/README.md +++ b/README.md @@ -85,11 +85,11 @@ A Promise of an Object that contains properties below: #### oEmbed -| Property | Type | Description | -| :-------------- | :--------- | :----------------------------------------------- | -| **src** | *string* | The source for the iframe | -| **height** | *number* | The height of the iframe | -| **allow** | *string[]* | The name of the `allow`ed permissions for iframe | +| Property | Type | Description | +| :-------------- | :--------- | :---------------------------------------------- | +| **src** | *string* | The source for the iframe | +| **height** | *number* | The height of the iframe | +| **allow** | *string[]* | The names of the allowed permissions for iframe | Currently the possible items in `allow` are: From 4c45ed716e3c1cdc0904ec1d6b008843a414032c Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sat, 11 Mar 2023 20:48:25 +0100 Subject: [PATCH 4/5] =?UTF-8?q?player=E3=82=92=E4=BD=BF=E3=81=86=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 15 ++++----------- src/general.ts | 25 ++++++++++++------------- src/summary.ts | 31 +++++-------------------------- test/index.ts | 24 +++++++++++++----------- 4 files changed, 34 insertions(+), 61 deletions(-) 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([]); }); }); From 5126f71e0ac5efd58793117898477a84501a772e Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sat, 11 Mar 2023 20:50:54 +0100 Subject: [PATCH 5/5] fix type error --- src/plugins/amazon.ts | 4 ++-- src/plugins/wikipedia.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/amazon.ts b/src/plugins/amazon.ts index e553c24..8c708a9 100644 --- a/src/plugins/amazon.ts +++ b/src/plugins/amazon.ts @@ -51,9 +51,9 @@ export async function summarize(url: URL.Url): Promise { 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/src/plugins/wikipedia.ts b/src/plugins/wikipedia.ts index f531108..f7d086e 100644 --- a/src/plugins/wikipedia.ts +++ b/src/plugins/wikipedia.ts @@ -38,9 +38,9 @@ export async function summarize(url: URL.Url): Promise { player: { url: null, width: null, - height: null + height: null, + allow: [], }, sitename: 'Wikipedia', - oEmbed: null, }; }