diff --git a/webAO/client/handleCharacterInfo.ts b/webAO/client/handleCharacterInfo.ts index 1a403e03..f2d9bfcb 100644 --- a/webAO/client/handleCharacterInfo.ts +++ b/webAO/client/handleCharacterInfo.ts @@ -23,9 +23,7 @@ export const handleCharacterInfo = async (chargs: string[], charid: number) => { )}/char_icon`; for (let i = 0; i < extensions.length; i++) { const fileUrl = charIconBaseUrl + extensions[i]; - const exists = await fileExistsManifest(client, - AO_HOST, - fileUrl); + const exists = await fileExistsManifest(fileUrl); if (exists) { img.alt = chargs[0]; img.title = chargs[0]; diff --git a/webAO/client/setEmote.ts b/webAO/client/setEmote.ts index 62ebf25a..41fe6b51 100644 --- a/webAO/client/setEmote.ts +++ b/webAO/client/setEmote.ts @@ -46,9 +46,7 @@ const setEmote = async ( )}${encodeURI(emotename)}${extension}`; } - const exists = await fileExistsManifest(client.manifest, - AO_HOST, - url.slice(AO_HOST.length)); + const exists = await fileExistsManifest(url); if (exists) { emoteSelector.src = url; break; diff --git a/webAO/packets/handlers/handlePV.ts b/webAO/packets/handlers/handlePV.ts index 32a82a7a..affabbed 100644 --- a/webAO/packets/handlers/handlePV.ts +++ b/webAO/packets/handlers/handlePV.ts @@ -74,8 +74,6 @@ export const handlePV = async (args: string[]) => { if ( await fileExistsManifest( - client.manifest, - AO_HOST, `characters/${encodeURI(me.name.toLowerCase())}/custom.gif` ) ) { diff --git a/webAO/utils/fileExists.js b/webAO/utils/fileExists.js index 2afd4ed8..dab41072 100644 --- a/webAO/utils/fileExists.js +++ b/webAO/utils/fileExists.js @@ -1,3 +1,5 @@ +import {AO_HOST} from "../client/aoHost" +import {client} from "../client" import {canonicalizePath} from "./paths" import {binarySearch} from "./binarySearch" @@ -21,22 +23,18 @@ const fileExists = async (url) => new Promise((resolve, reject) => { export default fileExists; /* Returns whether file exists. - * `manifest' is a sorted array of strings. - * `ao_head' is the base URL. - * `url' is a URL-encoded path. + * `url' is a URL, including the base URL for bw compat. * If manifest is empty, check the old way. * Otherwise, look it up in the manifest */ -const fileExistsManifest = async (manifest, ao_host, url) => +const fileExistsManifest = async (url) => new Promise((resolve, reject) => { + if(client.manifest.length == 0) { + resolve(fileExists(url)); + return; + } + const c_url = encodeURI(canonicalizePath(decodeURI(url.slice(AO_HOST.length)))); - if(manifest == undefined || - manifest == null || - manifest.length == 0) - resolve(fileExists(ao_host + url)); - - const c_url = encodeURI(canonicalizePath(decodeURI(url))); - - if(binarySearch(manifest, c_url) != null) + if(binarySearch(client.manifest, c_url) != null) resolve(true); resolve(false); diff --git a/webAO/utils/tryUrls.ts b/webAO/utils/tryUrls.ts index 7bca6322..1e5107f7 100644 --- a/webAO/utils/tryUrls.ts +++ b/webAO/utils/tryUrls.ts @@ -1,5 +1,3 @@ -import {client} from "../client.ts" -import {AO_HOST} from "../client/aoHost.ts" import {fileExistsManifest} from './fileExists' import transparentPng from '../constants/transparentPng' const urlExtensionsToTry = [ @@ -12,9 +10,7 @@ const tryUrls = async (url: string) => { for (let i = 0; i < urlExtensionsToTry.length; i++) { const extension = urlExtensionsToTry[i] const fullFileUrl = url + extension - const exists = await fileExistsManifest(client.manifest, - AO_HOST, - fullFileUrl); + const exists = await fileExistsManifest(fullFileUrl); if (exists) { return fullFileUrl } diff --git a/webAO/viewport/utils/setSide.ts b/webAO/viewport/utils/setSide.ts index 518b25d4..69018227 100644 --- a/webAO/viewport/utils/setSide.ts +++ b/webAO/viewport/utils/setSide.ts @@ -61,10 +61,8 @@ export const set_side = async ({ if (showDesk === true && desk) { const deskFilename = (await fileExistsManifest( - client.manifest, - AO_HOST, - (client.viewport.getBackgroundFolder() + - desk.ao2).slice(AO_HOST.length)) + (client.viewport.getBackgroundFolder() + + desk.ao2))) ? desk.ao2 : desk.ao1; bench.src = client.viewport.getBackgroundFolder() + deskFilename;