Skip to content

Commit

Permalink
fixup! use manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
notcancername committed Jan 31, 2023
1 parent a78a7b8 commit e1feede
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 32 deletions.
4 changes: 1 addition & 3 deletions webAO/client/handleCharacterInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 1 addition & 3 deletions webAO/client/setEmote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions webAO/packets/handlers/handlePV.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ export const handlePV = async (args: string[]) => {

if (
await fileExistsManifest(
client.manifest,
AO_HOST,
`characters/${encodeURI(me.name.toLowerCase())}/custom.gif`
)
) {
Expand Down
22 changes: 10 additions & 12 deletions webAO/utils/fileExists.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {AO_HOST} from "../client/aoHost"
import {client} from "../client"
import {canonicalizePath} from "./paths"
import {binarySearch} from "./binarySearch"

Expand All @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions webAO/utils/getAnimLength.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ const getAnimLength = async (url) => {
const extensions = ['.gif', '.webp', '.apng'];
for (const extension of extensions) {
const urlWithExtension = url + extension;
const exists = await fileExists(client.manifest,
AO_HOST,
urlWithExtension);
const exists = await fileExistsManifest(urlWithExtension);
if (exists) {
const fileBuffer = await requestBuffer(urlWithExtension);
const length = calculatorHandler[extension](fileBuffer);
Expand Down
6 changes: 1 addition & 5 deletions webAO/utils/tryUrls.ts
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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
}
Expand Down
6 changes: 2 additions & 4 deletions webAO/viewport/utils/setSide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e1feede

Please sign in to comment.