jormungandr-bite/src/server/web/url-preview.ts

16 lines
435 B
TypeScript
Raw Normal View History

2016-12-28 15:49:51 -07:00
import * as express from 'express';
import summaly from 'summaly';
module.exports = async (req: express.Request, res: express.Response) => {
const summary = await summaly(req.query.url);
summary.icon = wrap(summary.icon);
summary.thumbnail = wrap(summary.thumbnail);
res.send(summary);
};
function wrap(url: string): string {
2017-01-13 18:51:48 -07:00
return url != null
? `https://images.weserv.nl/?url=${url.replace(/^https?:\/\//, '')}`
: null;
2016-12-28 15:49:51 -07:00
}