mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-04-29 02:37:27 +09:00
なんかめっちゃ変えた
This commit is contained in:
parent
67909d360d
commit
7902ded327
122
.eslintrc.cjs
Normal file
122
.eslintrc.cjs
Normal file
@ -0,0 +1,122 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
tsconfigRootDir: __dirname,
|
||||
project: ['./tsconfig.json'],
|
||||
},
|
||||
plugins: [
|
||||
'@typescript-eslint',
|
||||
'import'
|
||||
],
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:import/recommended',
|
||||
'plugin:import/typescript'
|
||||
],
|
||||
rules: {
|
||||
'indent': ['warn', 'tab', {
|
||||
'SwitchCase': 1,
|
||||
'MemberExpression': 1,
|
||||
'flatTernaryExpressions': true,
|
||||
'ArrayExpression': 'first',
|
||||
'ObjectExpression': 'first',
|
||||
}],
|
||||
'eol-last': ['error', 'always'],
|
||||
'semi': ['error', 'always'],
|
||||
'semi-spacing': ['error', { 'before': false, 'after': true }],
|
||||
'quotes': ['warn', 'single'],
|
||||
'comma-dangle': ['warn', 'always-multiline'],
|
||||
'comma-spacing': ['error', { 'before': false, 'after': true }],
|
||||
'array-bracket-spacing': ['error', 'never'],
|
||||
'keyword-spacing': ['error', {
|
||||
'before': true,
|
||||
'after': true,
|
||||
}],
|
||||
'key-spacing': ['error', {
|
||||
'beforeColon': false,
|
||||
'afterColon': true,
|
||||
}],
|
||||
'arrow-spacing': ['error', {
|
||||
'before': true,
|
||||
'after': true,
|
||||
}],
|
||||
'brace-style': ['error', '1tbs', {
|
||||
'allowSingleLine': true,
|
||||
}],
|
||||
'padded-blocks': ['error', 'never'],
|
||||
/* TODO: path aliasを使わないとwarnする
|
||||
'no-restricted-imports': ['warn', {
|
||||
'patterns': [
|
||||
]
|
||||
}],
|
||||
*/
|
||||
'eqeqeq': ['error', 'always', { 'null': 'ignore' }],
|
||||
'no-multi-spaces': ['error'],
|
||||
'no-var': ['error'],
|
||||
'prefer-arrow-callback': ['error'],
|
||||
'no-throw-literal': ['error'],
|
||||
'no-param-reassign': ['warn'],
|
||||
'no-constant-condition': ['warn'],
|
||||
'no-empty-pattern': ['warn'],
|
||||
'no-async-promise-executor': ['off'],
|
||||
'no-useless-escape': ['off'],
|
||||
'no-multiple-empty-lines': ['error', { 'max': 1 }],
|
||||
'no-control-regex': ['warn'],
|
||||
'no-empty': ['warn'],
|
||||
'no-inner-declarations': ['off'],
|
||||
'no-sparse-arrays': ['off'],
|
||||
'nonblock-statement-body-position': ['error', 'beside'],
|
||||
'object-curly-spacing': ['error', 'always'],
|
||||
'space-infix-ops': ['error'],
|
||||
'space-before-blocks': ['error', 'always'],
|
||||
'padding-line-between-statements': [
|
||||
'error',
|
||||
{ 'blankLine': 'always', 'prev': 'function', 'next': '*' },
|
||||
{ 'blankLine': 'always', 'prev': '*', 'next': 'function' },
|
||||
],
|
||||
"lines-between-class-members": "off",
|
||||
/* typescript-eslint では enforce に対応してないっぽい
|
||||
'@typescript-eslint/lines-between-class-members': ['error', {
|
||||
enforce: [{
|
||||
blankLine: 'always',
|
||||
prev: 'method',
|
||||
next: '*',
|
||||
}]
|
||||
}],
|
||||
*/
|
||||
'@typescript-eslint/func-call-spacing': ['error', 'never'],
|
||||
'@typescript-eslint/no-explicit-any': ['warn'],
|
||||
'@typescript-eslint/no-unused-vars': ['warn'],
|
||||
'@typescript-eslint/no-unnecessary-condition': ['warn'],
|
||||
'@typescript-eslint/no-var-requires': ['warn'],
|
||||
'@typescript-eslint/no-inferrable-types': ['warn'],
|
||||
'@typescript-eslint/no-empty-function': ['off'],
|
||||
'@typescript-eslint/no-non-null-assertion': ['warn'],
|
||||
'@typescript-eslint/explicit-function-return-type': ['off'],
|
||||
'@typescript-eslint/no-misused-promises': ['error', {
|
||||
'checksVoidReturn': false,
|
||||
}],
|
||||
'@typescript-eslint/consistent-type-imports': 'off',
|
||||
'@typescript-eslint/prefer-nullish-coalescing': [
|
||||
'warn',
|
||||
],
|
||||
'@typescript-eslint/naming-convention': [
|
||||
'error',
|
||||
{
|
||||
"selector": "typeLike",
|
||||
"format": ["PascalCase"]
|
||||
},
|
||||
{
|
||||
"selector": "typeParameter",
|
||||
"format": []
|
||||
}
|
||||
],
|
||||
'import/no-unresolved': ['off'],
|
||||
'import/no-default-export': ['warn'],
|
||||
'import/order': ['warn', {
|
||||
'groups': ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object', 'type'],
|
||||
}]
|
||||
},
|
||||
};
|
31
.github/workflows/lint.yml
vendored
Normal file
31
.github/workflows/lint.yml
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
name: Test
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [20.10.0]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: 8
|
||||
run_install: false
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
cache: 'pnpm'
|
||||
- name: Install
|
||||
run: |
|
||||
corepack enable
|
||||
pnpm i --frozen-lockfile
|
||||
- name: eslint
|
||||
run: |
|
||||
pnpm eslint
|
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -26,6 +26,8 @@ jobs:
|
||||
run: |
|
||||
corepack enable
|
||||
pnpm i --frozen-lockfile
|
||||
- name: Build
|
||||
run: |
|
||||
pnpm build
|
||||
- name: Test
|
||||
run: |
|
||||
|
@ -5,5 +5,5 @@
|
||||
npm-debug.log
|
||||
gulpfile.js
|
||||
tsconfig.json
|
||||
tslint.json
|
||||
.eslintrc.cjs
|
||||
.editorconfig
|
||||
|
12
CHANGELOG.md
12
CHANGELOG.md
@ -1,7 +1,13 @@
|
||||
4.1.0 / 2023-12-30
|
||||
5.0.0 / 2023-12-30
|
||||
------------------
|
||||
* branch.ioを用いたディープリンク(spotify.link)などでパースに失敗する問題を修正
|
||||
* 'mixi:content-rating'をsensitive判定で見ることで、dlsiteなどでセンシティブ情報を得れるように
|
||||
* support `<link rel="alternate" type="application/activitypub+json" href="{href}">` https://github.com/misskey-dev/summaly/pull/10, https://github.com/misskey-dev/summaly/pull/11
|
||||
* 結果の`activityPub`プロパティでherfの内容を取得できます
|
||||
* branch.ioを用いたディープリンク(spotify.link)などでパースに失敗する問題を修正 https://github.com/misskey-dev/summaly/pull/13
|
||||
* Twitter Cardが読めていない問題を修正 https://github.com/misskey-dev/summaly/pull/15
|
||||
* 'mixi:content-rating'をsensitive判定で見ることで、dlsiteなどでセンシティブ情報を得れるように https://github.com/misskey-dev/summaly/pull/16
|
||||
* sitenameをURLから生成する場合、ポートを含むように (URL.hostname → URL.host)
|
||||
* `Summary`型に`url`プロパティを追加した`SummalyResult`型をexportするように
|
||||
* `IPlugin`インターフェースを`SummalyPlugin`に改称
|
||||
|
||||
4.0.2 / 2023-04-20
|
||||
------------------
|
||||
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016-2019 syuilo
|
||||
Copyright (c) 2016-2024 syuilo
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
34
README.md
34
README.md
@ -41,7 +41,7 @@ npm run build
|
||||
npm run serve
|
||||
```
|
||||
|
||||
### Options
|
||||
#### opts (SummalyOptions)
|
||||
|
||||
| Property | Type | Description | Default |
|
||||
| :------------------ | :--------------------- | :------------------------------ | :------ |
|
||||
@ -53,7 +53,7 @@ npm run serve
|
||||
#### Plugin
|
||||
|
||||
``` typescript
|
||||
interface IPlugin {
|
||||
interface SummalyPlugin {
|
||||
test: (url: URL) => boolean;
|
||||
summarize: (url: URL) => Promise<Summary>;
|
||||
}
|
||||
@ -76,26 +76,31 @@ A Promise of an Object that contains properties below:
|
||||
|
||||
※ Almost all values are nullable. player should not be null.
|
||||
|
||||
#### Root
|
||||
#### SummalyResult
|
||||
|
||||
| Property | Type | Description |
|
||||
| :-------------- | :------- | :------------------------------------------ |
|
||||
| **title** | *string* | The title of the web page |
|
||||
| **icon** | *string* | The url of the icon of the web page |
|
||||
| **description** | *string* | The description of the web page |
|
||||
| **thumbnail** | *string* | The url of the thumbnail of the web page |
|
||||
| **title** | *string* \| *null* | The title of the web page |
|
||||
| **icon** | *string* \| *null* | The url of the icon of the web page |
|
||||
| **description** | *string* \| *null* | The description of the web page |
|
||||
| **thumbnail** | *string* \| *null* | The url of the thumbnail of the web page |
|
||||
| **sitename** | *string* \| *null* | The name of the web site |
|
||||
| **player** | *Player* | The player of the web page |
|
||||
| **sitename** | *string* | The name of the web site |
|
||||
| **sensitive** | *boolean* | Whether the url is sensitive |
|
||||
| **activityPub** | *string* \| *null* | The url of the ActivityPub representation of that web page |
|
||||
| **url** | *string* | The url of the web page |
|
||||
|
||||
#### Summary
|
||||
|
||||
`Omit<SummalyResult, "url">`
|
||||
|
||||
#### 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 |
|
||||
| **url** | *string* \| *null* | The url of the player |
|
||||
| **width** | *number* \| *null* | The width of the player |
|
||||
| **height** | *number* \| *null* | The height of the player |
|
||||
| **allow** | *string[]* | The names of the allowed permissions for iframe |
|
||||
|
||||
Currently the possible items in `allow` are:
|
||||
@ -105,6 +110,7 @@ Currently the possible items in `allow` are:
|
||||
* `fullscreen`
|
||||
* `encrypted-media`
|
||||
* `picture-in-picture`
|
||||
* `web-share`
|
||||
|
||||
See [Permissions Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Permissions_Policy) in MDN for details of them.
|
||||
|
||||
@ -123,7 +129,7 @@ will be ... ↓
|
||||
```json
|
||||
{
|
||||
"title": "【アイドルマスター】「Stage Bye Stage」(歌:島村卯月、渋谷凛、本田未央)",
|
||||
"icon": "https://www.youtube.com/s/desktop/9318de79/img/favicon.ico",
|
||||
"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": {
|
||||
@ -135,11 +141,13 @@ will be ... ↓
|
||||
"clipboard-write",
|
||||
"encrypted-media",
|
||||
"picture-in-picture",
|
||||
"web-share"
|
||||
"web-share",
|
||||
"fullscreen",
|
||||
]
|
||||
},
|
||||
"sitename": "YouTube",
|
||||
"sensitive": false,
|
||||
"activityPub": null,
|
||||
"url": "https://www.youtube.com/watch?v=NMIEAhH_fTU"
|
||||
}
|
||||
```
|
||||
|
@ -16,6 +16,7 @@
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"eslint": "eslint --quiet \"src/**/*.ts\"",
|
||||
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --silent=false --verbose false",
|
||||
"serve": "fastify start ./built/index.js"
|
||||
},
|
||||
@ -27,7 +28,11 @@
|
||||
"@types/debug": "4.1.7",
|
||||
"@types/escape-regexp": "^0.0.1",
|
||||
"@types/node": "20.10.6",
|
||||
"@typescript-eslint/eslint-plugin": "^6.16.0",
|
||||
"@typescript-eslint/parser": "^6.16.0",
|
||||
"debug": "^4.3.4",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-plugin-import": "^2.29.1",
|
||||
"fastify": "^4.25.2",
|
||||
"fastify-cli": "^5.9.0",
|
||||
"jest": "^29.7.0",
|
||||
|
1258
pnpm-lock.yaml
generated
1258
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,12 +1,11 @@
|
||||
import { URL } from 'node:url';
|
||||
import { decode as decodeHtml } from 'html-entities';
|
||||
import * as cheerio from 'cheerio';
|
||||
import clip from './utils/clip.js';
|
||||
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, Player } from './summary.js';
|
||||
import * as cheerio from 'cheerio';
|
||||
|
||||
/**
|
||||
* Contains only the html snippet for a sanitized iframe as the thumbnail is
|
||||
@ -23,7 +22,7 @@ async function getOEmbedPlayer($: cheerio.CheerioAPI, pageUrl: string): Promise<
|
||||
const oEmbedUrl = (() => {
|
||||
try {
|
||||
return new URL(href, pageUrl);
|
||||
} catch { return null }
|
||||
} catch { return null; }
|
||||
})();
|
||||
if (!oEmbedUrl) {
|
||||
return null;
|
||||
@ -51,7 +50,7 @@ async function getOEmbedPlayer($: cheerio.CheerioAPI, pageUrl: string): Promise<
|
||||
}
|
||||
|
||||
const oEmbedHtml = cheerio.load(body.html);
|
||||
const iframe = oEmbedHtml("iframe");
|
||||
const iframe = oEmbedHtml('iframe');
|
||||
|
||||
if (iframe.length !== 1) {
|
||||
// Somehow we either have multiple iframes or none
|
||||
@ -127,8 +126,8 @@ async function getOEmbedPlayer($: cheerio.CheerioAPI, pageUrl: string): Promise<
|
||||
url,
|
||||
width,
|
||||
height,
|
||||
allow: allowedPermissions
|
||||
}
|
||||
allow: allowedPermissions,
|
||||
};
|
||||
}
|
||||
|
||||
export default async (_url: URL | string, lang: string | null = null): Promise<Summary | null> => {
|
||||
@ -203,10 +202,10 @@ export default async (_url: URL | string, lang: string | null = null): Promise<S
|
||||
description = null;
|
||||
}
|
||||
|
||||
let siteName = decodeHtml(
|
||||
const siteName = decodeHtml(
|
||||
$('meta[property="og:site_name"]').attr('content') ||
|
||||
$('meta[name="application-name"]').attr('content') ||
|
||||
url.hostname
|
||||
url.host,
|
||||
);
|
||||
|
||||
const favicon =
|
||||
@ -219,8 +218,7 @@ export default async (_url: URL | string, lang: string | null = null): Promise<S
|
||||
|
||||
// https://developer.mixi.co.jp/connect/mixi_plugin/mixi_check/spec_mixi_check/#toc-18-
|
||||
const sensitive =
|
||||
$("meta[property='mixi:content-rating']").attr('content') == '1' ||
|
||||
$('.tweet').attr('data-possibly-sensitive') === 'true'
|
||||
$('meta[property=\'mixi:content-rating\']').attr('content') === '1';
|
||||
|
||||
const find = async (path: string) => {
|
||||
const target = new URL(path, url.href);
|
||||
@ -234,12 +232,12 @@ export default async (_url: URL | string, lang: string | null = null): Promise<S
|
||||
|
||||
const getIcon = async () => {
|
||||
return (await find(favicon)) || null;
|
||||
}
|
||||
};
|
||||
|
||||
const [icon, oEmbed] = await Promise.all([
|
||||
getIcon(),
|
||||
getOEmbedPlayer($, url.href),
|
||||
])
|
||||
]);
|
||||
|
||||
// Clean up the title
|
||||
title = cleanupTitle(title, siteName);
|
||||
|
31
src/index.ts
31
src/index.ts
@ -1,20 +1,20 @@
|
||||
/**
|
||||
* summaly
|
||||
* https://github.com/syuilo/summaly
|
||||
* https://github.com/misskey-dev/summaly
|
||||
*/
|
||||
|
||||
import { URL } from 'node:url';
|
||||
import tracer from 'trace-redirect';
|
||||
import Summary from './summary.js';
|
||||
import type { IPlugin as _IPlugin } from './iplugin.js';
|
||||
export type IPlugin = _IPlugin;
|
||||
import { SummalyResult } from './summary.js';
|
||||
import { SummalyPlugin } from './iplugin.js';
|
||||
export * from './iplugin.js';
|
||||
import general from './general.js';
|
||||
import * as Got from 'got';
|
||||
import { setAgent } from './utils/got.js';
|
||||
import type { FastifyInstance } from 'fastify';
|
||||
import { plugins as builtinPlugins } from './plugins/index.js';
|
||||
|
||||
type Options = {
|
||||
export type SummalyOptions = {
|
||||
/**
|
||||
* Accept-Language for the request
|
||||
*/
|
||||
@ -28,7 +28,7 @@ type Options = {
|
||||
/**
|
||||
* Custom Plugins
|
||||
*/
|
||||
plugins?: IPlugin[];
|
||||
plugins?: SummalyPlugin[];
|
||||
|
||||
/**
|
||||
* Custom HTTP agent
|
||||
@ -36,26 +36,19 @@ type Options = {
|
||||
agent?: Got.Agents;
|
||||
};
|
||||
|
||||
type Result = Summary & {
|
||||
/**
|
||||
* The actual url of that web page
|
||||
*/
|
||||
url: string;
|
||||
};
|
||||
|
||||
const defaultOptions = {
|
||||
export const summalyDefaultOptions = {
|
||||
lang: null,
|
||||
followRedirects: true,
|
||||
plugins: [],
|
||||
} as Options;
|
||||
} as SummalyOptions;
|
||||
|
||||
/**
|
||||
* Summarize an web page
|
||||
*/
|
||||
export const summaly = async (url: string, options?: Options): Promise<Result> => {
|
||||
export const summaly = async (url: string, options?: SummalyOptions): Promise<SummalyResult> => {
|
||||
if (options?.agent) setAgent(options.agent);
|
||||
|
||||
const opts = Object.assign(defaultOptions, options);
|
||||
const opts = Object.assign(summalyDefaultOptions, options);
|
||||
|
||||
const plugins = builtinPlugins.concat(opts.plugins || []);
|
||||
|
||||
@ -78,7 +71,7 @@ export const summaly = async (url: string, options?: Options): Promise<Result> =
|
||||
const summary = await (match ? match.summarize : general)(_url, opts.lang || undefined);
|
||||
|
||||
if (summary == null) {
|
||||
throw 'failed summarize';
|
||||
throw new Error('failed summarize');
|
||||
}
|
||||
|
||||
return Object.assign(summary, {
|
||||
@ -86,7 +79,7 @@ export const summaly = async (url: string, options?: Options): Promise<Result> =
|
||||
});
|
||||
};
|
||||
|
||||
export default function (fastify: FastifyInstance, options: Options, done: (err?: Error) => void) {
|
||||
export default function (fastify: FastifyInstance, options: SummalyOptions, done: (err?: Error) => void) {
|
||||
fastify.get<{
|
||||
Querystring: {
|
||||
url?: string;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { URL } from 'node:url';
|
||||
import Summary from './summary.js';
|
||||
|
||||
export interface IPlugin {
|
||||
export interface SummalyPlugin {
|
||||
test: (url: URL) => boolean;
|
||||
summarize: (url: URL, lang?: string) => Promise<Summary | null>;
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ export function test(url: URL): boolean {
|
||||
}
|
||||
|
||||
export async function summarize(url: URL, lang: string | null = null): Promise<Summary | null> {
|
||||
|
||||
// https://help.branch.io/using-branch/docs/creating-a-deep-link#redirections
|
||||
// Web版に強制リダイレクトすることでbranch.ioの独自ページが開くのを防ぐ
|
||||
url.searchParams.append('$web_only', 'true');
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { IPlugin } from '@/iplugin.js';
|
||||
import { SummalyPlugin } from '@/iplugin.js';
|
||||
import * as amazon from './amazon.js';
|
||||
import * as wikipedia from './wikipedia.js';
|
||||
import * as branchIoDeeplinks from './branchio-deeplinks.js';
|
||||
|
||||
export const plugins: IPlugin[] = [
|
||||
amazon,
|
||||
wikipedia,
|
||||
branchIoDeeplinks,
|
||||
export const plugins: SummalyPlugin[] = [
|
||||
amazon,
|
||||
wikipedia,
|
||||
branchIoDeeplinks,
|
||||
];
|
||||
|
@ -25,7 +25,7 @@ export async function summarize(url: URL): Promise<summary> {
|
||||
log(body);
|
||||
|
||||
if (!('query' in body) || !('pages' in body.query)) {
|
||||
throw 'fetch failed';
|
||||
throw new Error('fetch failed');
|
||||
}
|
||||
|
||||
const info = body.query.pages[Object.keys(body.query.pages)[0]];
|
||||
|
@ -1,8 +1,8 @@
|
||||
type Summary = {
|
||||
/**
|
||||
* The description of that web page
|
||||
* The title of that web page
|
||||
*/
|
||||
description: string | null;
|
||||
title: string | null;
|
||||
|
||||
/**
|
||||
* The url of the icon of that web page
|
||||
@ -10,25 +10,25 @@ type Summary = {
|
||||
icon: string | null;
|
||||
|
||||
/**
|
||||
* The name of site of that web page
|
||||
* The description of that web page
|
||||
*/
|
||||
sitename: string | null;
|
||||
description: string | null;
|
||||
|
||||
/**
|
||||
* The url of the thumbnail of that web page
|
||||
*/
|
||||
thumbnail: string | null;
|
||||
|
||||
/**
|
||||
* The name of site of that web page
|
||||
*/
|
||||
sitename: string | null;
|
||||
|
||||
/**
|
||||
* The player of that web page
|
||||
*/
|
||||
player: Player;
|
||||
|
||||
/**
|
||||
* The title of that web page
|
||||
*/
|
||||
title: string | null;
|
||||
|
||||
/**
|
||||
* Possibly sensitive
|
||||
*/
|
||||
@ -40,6 +40,13 @@ type Summary = {
|
||||
activityPub: string | null;
|
||||
};
|
||||
|
||||
export type SummalyResult = Summary & {
|
||||
/**
|
||||
* The actual url of that web page
|
||||
*/
|
||||
url: string;
|
||||
};
|
||||
|
||||
export default Summary;
|
||||
|
||||
export type Player = {
|
||||
|
@ -7,6 +7,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>KISS principle</h1>
|
||||
<p>KISS is an acronym for "Keep it simple, stupid" as a design principle noted by the U.S. Navy in 1960.</p>
|
||||
<p>KISS is an acronym for ”Keep it simple, stupid” as a design principle noted by the U.S. Navy in 1960.</p>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,9 +1,13 @@
|
||||
<!doctype html>
|
||||
|
||||
<html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta property="og:site_name" content="Alice's Site">
|
||||
<title>Strawberry Pasta | Alice's Site</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Strawberry Pasta</h1>
|
||||
<p>Strawberry pasta is a kind of pasta with strawberry sauce.</p>
|
||||
</body>
|
||||
</html>
|
||||
|
13
test/htmls/mixi-sensitive.html
Normal file
13
test/htmls/mixi-sensitive.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta property="mixi:content-rating" content="1">
|
||||
<title>SENSITIVE CONTENT!!</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Yo</h1>
|
||||
<p>Hey hey hey syuilo.</p>
|
||||
</body>
|
||||
</html>
|
@ -3,9 +3,10 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>KISS principle</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>KISS principle</h1>
|
||||
<p>KISS is an acronym for "Keep it simple, stupid" as a design principle noted by the U.S. Navy in 1960.</p>
|
||||
<p>KISS is an acronym for ”Keep it simple, stupid” as a design principle noted by the U.S. Navy in 1960.</p>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -46,6 +46,65 @@ afterEach(async () => {
|
||||
|
||||
/* tests below */
|
||||
|
||||
test('basic', async () => {
|
||||
app = fastify();
|
||||
app.get('/', (request, reply) => {
|
||||
return reply.send(fs.createReadStream(_dirname + '/htmls/basic.html'));
|
||||
});
|
||||
await app.listen({ port });
|
||||
expect(await summaly(host)).toEqual({
|
||||
title: 'KISS principle',
|
||||
icon: null,
|
||||
description: null,
|
||||
thumbnail: null,
|
||||
player: {
|
||||
url: null,
|
||||
width: null,
|
||||
height: null,
|
||||
"allow": [
|
||||
"autoplay",
|
||||
"encrypted-media",
|
||||
"fullscreen",
|
||||
],
|
||||
},
|
||||
sitename: 'localhost:3060',
|
||||
sensitive: false,
|
||||
url: host,
|
||||
activityPub: null,
|
||||
});
|
||||
});
|
||||
|
||||
test('Stage Bye Stage', async () => {
|
||||
// If this test fails, you must rewrite the result data and the example in README.md.
|
||||
|
||||
const summary = await summaly('https://www.youtube.com/watch?v=NMIEAhH_fTU');
|
||||
expect(summary).toEqual(
|
||||
{
|
||||
"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"
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test('faviconがHTML上で指定されていないが、ルートに存在する場合、正しく設定される', async () => {
|
||||
app = fastify();
|
||||
app.get('/', (request, reply) => {
|
||||
@ -393,3 +452,23 @@ describe('ActivityPub', () => {
|
||||
expect(summary.activityPub).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sensitive', () => {
|
||||
test('default', async () => {
|
||||
app = fastify();
|
||||
app.get('/', (request, reply) => {
|
||||
return reply.send(fs.createReadStream(_dirname + '/htmls/basic.html'));
|
||||
});
|
||||
await app.listen({ port });
|
||||
expect((await summaly(host)).sensitive).toBe(false);
|
||||
});
|
||||
|
||||
test('mixi:content-rating 1', async () => {
|
||||
app = fastify();
|
||||
app.get('/', (request, reply) => {
|
||||
return reply.send(fs.createReadStream(_dirname + '/htmls/mixi-sensitive.html'));
|
||||
});
|
||||
await app.listen({ port });
|
||||
expect((await summaly(host)).sensitive).toBe(true);
|
||||
});
|
||||
});
|
||||
|
86
tslint.json
86
tslint.json
@ -1,86 +0,0 @@
|
||||
{
|
||||
"rules": {
|
||||
"align": [true,
|
||||
"parameters",
|
||||
"statements"
|
||||
],
|
||||
"ban": false,
|
||||
"class-name": true,
|
||||
"comment-format": [true,
|
||||
"check-upper-case"
|
||||
],
|
||||
"curly": true,
|
||||
"eofline": true,
|
||||
"forin": false,
|
||||
"indent": [true, "tabs"],
|
||||
"interface-name": false,
|
||||
"jsdoc-format": true,
|
||||
"label-position": true,
|
||||
"label-undefined": true,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"member-ordering": [true,
|
||||
"static-before-instance",
|
||||
"variables-before-functions"
|
||||
],
|
||||
"no-any": false,
|
||||
"no-arg": true,
|
||||
"no-bitwise": true,
|
||||
"no-console": [true,
|
||||
"debug",
|
||||
"info",
|
||||
"time",
|
||||
"timeEnd",
|
||||
"trace"
|
||||
],
|
||||
"no-consecutive-blank-lines": true,
|
||||
"no-construct": true,
|
||||
"no-constructor-vars": true,
|
||||
"no-debugger": true,
|
||||
"no-duplicate-key": true,
|
||||
"no-shadowed-variable": false,
|
||||
"no-duplicate-variable": true,
|
||||
"no-empty": true,
|
||||
"no-eval": true,
|
||||
"no-internal-module": true,
|
||||
"no-require-imports": false,
|
||||
"no-string-literal": false,
|
||||
"no-switch-case-fall-through": true,
|
||||
"no-trailing-whitespace": true,
|
||||
"no-unreachable": true,
|
||||
"no-unused-expression": true,
|
||||
"no-unused-variable": true,
|
||||
"no-use-before-declare": true,
|
||||
"no-var-keyword": true,
|
||||
"no-var-requires": false,
|
||||
"one-line": [true,
|
||||
"check-catch",
|
||||
"check-whitespace"
|
||||
],
|
||||
"quotemark": false,
|
||||
"radix": true,
|
||||
"semicolon": true,
|
||||
"switch-default": false,
|
||||
"triple-equals": false,
|
||||
"typedef": [true,
|
||||
"call-signature",
|
||||
"property-declaration"
|
||||
],
|
||||
"typedef-whitespace": [true, {
|
||||
"call-signature": "nospace",
|
||||
"index-signature": "nospace",
|
||||
"parameter": "nospace",
|
||||
"property-declaration": "nospace",
|
||||
"variable-declaration": "nospace"
|
||||
}],
|
||||
"use-strict": false,
|
||||
"variable-name": false,
|
||||
"whitespace": [true,
|
||||
"check-branch",
|
||||
"check-decl",
|
||||
"check-operator",
|
||||
"check-separator",
|
||||
"check-type"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user