From 1296cecb0690bbe70c109693625cb424297a0b40 Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Sat, 12 Mar 2022 22:06:52 -0500 Subject: Removing console logs adding function for different char icons --- webAO/utils/calculateApngLength.js | 1 - webAO/utils/fileExists.js | 25 ++++++++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) (limited to 'webAO/utils') diff --git a/webAO/utils/calculateApngLength.js b/webAO/utils/calculateApngLength.js index bc6b3fa..86c2073 100644 --- a/webAO/utils/calculateApngLength.js +++ b/webAO/utils/calculateApngLength.js @@ -12,7 +12,6 @@ const calculateApngLength = (apngFile) => { && d[i + 1] === 0x63 && d[i + 2] === 0x54 && d[i + 3] === 0x4C) { - console.log("found apng header"); // numerator and denominator let delay = ((d[i + 21] / d[i + 23]) * 1000) diff --git a/webAO/utils/fileExists.js b/webAO/utils/fileExists.js index 6d32a1e..3065112 100644 --- a/webAO/utils/fileExists.js +++ b/webAO/utils/fileExists.js @@ -1,8 +1,23 @@ -const fileExists = async (url) => { - const xhr = new XMLHttpRequest(); - xhr.open('HEAD', url, false); - xhr.send(); - return xhr.status === 200; +const fileExists = async (url) => { + return new Promise((resolve, reject) => { + const xhr = new XMLHttpRequest(); + xhr.open('HEAD', url); + xhr.onload = function (e) { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + resolve(true) + } else { + reject(false) + } + } + }; + xhr.onerror = function (e) { + resolve(false) + }; + xhr.send(null); + }) + + }; export default fileExists; -- cgit From 39da04dc796b635b43879d285bc9d2c2aabc8761 Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Sat, 12 Mar 2022 22:07:48 -0500 Subject: Lint --- webAO/utils/calculateApngLength.js | 28 ++++++++++++++-------------- webAO/utils/fileExists.js | 37 ++++++++++++++++--------------------- webAO/utils/getAnimLength.js | 2 +- 3 files changed, 31 insertions(+), 36 deletions(-) (limited to 'webAO/utils') diff --git a/webAO/utils/calculateApngLength.js b/webAO/utils/calculateApngLength.js index 86c2073..932f581 100644 --- a/webAO/utils/calculateApngLength.js +++ b/webAO/utils/calculateApngLength.js @@ -1,25 +1,25 @@ - /** +/** * Adds up the chunk delays to find out how long a APNG is * @param {data} apngFile the APNG data */ const calculateApngLength = (apngFile) => { const d = new Uint8Array(apngFile); - // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk - let duration = 0; - for (var i = 0; i < d.length; i++) { - // Find fcTL header (66 63 54 4C) - if (d[i] === 0x66 + // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk + let duration = 0; + for (let i = 0; i < d.length; i++) { + // Find fcTL header (66 63 54 4C) + if (d[i] === 0x66 && d[i + 1] === 0x63 && d[i + 2] === 0x54 && d[i + 3] === 0x4C) { - // numerator and denominator - let delay = ((d[i + 21] / d[i + 23]) * 1000) + // numerator and denominator + const delay = ((d[i + 21] / d[i + 23]) * 1000); - // minimum is 100ms - duration += delay < 100 ? 100 : delay; - } - } - console.debug(duration); - return duration * 10; + // minimum is 100ms + duration += delay < 100 ? 100 : delay; + } + } + console.debug(duration); + return duration * 10; }; export default calculateApngLength; diff --git a/webAO/utils/fileExists.js b/webAO/utils/fileExists.js index 3065112..13958e0 100644 --- a/webAO/utils/fileExists.js +++ b/webAO/utils/fileExists.js @@ -1,23 +1,18 @@ - -const fileExists = async (url) => { - return new Promise((resolve, reject) => { - const xhr = new XMLHttpRequest(); - xhr.open('HEAD', url); - xhr.onload = function (e) { - if (xhr.readyState === 4) { - if (xhr.status === 200) { - resolve(true) - } else { - reject(false) - } +const fileExists = async (url) => new Promise((resolve, reject) => { + const xhr = new XMLHttpRequest(); + xhr.open('HEAD', url); + xhr.onload = function (e) { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + resolve(true); + } else { + reject(false); } - }; - xhr.onerror = function (e) { - resolve(false) - }; - xhr.send(null); - }) - - -}; + } + }; + xhr.onerror = function (e) { + resolve(false); + }; + xhr.send(null); +}); export default fileExists; diff --git a/webAO/utils/getAnimLength.js b/webAO/utils/getAnimLength.js index 1441548..aa303cf 100644 --- a/webAO/utils/getAnimLength.js +++ b/webAO/utils/getAnimLength.js @@ -1,6 +1,6 @@ import calculatorHandler from './calculatorHandler'; import fileExists from './fileExists.js'; -import {requestBuffer} from '../services/request.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 From af6b6a6d5cbf669024d88146ca5913a0676e4368 Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Sun, 13 Mar 2022 01:29:10 -0500 Subject: Resolve too many network calls --- webAO/utils/fileExists.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webAO/utils') diff --git a/webAO/utils/fileExists.js b/webAO/utils/fileExists.js index 13958e0..7978cbc 100644 --- a/webAO/utils/fileExists.js +++ b/webAO/utils/fileExists.js @@ -6,7 +6,7 @@ const fileExists = async (url) => new Promise((resolve, reject) => { if (xhr.status === 200) { resolve(true); } else { - reject(false); + resolve(false); } } }; -- cgit