From c56ff5d88db282547a304456892dcacac2b0a490 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 26 Aug 2018 01:56:21 +0900 Subject: [PATCH] Add sunnaly proxy option --- .config/example.yml | 3 +++ src/config/types.ts | 2 ++ src/server/web/url-preview.ts | 11 ++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.config/example.yml b/.config/example.yml index 9ea048f70b..ecb1dd1934 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -138,3 +138,6 @@ drive: # Clustering # clusterLimit: 1 + +# Summaly proxy +# summalyProxy: "http://example.com" diff --git a/src/config/types.ts b/src/config/types.ts index f220e15822..a1dc9a5bd4 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -62,6 +62,8 @@ export type Source = { */ ghost?: string; + summalyProxy?: string; + accesslog?: string; twitter?: { consumer_key: string; diff --git a/src/server/web/url-preview.ts b/src/server/web/url-preview.ts index e96eb309fe..41ca6bad8b 100644 --- a/src/server/web/url-preview.ts +++ b/src/server/web/url-preview.ts @@ -1,11 +1,20 @@ import * as Koa from 'koa'; +import * as request from 'request-promise-native'; import summaly from 'summaly'; +import config from '../../config'; module.exports = async (ctx: Koa.Context) => { try { - const summary = await summaly(ctx.query.url, { + const summary = config.summalyProxy ? await request.get({ + url: config.summalyProxy, + qs: { + url: ctx.query.url + }, + json: true + }) : await summaly(ctx.query.url, { followRedirects: false }); + summary.icon = wrap(summary.icon); summary.thumbnail = wrap(summary.thumbnail);