-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
32 lines (23 loc) · 798 Bytes
/
worker.js
File metadata and controls
32 lines (23 loc) · 798 Bytes
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
const redisConnection = require("./redis-connection");
const axios = require("axios");
var API_KEY = '8547473-192d21ba9cf3dee0267d6a331';
redisConnection.on("getphoto", (data, channel) => {
let username = data.username;
let message = data.message;
let query = data.query;
var URL = "https://pixabay.com/api/?key="+API_KEY+"&q="+encodeURIComponent(query);
async function getData() {
let gistResults = await axios.get(URL)
if (gistResults.data === null) {
setTimeout(getData, 5000);
} else {
console.log(gistResults.data)
await redisConnection.emit(`results-return:${data.channelId}`, {
returndata: gistResults.data,
username:username,
message: message
});
}
}
getData();
});