-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathembeds.js
32 lines (27 loc) · 880 Bytes
/
embeds.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
const http = require('superagent');
const API_KEY = process.env.API_KEY;
const API_PATH = 'https://api.embed.rocks/api/';
const get = async urls => {
const fetchedEmbeds = {};
const promises = urls.map(url => {
const reqUrl = `${API_PATH}?key=${API_KEY}&url=${url}&skip=article`;
console.log(`Making API call to ${reqUrl}`);
return (
http
.get(reqUrl)
.set('Accept', 'application/json')
// ... do this for each request so that the original url is set
// so that if the original url has a redirect, the hashmap still has
// the key of the url requested
.then(res => {
const embed = res.body;
embed.requested_url = url;
fetchedEmbeds[embed.requested_url] = embed;
})
);
});
return Promise.all(promises).then(() => fetchedEmbeds);
};
module.exports = {
get
};