Skip to content

Commit

Permalink
use manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
notcancername committed Jan 31, 2023
1 parent a2c9143 commit a78a7b8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 18 deletions.
8 changes: 5 additions & 3 deletions webAO/client/handleCharacterInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { client } from "../client";
import { safeTags } from "../encoding";
import iniParse from "../iniParse";
import request from "../services/request";
import fileExists from "../utils/fileExists";
import { fileExistsManifest } from "../utils/fileExists";
import { AO_HOST } from "./aoHost";


Expand All @@ -23,7 +23,9 @@ 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 fileExists(fileUrl);
const exists = await fileExistsManifest(client,
AO_HOST,
fileUrl);
if (exists) {
img.alt = chargs[0];
img.title = chargs[0];
Expand Down Expand Up @@ -102,4 +104,4 @@ export const handleCharacterInfo = async (chargs: string[], charid: number) => {
console.warn(`missing charid ${charid}`);
img.style.display = "none";
}
}
}
9 changes: 6 additions & 3 deletions webAO/client/setEmote.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Client from "../client";
import transparentPng from "../constants/transparentPng";
import fileExists from "../utils/fileExists";
import {fileExistsManifest} from "../utils/fileExists";

/**
* Sets all the img tags to the right sources
Expand Down Expand Up @@ -39,13 +39,16 @@ const setEmote = async (
} else if (extension === ".webp.static") {
url = `${characterFolder}${encodeURI(charactername)}/${encodeURI(
emotename
)}.webp`;
)}.webp`;
} else {
url = `${characterFolder}${encodeURI(charactername)}/${encodeURI(
prefix
)}${encodeURI(emotename)}${extension}`;
}
const exists = await fileExists(url);

const exists = await fileExistsManifest(client.manifest,
AO_HOST,
url.slice(AO_HOST.length));
if (exists) {
emoteSelector.src = url;
break;
Expand Down
8 changes: 5 additions & 3 deletions webAO/packets/handlers/handlePV.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { client } from "../../client";
import fileExists from "../../utils/fileExists";
import { fileExistsManifest } from "../../utils/fileExists";
import { updateActionCommands } from '../../dom/updateActionCommands'
import { pickEmotion } from '../../dom/pickEmotion'
import { AO_HOST } from "../../client/aoHost";
Expand Down Expand Up @@ -73,8 +73,10 @@ export const handlePV = async (args: string[]) => {
}

if (
await fileExists(
`${AO_HOST}characters/${encodeURI(me.name.toLowerCase())}/custom.gif`
await fileExistsManifest(
client.manifest,
AO_HOST,
`characters/${encodeURI(me.name.toLowerCase())}/custom.gif`
)
) {
document.getElementById("button_4")!.style.display = "";
Expand Down
8 changes: 6 additions & 2 deletions webAO/utils/getAnimLength.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {client} from '../client'
import {AO_HOST} from '../client/aoHost'
import calculatorHandler from './calculatorHandler';
import fileExists from './fileExists.js';
import {fileExistsManifest} from './fileExists.js';
import { requestBuffer } from '../services/request.js';
/**
* Gets animation length. If the animation cannot be found, it will
Expand All @@ -11,7 +13,9 @@ const getAnimLength = async (url) => {
const extensions = ['.gif', '.webp', '.apng'];
for (const extension of extensions) {
const urlWithExtension = url + extension;
const exists = await fileExists(urlWithExtension);
const exists = await fileExists(client.manifest,
AO_HOST,
urlWithExtension);
if (exists) {
const fileBuffer = await requestBuffer(urlWithExtension);
const length = calculatorHandler[extension](fileBuffer);
Expand Down
10 changes: 7 additions & 3 deletions webAO/utils/tryUrls.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import fileExists from './fileExists'
import {client} from "../client.ts"
import {AO_HOST} from "../client/aoHost.ts"
import {fileExistsManifest} from './fileExists'
import transparentPng from '../constants/transparentPng'
const urlExtensionsToTry = [
'.png',
Expand All @@ -10,11 +12,13 @@ const tryUrls = async (url: string) => {
for (let i = 0; i < urlExtensionsToTry.length; i++) {
const extension = urlExtensionsToTry[i]
const fullFileUrl = url + extension
const exists = await fileExists(fullFileUrl);
const exists = await fileExistsManifest(client.manifest,
AO_HOST,
fullFileUrl);
if (exists) {
return fullFileUrl
}
}
return transparentPng
}
export default tryUrls
export default tryUrls
12 changes: 8 additions & 4 deletions webAO/viewport/utils/setSide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { positions } from '../constants/positions'
import { AO_HOST } from '../../client/aoHost'
import { client } from '../../client'
import tryUrls from '../../utils/tryUrls';
import fileExists from '../../utils/fileExists';
import { fileExistsManifest } from '../../utils/fileExists';

/**
* Changes the viewport background based on a given position.
Expand Down Expand Up @@ -57,10 +57,14 @@ export const set_side = async ({
} else {
court.src = await tryUrls(client.viewport.getBackgroundFolder() + bg);
}


if (showDesk === true && desk) {
const deskFilename = (await fileExists(client.viewport.getBackgroundFolder() + desk.ao2))
const deskFilename = (await fileExistsManifest(
client.manifest,
AO_HOST,
(client.viewport.getBackgroundFolder() +
desk.ao2).slice(AO_HOST.length))
? desk.ao2
: desk.ao1;
bench.src = client.viewport.getBackgroundFolder() + deskFilename;
Expand Down

0 comments on commit a78a7b8

Please sign in to comment.