From dc208478fd18a4e28c0083641bf405170859fc58 Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Thu, 10 Mar 2022 23:21:38 -0500 Subject: Magnum Opus pt1 --- webAO/utils/getAnimLength.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 webAO/utils/getAnimLength.js (limited to 'webAO/utils/getAnimLength.js') diff --git a/webAO/utils/getAnimLength.js b/webAO/utils/getAnimLength.js new file mode 100644 index 0000000..e64703f --- /dev/null +++ b/webAO/utils/getAnimLength.js @@ -0,0 +1,22 @@ +import calculatorHandler from './calculatorHandler'; +import fileExists from './fileExists.js'; +/** + * Gets animation length. If the animation cannot be found, it will + * silently fail and return 0 instead. + * @param {string} filename the animation file name + */ + +const getAnimLength = async (url) => { + const extensions = ['.gif', '.webp']; + for (const extension of extensions) { + const urlWithExtension = url + extension; + const exists = await fileExists(urlWithExtension); + if (exists) { + const fileBuffer = await requestBuffer(urlWithExtension); + const length = calculatorHandler[extension](fileBuffer); + return length; + } + } + return 0; +}; +export default getAnimLength; -- cgit