2018-04-13 00:06:18 +03:00
|
|
|
import * as Koa from 'koa';
|
2016-12-29 00:49:51 +02:00
|
|
|
import summaly from 'summaly';
|
|
|
|
|
2018-04-13 00:06:18 +03:00
|
|
|
module.exports = async (ctx: Koa.Context) => {
|
|
|
|
const summary = await summaly(ctx.query.url);
|
2016-12-29 00:49:51 +02:00
|
|
|
summary.icon = wrap(summary.icon);
|
|
|
|
summary.thumbnail = wrap(summary.thumbnail);
|
2018-04-13 00:06:18 +03:00
|
|
|
ctx.body = summary;
|
2016-12-29 00:49:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function wrap(url: string): string {
|
2017-01-14 03:51:48 +02:00
|
|
|
return url != null
|
|
|
|
? `https://images.weserv.nl/?url=${url.replace(/^https?:\/\//, '')}`
|
|
|
|
: null;
|
2016-12-29 00:49:51 +02:00
|
|
|
}
|