aboutsummaryrefslogtreecommitdiff
path: root/webAO/utils/tryUrls.ts
diff options
context:
space:
mode:
authorstonedDiscord <Tukz@gmx.de>2022-03-28 23:41:56 +0200
committerstonedDiscord <Tukz@gmx.de>2022-03-28 23:41:56 +0200
commit903a13ff5b5beaaf42b4fcf8965eb55b642e1d2a (patch)
tree7e7cbf09c1ce6d2539bb2f33a9c3c86f19ce9d48 /webAO/utils/tryUrls.ts
parent06ee582c4adefdb35220c63ee4a30444474e9388 (diff)
parentd3911aa9ad6bc16c70355fe11d1377d636b14565 (diff)
Merge branch 'master' into coolloading
Diffstat (limited to 'webAO/utils/tryUrls.ts')
-rw-r--r--webAO/utils/tryUrls.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/webAO/utils/tryUrls.ts b/webAO/utils/tryUrls.ts
new file mode 100644
index 0000000..14ef885
--- /dev/null
+++ b/webAO/utils/tryUrls.ts
@@ -0,0 +1,20 @@
+import fileExists from './fileExists'
+import transparentPng from '../constants/transparentPng'
+const urlExtensionsToTry = [
+ '.png',
+ '.gif',
+ '.webp',
+ '.apng'
+]
+const tryUrls = async (url: string) => {
+ for (let i = 0; i < urlExtensionsToTry.length; i++) {
+ const extension = urlExtensionsToTry[i]
+ const fullFileUrl = url + extension
+ const exists = await fileExists(fullFileUrl);
+ if (exists) {
+ return fullFileUrl
+ }
+ }
+ return transparentPng
+}
+export default tryUrls \ No newline at end of file