This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fetch = require("node-fetch"); | |
const oauthClientUrl = "https://pastebin.com/raw/pS7Z6yyP" | |
const baseUrl = "https://owner-api.teslamotors.com"; | |
function wait(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
async function getHeaders() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function processBodyChunkwiseWithProgress(res, processChunk) { | |
const dummyEventTarget = document.createElement("div"); // why isn't EventTarget constructible? :( | |
const lengthComputable = res.headers.has("Content-Length"); | |
const total = res.headers.get("Content-Length") || 0; | |
let loaded = 0; | |
// Using http://underscorejs.org/#throttle | |
const fireProgressThrottled = _.throttle(fireProgress, 50, { trailing: false }); |