generalized auth header

This commit is contained in:
Dalton
2018-12-12 20:28:10 -08:00
parent 803617304d
commit e564d2b94d

23
bot.js
View File

@@ -228,9 +228,13 @@ async function loadJson(url, auth) {
let response; let response;
if (auth) { if (auth) {
response = await fetch(url, auth); response = await fetch(url, {
sendToBotTestingChannel('imgur url:' + url); headers: {
sendToBotTestingChannel('imgur auth:' + JSON.stringify(auth)); Authorization: 'Client-ID ' + auth,
credentials: 'same-origin',
Accept: 'application/json'
}
});
} else { } else {
response = await fetch(url); response = await fetch(url);
} }
@@ -254,18 +258,9 @@ async function asyncImageRequest(channelMessage) {
//collect all the json //collect all the json
let image_url_list = []; let image_url_list = [];
let reddit_json = await loadJson("https://www.reddit.com/r/" + requested_item + "/.json?show=all&count=25&limit=100"); let reddit_json = await loadJson("https://www.reddit.com/r/" + requested_item + "/.json?show=all&count=25&limit=100");
let imgur_json = await loadJson( let imgur_json = await loadJson('https://api.imgur.com/3/gallery/r/' + requested_item + '/time/' + getRandomInt(1, 5), auth.imgur);
'https://api.imgur.com/3/gallery/r/' + requested_item + '/time/' + getRandomInt(1, 5),
{
headers: {
Authorization: 'Client-ID ' + auth.imgur,
credentials: 'same-origin',
Accept: 'application/json'
}
}
);
console.log('imgur_json -> ' + JSON.stringify(imgur_json)); //console.log('imgur_json -> ' + JSON.stringify(imgur_json));
// todo need to check config to see if it's a valid booruuuuu // todo need to check config to see if it's a valid booruuuuu
//let redditbooru_json = await loadJson("https://" + requested_item + ".redditbooru.com/images/?limit=1000"); //let redditbooru_json = await loadJson("https://" + requested_item + ".redditbooru.com/images/?limit=1000");