diff options
| author | caleb.mabry.15@cnu.edu <caleb.mabry.15@cnu.edu> | 2022-03-10 23:21:38 -0500 |
|---|---|---|
| committer | caleb.mabry.15@cnu.edu <caleb.mabry.15@cnu.edu> | 2022-03-10 23:21:38 -0500 |
| commit | dc208478fd18a4e28c0083641bf405170859fc58 (patch) | |
| tree | 1fad0ecbaf5639d02908b5f9c9f31f1878ee446c /webAO/utils/getAnimLength.js | |
| parent | 6dd1b296c2dd1d7462dd8514dff43db59ac8dd19 (diff) | |
Magnum Opus pt1
Diffstat (limited to 'webAO/utils/getAnimLength.js')
| -rw-r--r-- | webAO/utils/getAnimLength.js | 22 |
1 files changed, 22 insertions, 0 deletions
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; |
