diff options
Diffstat (limited to 'webAO/dom')
| -rw-r--r-- | webAO/dom/updateBackgroundPreview.ts | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/webAO/dom/updateBackgroundPreview.ts b/webAO/dom/updateBackgroundPreview.ts index 61186e0..2b8a18b 100644 --- a/webAO/dom/updateBackgroundPreview.ts +++ b/webAO/dom/updateBackgroundPreview.ts @@ -1,5 +1,20 @@ import { AO_HOST } from "../client/aoHost"; -import tryBackgroundUrls from "../utils/tryBackgroundUrls"; +import fileExists from "../utils/fileExists"; +import transparentPng from "../constants/transparentPng"; + +const urlExtensionsToTry = [".png", ".gif", ".webp", ".apng"]; +const tryBackgroundUrls = 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 tryBackgroundUrls; /** * Update background preview. |
