-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
65 lines (55 loc) · 1.98 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import * as express from 'express';
import * as client from 'cheerio-httpcli';
import * as requestImageSize from 'request-image-size';
const app = express();
app.get("/size", (expressRequest, expressResponse, expressNext) => {
const url = expressRequest.query.url;
client.fetch(url, (err, $, res, body) => {
if (err) {
expressNext(err)
return;
}
requestImageSize(url)
.then(size => {
const result = {
width: size.width,
height: size.height,
};
expressResponse.json(result);
})
.catch(err => console.error(err));
});
})
app.get("/getogp", (expressRequest, expressResponse, expressNext) => {
const url = expressRequest.query.url;
client.fetch(url, (err, $, res, body) => {
if (err) {
expressNext(err)
return;
}
const result = {
exists: false,
title: "",
description: "",
url: "",
image: "",
site_name: "",
type: "",
}
const ogTitleQuery = $("meta[property='og:title']");
if (ogTitleQuery.length > 0) {
result.exists = true;
result.title = $("meta[property='og:title']").attr("content");
result.description = $("meta[property='og:description']").attr("content");
result.url = $("meta[property='og:url']").attr("content");
result.image = $("meta[property='og:image']").attr("content");
result.site_name = $("meta[property='og:site_name']").attr("content");
result.type = $("meta[property='og:type']").attr("content");
} else {
result.title = $("head title").text()
result.description = $("meta[name='description']").attr("content");
}
expressResponse.json(result);
});
})
app.listen(6060, () => console.log('Listening on port 6060'));