diff options
| author | stonedDiscord <Tukz@gmx.de> | 2022-03-11 12:46:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-11 12:46:07 +0100 |
| commit | 4b918084e413933cfc819bd1a1246c6a1ac13e31 (patch) | |
| tree | d01a1ef9c4818336fd82330855e09a74824a5fa7 /webAO/utils/getAnimLength.js | |
| parent | 6dd1b296c2dd1d7462dd8514dff43db59ac8dd19 (diff) | |
| parent | 20424a76b00b303a94921a1b3c5fec6495471f0c (diff) | |
Merge pull request #101 from caleb-mabry/remove-unused-code
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; |
