Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -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();
}
14 changes: 3 additions & 11 deletions src/general.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
});
Expand Down
12 changes: 3 additions & 9 deletions src/plugins/amazon.ts
Original file line number Diff line number Diff line change
@@ -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' ||
Expand All @@ -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.$;

Expand Down