From 42ca60ff5fa206359383c6aba981780a22413054 Mon Sep 17 00:00:00 2001 From: headshot2017 <> Date: Wed, 22 Nov 2023 20:35:26 -0400 Subject: [PATCH 1/3] check if SFX exists before adding to validUrls --- public/index.html | 9 +++++-- public/index.js | 68 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 61 insertions(+), 16 deletions(-) diff --git a/public/index.html b/public/index.html index 9ff9526..dde02d6 100644 --- a/public/index.html +++ b/public/index.html @@ -25,7 +25,12 @@

WebAO Character Downloader

-

Loading characters...

+
+

Loading characters...

+
+
@@ -86,4 +91,4 @@

WebAO Background Downloader

- \ No newline at end of file + diff --git a/public/index.js b/public/index.js index 980b6aa..08ffd51 100644 --- a/public/index.js +++ b/public/index.js @@ -75,6 +75,36 @@ const getAllCharacterNames = async () => { } return validLinks } +const getAllSfxs = async (url) => { + const response = await fetch(url) + if (response.status === 404) { + return + } + + // Create a fake webpage + const websiteDirectoryPage = await response.text() + const tempPage = document.createElement("html"); + tempPage.innerHTML = websiteDirectoryPage; + + const tags = tempPage.getElementsByTagName('a') + var validLinks = [] + for (const link of tags) { + const aTagValue = link.getAttribute('href') + if (IGNORE_VALUES.has(link.innerHTML) || aTagValue == "music/") { + continue + } + + // Crawl all directories, + if (aTagValue.endsWith('/')) { + const extraLinks = await getAllSfxs(url + aTagValue); + if (extraLinks != null) + validLinks = validLinks.concat(extraLinks); + } else + validLinks.push(decodeURI(aTagValue)); + } + return validLinks +} + const getAllBackgroundNames = async () => { const response = await fetch(`${BASE_BACKGROUND_URL}`) if (response.status === 404) { @@ -122,23 +152,26 @@ export const getCharacterUrls = async () => { // include blip sound, SoundN and frameSFX files await fetch(`${BASE_CHARACTERS_URL}${characterName}/char.ini`).then(resp => resp.blob()).then(blob => blob.text()).then(text => { - const charIni = ini.parse(text.toLowerCase()); + const charIni = ini.parse(text.toLowerCase()); - const blip = (charIni.options.blips != null) ? charIni.options.blips : (charIni.options.gender != null) ? charIni.options.gender : null; - if (blip !== null) - validUrls.push(`${BASE_SOUNDS_URL}` + "blips/" + blip + ".opus"); + const blip = (charIni.options.blips != null) ? charIni.options.blips : (charIni.options.gender != null) ? charIni.options.gender : null; + if (blip !== null && window.sfx.find((element) => element.includes(blip))) + validUrls.push(`${BASE_SOUNDS_URL}` + "blips/" + blip + ".opus"); - for (const key in charIni) { - if (key !== "soundn" && !key.endsWith("_framesfx")) - continue; + for (const key in charIni) { + if (key !== "soundn" && !key.endsWith("_framesfx")) + continue; - for (const value in charIni[key]) { - const sfx = charIni[key][value]; - const sfxUrl = `${BASE_SOUNDS_URL}` + "general/" + sfx + ".opus"; - if (sfx != null && sfx.length > 1 && !validUrls.find((existing) => existing == sfxUrl)) - validUrls.push(sfxUrl); + for (const value in charIni[key]) { + const sfx = charIni[key][value]; + const sfxUrl = `${BASE_SOUNDS_URL}` + "general/" + sfx + ".opus"; + + if (sfx != null && sfx.length > 1 && !validUrls.find((existing) => existing == sfxUrl) && window.sfx.find((element) => element.includes(sfx))) + { + validUrls.push(sfxUrl); + } + } } - } }); await downloadAndZip(characterName, validUrls); @@ -147,11 +180,18 @@ export const getCharacterUrls = async () => { document.getElementById('downloadButton').onclick = getCharacterUrls window.characters = [] +window.sfx = [] const createCharactersForDropdown = async () => { const allCharacterNames = await getAllCharacterNames() const uniqueNames = new Set(allCharacterNames) + document.getElementById('loadingCharactersText').style.display = "none"; + document.getElementById('loadingSfxText').style.display = "block"; + const allSfxNames = await getAllSfxs(`${BASE_SOUNDS_URL}`) + const uniqueSfx = new Set(allSfxNames) + window.characters = Array.from(uniqueNames) + window.sfx = Array.from(uniqueSfx) document.getElementById('loadingContainer').style.display = 'none' document.getElementById('searchCharacter').style.display = "block" } @@ -236,4 +276,4 @@ if(urlParams.has('char')) { document.getElementById('buttonText').style.display = 'none' document.getElementById('buttonLoading').style.display = 'block'; await downloadAndZip(characterName, validUrls); -} \ No newline at end of file +} From 6dd1bde74a40c813556eb5eace2a73080b6af489 Mon Sep 17 00:00:00 2001 From: Headshotnoby <36455681+headshot2017@users.noreply.github.com> Date: Wed, 22 Nov 2023 21:19:06 -0400 Subject: [PATCH 2/3] update the damn page --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1e05423..c0584f4 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,4 @@ To run this locally: ### Creating a production build Running `npm run build` will build the /dist folder which is ready for static content hosting. +. From cf7beec731676036493dfa290b7b73a83fbce145 Mon Sep 17 00:00:00 2001 From: headshot2017 <> Date: Wed, 22 Nov 2023 21:21:04 -0400 Subject: [PATCH 3/3] Revert "update the damn page" This reverts commit 6dd1bde74a40c813556eb5eace2a73080b6af489. --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index c0584f4..1e05423 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,3 @@ To run this locally: ### Creating a production build Running `npm run build` will build the /dist folder which is ready for static content hosting. -.