mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-08-02 14:26:42 +09:00
マルチインスタンス対応など (#144)
This commit is contained in:
@ -14,18 +14,18 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/debug": "0.0.30",
|
||||
"@types/express": "4.16.0",
|
||||
"@types/express": "4.17.3",
|
||||
"@types/html-entities": "1.2.16",
|
||||
"@types/mocha": "5.2.2",
|
||||
"@types/node": "10.3.4",
|
||||
"@types/node": "16.4.1",
|
||||
"@types/request": "2.47.1",
|
||||
"@types/request-promise-native": "1.0.15",
|
||||
"express": "4.16.3",
|
||||
"mocha": "5.2.0",
|
||||
"typescript": "2.9.2"
|
||||
"typescript": "4.3.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"cheerio-httpcli": "0.7.4",
|
||||
"cheerio-httpcli": "0.8.2",
|
||||
"debug": "3.1.0",
|
||||
"escape-regexp": "0.0.1",
|
||||
"html-entities": "1.2.1",
|
||||
|
13
src/client.ts
Normal file
13
src/client.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { version } from '../package.json';
|
||||
import * as client from 'cheerio-httpcli';
|
||||
|
||||
client.set('headers', {
|
||||
'User-Agent': `SummalyBot/${version}`
|
||||
});
|
||||
client.set('referer', false);
|
||||
client.set('timeout', 20000);
|
||||
client.set('maxDataSize', 10 * 1024 * 1024);
|
||||
|
||||
export function createInstance() {
|
||||
return client.fork();
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
import { name, version } from '../package.json';
|
||||
import * as URL from 'url';
|
||||
import * as request from 'request';
|
||||
import nullOrEmpty from './utils/null-or-empty';
|
||||
@ -8,21 +7,14 @@ import cleanupTitle from './utils/cleanup-title';
|
||||
import { AllHtmlEntities } from 'html-entities';
|
||||
const entities = new AllHtmlEntities();
|
||||
|
||||
import * as client from 'cheerio-httpcli';
|
||||
|
||||
// 単一インスタンスなのでamazonと値を揃えないといけない
|
||||
client.set('headers', {
|
||||
'User-Agent': `SummalyBot/${version}`
|
||||
});
|
||||
client.set('referer', false);
|
||||
client.set('timeout', 10000);
|
||||
client.set('maxDataSize', 10 * 1024 * 1024);
|
||||
|
||||
import { createInstance } from './client';
|
||||
import Summary from './summary';
|
||||
|
||||
export default async (url: URL.Url, lang: string = null): Promise<Summary> => {
|
||||
if (lang && !lang.match(/^[\w-]+(\s*,\s*[\w-]+)*$/)) lang = null;
|
||||
|
||||
const client = createInstance();
|
||||
|
||||
client.set('headers', {
|
||||
'Accept-Language': lang
|
||||
});
|
||||
|
@ -1,15 +1,7 @@
|
||||
import { name, version } from '../../package.json';
|
||||
import * as URL from 'url';
|
||||
import * as client from 'cheerio-httpcli';
|
||||
import { createInstance } from '../client';
|
||||
import summary from '../summary';
|
||||
|
||||
client.set('headers', {
|
||||
'User-Agent': `SummalyBot/${version}`
|
||||
});
|
||||
client.set('referer', false);
|
||||
client.set('timeout', 10000);
|
||||
client.set('maxDataSize', 10 * 1024 * 1024);
|
||||
|
||||
export function test(url: URL.Url): boolean {
|
||||
return url.hostname === 'www.amazon.com' ||
|
||||
url.hostname === 'www.amazon.co.jp' ||
|
||||
@ -28,6 +20,8 @@ export function test(url: URL.Url): boolean {
|
||||
}
|
||||
|
||||
export async function summarize(url: URL.Url): Promise<summary> {
|
||||
const client = createInstance();
|
||||
|
||||
const res = await client.fetch(url.href);
|
||||
const $ = res.$;
|
||||
|
||||
|
Reference in New Issue
Block a user