1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-11-02 16:15:57 +09:00
cherrypick/src/server/web/url-preview.ts

16 lines
401 B
TypeScript
Raw Normal View History

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