mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-05-21 13:37:16 +09:00
support width (for size ratio)
This commit is contained in:
parent
1866d9929a
commit
6d182f919e
@ -64,8 +64,12 @@ async function getOEmbedPlayer($: cheerio.CheerioAPI, pageUrl: string): Promise<
|
||||
return null;
|
||||
}
|
||||
|
||||
const height = Math.min(Number(iframe.attr('height') ?? body.height), 1024);
|
||||
if (Number.isNaN(height)) {
|
||||
if (
|
||||
typeof body.width !== 'number' ||
|
||||
body.width <= 0 ||
|
||||
typeof body.height !== 'number' ||
|
||||
body.height <= 0
|
||||
) {
|
||||
// No proper size info
|
||||
return null;
|
||||
}
|
||||
@ -87,8 +91,8 @@ async function getOEmbedPlayer($: cheerio.CheerioAPI, pageUrl: string): Promise<
|
||||
|
||||
return {
|
||||
url,
|
||||
width: null,
|
||||
height,
|
||||
width: body.width,
|
||||
height: body.height,
|
||||
allow: allowedFeatures
|
||||
}
|
||||
}
|
||||
|
@ -262,16 +262,12 @@ describe("oEmbed", () => {
|
||||
});
|
||||
}
|
||||
|
||||
test('src', async () => {
|
||||
test('basic properties', async () => {
|
||||
await setUpFastify('oembed.json');
|
||||
const summary = await summaly(host);
|
||||
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.player.height).toBe(1024);
|
||||
expect(summary.player.width).toBe(500);
|
||||
expect(summary.player.height).toBe(300);
|
||||
});
|
||||
|
||||
test('children are ignored', async () => {
|
||||
|
@ -2,5 +2,6 @@
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
"html": "<div><iframe src='https://example.com/'></iframe>",
|
||||
"width": 500,
|
||||
"height": 300
|
||||
}
|
||||
|
@ -2,5 +2,6 @@
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
"html": "<iframe src='https://example.com/'></iframe><iframe src='https://example.com/'></iframe>",
|
||||
"width": 500,
|
||||
"height": 300
|
||||
}
|
||||
|
@ -2,5 +2,6 @@
|
||||
"version": "11.0",
|
||||
"type": "rich",
|
||||
"html": "<iframe src='https://example.com/'></iframe>",
|
||||
"width": 500,
|
||||
"height": 300
|
||||
}
|
||||
|
@ -2,5 +2,6 @@
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
"html": "<iframe src='http://example.com/'></iframe>",
|
||||
"width": 500,
|
||||
"height": 300
|
||||
}
|
||||
|
@ -2,5 +2,6 @@
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
"html": "<iframe src='https://example.com/'></iframe>",
|
||||
"width": 500,
|
||||
"height": "blobcat"
|
||||
}
|
||||
|
7
test/oembed/invalid/oembed-invalid-width.json
Normal file
7
test/oembed/invalid/oembed-invalid-width.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
"html": "<iframe src='https://example.com/'></iframe>",
|
||||
"width": "blobcat",
|
||||
"height": 300
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
"html": "<iframe src='https://example.com/'></iframe>"
|
||||
"html": "<iframe src='https://example.com/'></iframe>",
|
||||
"width": 500
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"type": "rich",
|
||||
"html": "<iframe src='https://example.com/'></iframe>",
|
||||
"width": 500,
|
||||
"height": 300
|
||||
}
|
||||
|
@ -2,5 +2,5 @@
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
"html": "<iframe src='https://example.com/'></iframe>",
|
||||
"height": 3000
|
||||
"height": 300
|
||||
}
|
@ -2,5 +2,6 @@
|
||||
"version": "0.1",
|
||||
"type": "rich",
|
||||
"html": "<iframe src='https://example.com/'></iframe>",
|
||||
"width": 500,
|
||||
"height": 300
|
||||
}
|
||||
|
@ -2,5 +2,6 @@
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
"html": "<iframe src='https://example.com/' allow='camera'></iframe>",
|
||||
"width": 500,
|
||||
"height": 300
|
||||
}
|
||||
|
@ -2,5 +2,6 @@
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
"html": "<iframe src='https://example.com/' allow='fullscreen;camera'></iframe>",
|
||||
"width": 500,
|
||||
"height": 300
|
||||
}
|
||||
|
@ -2,5 +2,6 @@
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
"html": "<iframe src='https://example.com/' allow='fullscreen'></iframe>",
|
||||
"width": 500,
|
||||
"height": 300
|
||||
}
|
||||
|
@ -2,5 +2,6 @@
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
"html": "<iframe src='https://example.com/' allow='autoplay;clipboard-write;fullscreen;encrypted-media;picture-in-picture'></iframe>",
|
||||
"width": 500,
|
||||
"height": 300
|
||||
}
|
||||
|
@ -2,5 +2,6 @@
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
"html": "<iframe src='https://example.com/'><script>alert('Hahaha I take this world')</script></iframe>",
|
||||
"width": 500,
|
||||
"height": 300
|
||||
}
|
||||
|
@ -2,5 +2,6 @@
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
"html": "<iframe src='https://example.com/'></iframe>",
|
||||
"width": 500,
|
||||
"height": 300
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user