forked from CyberLight/cyxbot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquerier.js
37 lines (31 loc) · 1.05 KB
/
querier.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
const Bluebird = require('bluebird');
const fetch = require('node-fetch');
fetch.Promise = Bluebird;
const reportsQuery = require('./query.graphql');
class Querier {
constructor(config = {}) {
this.config = config;
}
async queryReports(variables) {
const res = await fetch('https://hackerone.com/hacktivity');
const html = await res.text();
const csrfMeta = html.match(/<meta name="csrf-token" content="*[^>]*>/)[0];
const cookie = res.headers.get('set-cookie');
const csrfToken = csrfMeta.match(/content="([^"]*)/)[1];
const params = {
query: reportsQuery,
variables
}
return fetch(this.config.uri, {
headers: {
'Content-Type': 'application/json',
'cookie': cookie,
'x-csrf-token': csrfToken
},
method: 'POST',
body: JSON.stringify(params)
})
.then(res => res.json());
}
}
module.exports = Querier;