From 7c5fac67edf4e265176d57b714bd21cdc8c8aa7d Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Fri, 11 Mar 2022 12:58:22 +0100 Subject: move requestbuffer into request and fix preanims --- webAO/client.js | 34 ---------------------------------- webAO/services/request.js | 34 ++++++++++++++++++++++++++++++++++ webAO/utils/getAnimLength.js | 1 + 3 files changed, 35 insertions(+), 34 deletions(-) (limited to 'webAO') diff --git a/webAO/client.js b/webAO/client.js index a0dd895..835d8d2 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -2649,40 +2649,6 @@ export function opusCheck(channel) { } window.opusCheck = opusCheck; -/** - * Make a GET request for a specific URI. - * @param {string} url the URI to be requested - * @returns response data - * @throws {Error} if status code is not 2xx, or a network error occurs - */ -async function requestBuffer(url) { - return new Promise((resolve, reject) => { - const xhr = new XMLHttpRequest(); - xhr.responseType = 'arraybuffer'; - xhr.addEventListener('error', () => { - const err = new Error(`Request for ${url} failed: ${xhr.statusText}`); - err.code = xhr.status; - reject(err); - }); - xhr.addEventListener('abort', () => { - const err = new Error(`Request for ${url} was aborted!`); - err.code = xhr.status; - reject(err); - }); - xhr.addEventListener('load', () => { - if (xhr.status < 200 || xhr.status >= 300) { - const err = new Error(`Request for ${url} failed with status code ${xhr.status}`); - err.code = xhr.status; - reject(err); - } else { - resolve(xhr.response); - } - }); - xhr.open('GET', url, true); - xhr.send(); - }); -} - /** * Triggered when the reconnect button is pushed. */ diff --git a/webAO/services/request.js b/webAO/services/request.js index 6479dcc..5a060fd 100644 --- a/webAO/services/request.js +++ b/webAO/services/request.js @@ -1,3 +1,37 @@ +/** + * Make a GET request for a specific URI. + * @param {string} url the URI to be requested + * @returns response data + * @throws {Error} if status code is not 2xx, or a network error occurs + */ +export async function requestBuffer(url) { + return new Promise((resolve, reject) => { + const xhr = new XMLHttpRequest(); + xhr.responseType = 'arraybuffer'; + xhr.addEventListener('error', () => { + const err = new Error(`Request for ${url} failed: ${xhr.statusText}`); + err.code = xhr.status; + reject(err); + }); + xhr.addEventListener('abort', () => { + const err = new Error(`Request for ${url} was aborted!`); + err.code = xhr.status; + reject(err); + }); + xhr.addEventListener('load', () => { + if (xhr.status < 200 || xhr.status >= 300) { + const err = new Error(`Request for ${url} failed with status code ${xhr.status}`); + err.code = xhr.status; + reject(err); + } else { + resolve(xhr.response); + } + }); + xhr.open('GET', url, true); + xhr.send(); + }); +} + /** * Make a GET request for a specific URI. * @param {string} url the URI to be requested diff --git a/webAO/utils/getAnimLength.js b/webAO/utils/getAnimLength.js index e64703f..5b24e84 100644 --- a/webAO/utils/getAnimLength.js +++ b/webAO/utils/getAnimLength.js @@ -1,5 +1,6 @@ import calculatorHandler from './calculatorHandler'; import fileExists from './fileExists.js'; +import requestBuffer from '../services/request.js'; /** * Gets animation length. If the animation cannot be found, it will * silently fail and return 0 instead. -- cgit