From a7facd6e825e3a2d60752df0b8526482b19a12de Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Wed, 23 Mar 2022 14:40:25 -0400 Subject: Added support for custom backgrounds --- webAO/utils/tryUrls.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 webAO/utils/tryUrls.js (limited to 'webAO/utils') diff --git a/webAO/utils/tryUrls.js b/webAO/utils/tryUrls.js new file mode 100644 index 0000000..db07ec7 --- /dev/null +++ b/webAO/utils/tryUrls.js @@ -0,0 +1,20 @@ +import fileExists from './fileExists' +import transparentPng from '../constants/transparentPng' +const urlExtensionsToTry = [ + '.png', + '.gif', + '.webp', + '.apng' +] +const tryUrls = async (url) => { + for (let i = 0; i < urlExtensionsToTry.length; i++) { + const extension = urlExtensionsToTry[i] + const fullFileUrl = url + extension + const exists = await fileExists(fullFileUrl); + if (exists) { + return fullFileUrl + } + } + return transparentPng +} +export default tryUrls \ No newline at end of file -- cgit From 63410fd71e31e0de21aed41016983146405e2e9d Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 23 Mar 2022 21:52:13 +0100 Subject: ao host is a string --- webAO/utils/aoml.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webAO/utils') diff --git a/webAO/utils/aoml.ts b/webAO/utils/aoml.ts index da66d0c..154274d 100644 --- a/webAO/utils/aoml.ts +++ b/webAO/utils/aoml.ts @@ -32,7 +32,7 @@ const aomlParser = (text: string) => { return parsed } -const mlConfig = (AO_HOST) => { +const mlConfig = (AO_HOST: string) => { const defaultUrl = `${AO_HOST}themes/default/chat_config.ini` let aomlParsed: Promise<{[key: string]: Aoml}> = request(defaultUrl).then((data) => aomlParser(data)); -- cgit From b2000f04663092f7a4dfcbab306d67df7e5ce538 Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Thu, 24 Mar 2022 00:22:33 -0400 Subject: Added support for issue with aomlParser --- webAO/utils/aoml.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'webAO/utils') diff --git a/webAO/utils/aoml.ts b/webAO/utils/aoml.ts index 154274d..c355edf 100644 --- a/webAO/utils/aoml.ts +++ b/webAO/utils/aoml.ts @@ -1,6 +1,7 @@ import request from "../services/request" interface Aoml { + [key: string]: any | number, name: string; start: string; end: string; -- cgit From cb5117e66c7789db728e80a0b47c2011a46bd6e0 Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Thu, 24 Mar 2022 00:26:33 -0400 Subject: Change any to string --- webAO/utils/aoml.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webAO/utils') diff --git a/webAO/utils/aoml.ts b/webAO/utils/aoml.ts index c355edf..fbdee21 100644 --- a/webAO/utils/aoml.ts +++ b/webAO/utils/aoml.ts @@ -1,7 +1,7 @@ import request from "../services/request" interface Aoml { - [key: string]: any | number, + [key: string]: string | number, name: string; start: string; end: string; -- cgit From 08916f6d4eb8db40e6e54f78c744071f3b5298d7 Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Thu, 24 Mar 2022 00:42:24 -0400 Subject: Adding typescript support and unit tests --- webAO/utils/__tests__/tryUrls.test.ts | 31 +++++++++++++++++++++++++++++++ webAO/utils/tryUrls.js | 20 -------------------- webAO/utils/tryUrls.ts | 20 ++++++++++++++++++++ 3 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 webAO/utils/__tests__/tryUrls.test.ts delete mode 100644 webAO/utils/tryUrls.js create mode 100644 webAO/utils/tryUrls.ts (limited to 'webAO/utils') diff --git a/webAO/utils/__tests__/tryUrls.test.ts b/webAO/utils/__tests__/tryUrls.test.ts new file mode 100644 index 0000000..444664e --- /dev/null +++ b/webAO/utils/__tests__/tryUrls.test.ts @@ -0,0 +1,31 @@ +import fileExists from '../fileExists' +import tryUrls from '../tryUrls'; +import transparentPng from '../../constants/transparentPng' +jest.mock('../fileExists') + +const mockFileExists = fileExists as jest.MockedFunction; + +describe('tryUrls', () => { + it('Should try multiple file extensions', async () => { + const url = "localhost/stoneddiscord/assets" + mockFileExists + .mockReturnValueOnce(Promise.resolve(false)) + .mockReturnValueOnce(Promise.resolve(false)) + .mockReturnValueOnce(Promise.resolve(false)) + .mockReturnValueOnce(Promise.resolve(true)) + const actual = await tryUrls(url) + const expected = 'localhost/stoneddiscord/assets.apng' + expect(actual).toBe(expected); + }); + + it('Should return a transparent png if it cant find any assets', async () => { + const url = "localhost/stoneddiscord/assets" + mockFileExists + .mockReturnValue(Promise.resolve(false)) + const actual = await tryUrls(url) + const expected = transparentPng + expect(actual).toBe(expected); + }); +}) + + diff --git a/webAO/utils/tryUrls.js b/webAO/utils/tryUrls.js deleted file mode 100644 index db07ec7..0000000 --- a/webAO/utils/tryUrls.js +++ /dev/null @@ -1,20 +0,0 @@ -import fileExists from './fileExists' -import transparentPng from '../constants/transparentPng' -const urlExtensionsToTry = [ - '.png', - '.gif', - '.webp', - '.apng' -] -const tryUrls = async (url) => { - for (let i = 0; i < urlExtensionsToTry.length; i++) { - const extension = urlExtensionsToTry[i] - const fullFileUrl = url + extension - const exists = await fileExists(fullFileUrl); - if (exists) { - return fullFileUrl - } - } - return transparentPng -} -export default tryUrls \ No newline at end of file diff --git a/webAO/utils/tryUrls.ts b/webAO/utils/tryUrls.ts new file mode 100644 index 0000000..14ef885 --- /dev/null +++ b/webAO/utils/tryUrls.ts @@ -0,0 +1,20 @@ +import fileExists from './fileExists' +import transparentPng from '../constants/transparentPng' +const urlExtensionsToTry = [ + '.png', + '.gif', + '.webp', + '.apng' +] +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); + if (exists) { + return fullFileUrl + } + } + return transparentPng +} +export default tryUrls \ No newline at end of file -- cgit