diff options
| author | stonedDiscord <Tukz@gmx.de> | 2023-11-30 02:35:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-30 02:35:02 +0100 |
| commit | 4435a4014c0a68fc156a29f83e01cbfab4912794 (patch) | |
| tree | 3c4f6927ae2c515dca1585430aca6cd7f1bf8874 /webAO/utils/findImgSrc.ts | |
| parent | 92aa1322f8b086484a74f40619cf60b4b702720c (diff) | |
| parent | 90ed4b74cac7e8e410175cc3445d7140671e221f (diff) | |
Merge pull request #205 from Troid-Tech/fix-missing-desks
Fix missing desks
Diffstat (limited to 'webAO/utils/findImgSrc.ts')
| -rw-r--r-- | webAO/utils/findImgSrc.ts | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/webAO/utils/findImgSrc.ts b/webAO/utils/findImgSrc.ts new file mode 100644 index 0000000..b4db849 --- /dev/null +++ b/webAO/utils/findImgSrc.ts @@ -0,0 +1,19 @@ +import filesExist from "./filesExist"; +import transparentPng from '../constants/transparentPng' + +/** + * This function takes a list of urls and returns the first one that exists. + * If none is found, return a transparent png. + * The function will always return a value that is appriopriate for an img src. + * @param urls The list of urls to try + * @returns The image source of the first url that exists, or a transparent png if none exist + */ +export default async function findImgSrc(urls: string[]): Promise<string> { + return filesExist(urls).then((url) => { + if (url !== null) { + return url; + } + // If none of the images exist, return a transparent png + return transparentPng; + }); +} |
