5.1.0 • Published 2 months ago

@misskey-dev/summaly v5.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

summaly

Installation

npm install @misskey-dev/summaly

Usage

As a function:

import { summaly } from 'summaly';

summaly(url[, opts])

As Fastify plugin: (will listen GET of /)

import Summaly from 'summaly';

fastify.register(Summaly[, opts])

Run the server:

git clone https://github.com/misskey-dev/summaly.git
cd summaly
NODE_ENV=development npm install
npm run build
npm run serve

opts (SummalyOptions)

PropertyTypeDescriptionDefault
langstringAccept-Language for the requestnull
followRedirectsbooleanWhether follow redirectstrue
pluginsplugin[] (see below)Custom pluginsnull
agentGot.AgentsCustom HTTP agent (see below)null
userAgentstringUser-Agent for the requestSummalyBot/[version]
responseTimeoutnumberSet timeouts for each phase, such as host name resolution and socket communication.20000
operationTimeoutnumberSet the timeout from the start to the end of the request.60000
contentLengthLimitnumberIf set to true, an error will occur if the content-length value returned from the other server is larger than this parameter (or if the received body size exceeds this parameter).10485760
contentLengthRequiredbooleanIf set to true, it will be an error if the other server does not return content-length.false

Plugin

interface SummalyPlugin {
	test: (url: URL) => boolean;
	summarize: (url: URL) => Promise<Summary>;
}

urls are WHATWG URL since v4.

Custom HTTP agent for proxy

You can specify agents to be passed to Got for proxy use, etc.
https://github.com/sindresorhus/got/blob/v12.6.0/documentation/tips.md#proxying

⚠️If you set some agent, local IP rejecting will not work.⚠️
(Summaly usually rejects local IPs.)

(Summaly currently does not support http2.)

Returns

A Promise of an Object that contains properties below:

※ Almost all values are nullable. player should not be null.

SummalyResult

PropertyTypeDescription
titlestring | nullThe title of the web page
iconstring | nullThe url of the icon of the web page
descriptionstring | nullThe description of the web page
thumbnailstring | nullThe url of the thumbnail of the web page
sitenamestring | nullThe name of the web site
playerPlayerThe player of the web page
sensitivebooleanWhether the url is sensitive
activityPubstring | nullThe url of the ActivityPub representation of that web page
urlstringThe url of the web page

Summary

Omit<SummalyResult, "url">

Player

PropertyTypeDescription
urlstring | nullThe url of the player
widthnumber | nullThe width of the player
heightnumber | nullThe height of the player
allowstring[]The names of the allowed permissions for iframe

Currently the possible items in allow are:

  • autoplay
  • clipboard-write
  • fullscreen
  • encrypted-media
  • picture-in-picture
  • web-share

See Permissions Policy in MDN for details of them.

Example

import { summaly } from 'summaly';

const summary = await summaly('https://www.youtube.com/watch?v=NMIEAhH_fTU');

console.log(summary);

will be ... ↓

{
	"title": "【アイドルマスター】「Stage Bye Stage」(歌:島村卯月、渋谷凛、本田未央)",
	"icon": "https://www.youtube.com/s/desktop/28b0985e/img/favicon.ico",
	"description": "Website▶https://columbia.jp/idolmaster/Playlist▶https://www.youtube.com/playlist?list=PL83A2998CF3BBC86D2018年7月18日発売予定THE IDOLM@STER CINDERELLA GIRLS CG STAR...",
	"thumbnail": "https://i.ytimg.com/vi/NMIEAhH_fTU/maxresdefault.jpg",
	"player": {
		"url": "https://www.youtube.com/embed/NMIEAhH_fTU?feature=oembed",
		"width": 200,
		"height": 113,
		"allow": [
			"autoplay",
			"clipboard-write",
			"encrypted-media",
			"picture-in-picture",
			"web-share",
			"fullscreen",
		]
	},
	"sitename": "YouTube",
	"sensitive": false,
	"activityPub": null,
	"url": "https://www.youtube.com/watch?v=NMIEAhH_fTU"
}

Testing

npm run test

License

MIT