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
2018-03-29 20:32:18 +09:00

16 lines
435 B
TypeScript

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 {
return url != null
? `https://images.weserv.nl/?url=${url.replace(/^https?:\/\//, '')}`
: null;
}