From d32308060388c3ef302f6e8826c9f8f96c514009 Mon Sep 17 00:00:00 2001 From: Lucas <50644934+RandomPerson3465@users.noreply.github.com> Date: Sat, 30 Dec 2023 20:44:09 -0800 Subject: [PATCH] Update index.js Fix issue with headers (empty object as headers causes a cors error when using googleapis) and fix bug where the update interval gets x1000 every time it is loaded. --- top50/index.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/top50/index.js b/top50/index.js index 42f6d01..1f53d50 100644 --- a/top50/index.js +++ b/top50/index.js @@ -1613,13 +1613,22 @@ function apiUpdate(interval) { } function fetchNext(url) { if (data.apiUpdates.method == 'GET') { - fetch(url, { - method: data.apiUpdates.method, - headers: data.apiUpdates.headers - }).then(response => response.json()) + if (Object.keys(data.apiUpdates.headers).filter(x=>x).length) { + fetch(url, { + method: data.apiUpdates.method, + headers: data.apiUpdates.headers, + }).then(response => response.json()) .then(json => { doStuff(json) }) + } else { + fetch(url, { + method: data.apiUpdates.method + }).then(response => response.json()) + .then(json => { + doStuff(json) + }) + } } else { fetch(url, { method: data.apiUpdates.method, @@ -1715,7 +1724,9 @@ function saveAPIUpdates() { let newHeaders = {} for (let i = 0; i < headers.length; i++) { let header = headers[i].split(': ') - newHeaders[header[0]] = header[1] + if (header[1]) { + newHeaders[header[0]] = header[1] + } } data.apiUpdates.headers = newHeaders let body = document.getElementById('body').value.toString().split('; ').join(';\n').split(';\n') @@ -1772,7 +1783,7 @@ function loadAPIUpdates() { document.getElementById('pathImage').value = data.apiUpdates.response.image.path document.getElementById('updateID').checked = data.apiUpdates.response.id.enabled document.getElementById('pathID').value = data.apiUpdates.response.id.path - document.getElementById('apiUpdateInt').value = data.apiUpdates.interval + document.getElementById('apiUpdateInt').value = data.apiUpdates.interval / 1000; document.getElementById('enableApiUpdate').innerHTML = data.apiUpdates.enabled == true ? 'Disable API Updates' : 'Enable API Updates' } loadAPIUpdates()