aboutsummaryrefslogtreecommitdiff
path: root/webAO/utils/filesExist.ts
diff options
context:
space:
mode:
authorstonedDiscord <Tukz@gmx.de>2023-11-30 02:35:02 +0100
committerGitHub <noreply@github.com>2023-11-30 02:35:02 +0100
commit4435a4014c0a68fc156a29f83e01cbfab4912794 (patch)
tree3c4f6927ae2c515dca1585430aca6cd7f1bf8874 /webAO/utils/filesExist.ts
parent92aa1322f8b086484a74f40619cf60b4b702720c (diff)
parent90ed4b74cac7e8e410175cc3445d7140671e221f (diff)
Merge pull request #205 from Troid-Tech/fix-missing-desks
Fix missing desks
Diffstat (limited to 'webAO/utils/filesExist.ts')
-rw-r--r--webAO/utils/filesExist.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/webAO/utils/filesExist.ts b/webAO/utils/filesExist.ts
new file mode 100644
index 0000000..2f39427
--- /dev/null
+++ b/webAO/utils/filesExist.ts
@@ -0,0 +1,28 @@
+import fileExists from "./fileExists";
+
+/**
+ * This function takes a list of urls and returns the first one that exists.
+ * It checks all the URLs in parallel.
+ * @param urls the list of URLs to check
+ * @returns either the first URL that exists or null if none were found
+ */
+export default async function filesExist(urls: string[]): Promise<string | null> {
+ const promises = urls.map(async (url) => {
+ if (await fileExists(url)) {
+ return url;
+ }
+ return null;
+ });
+
+ // Run all in parallel
+ const results = await Promise.all(promises);
+
+ // Find the first URL that exists (not null) or return null if none exist
+ for (const result of results) {
+ if (result !== null) {
+ return result;
+ }
+ }
+
+ return null; // None of the URLs exist
+}