From 1ba59be463abe60448b0eb7da157251c393c0590 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 3 Sep 2025 10:29:13 +0200 Subject: bgurls --- webAO/utils/tryBackgroundUrls.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 webAO/utils/tryBackgroundUrls.ts (limited to 'webAO/utils/tryBackgroundUrls.ts') diff --git a/webAO/utils/tryBackgroundUrls.ts b/webAO/utils/tryBackgroundUrls.ts new file mode 100644 index 0000000..154978b --- /dev/null +++ b/webAO/utils/tryBackgroundUrls.ts @@ -0,0 +1,15 @@ +import fileExists from "./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; -- cgit