From 5d3c7d1e2f6d631646ece755d443f59a76dc8f4f Mon Sep 17 00:00:00 2001 From: S1m Date: Sun, 19 Sep 2021 17:35:28 +0200 Subject: [PATCH 1/3] Allow using external index.json and stickerpack --- web/src/index.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/web/src/index.js b/web/src/index.js index d084b37..0577b1f 100644 --- a/web/src/index.js +++ b/web/src/index.js @@ -21,6 +21,14 @@ import * as frequent from "./frequently-used.js" // The base URL for fetching packs. The app will first fetch ${PACK_BASE_URL}/index.json, // then ${PACK_BASE_URL}/${packFile} for each packFile in the packs object of the index.json file. const PACKS_BASE_URL = "packs" + +let INDEX = `${PACKS_BASE_URL}/index.json`; +let params = new URLSearchParams(document.location.search); +let REMOTE = false; +if (params.has('config')) { + INDEX = params.get("config"); + REMOTE = true; +} // This is updated from packs/index.json let HOMESERVER_URL = "https://matrix-client.matrix.org" @@ -117,7 +125,7 @@ class App extends Component { _loadPacks(disableCache = false) { const cache = disableCache ? "no-cache" : undefined - fetch(`${PACKS_BASE_URL}/index.json`, { cache }).then(async indexRes => { + fetch(INDEX, { cache }).then(async indexRes => { if (indexRes.status >= 400) { this.setState({ loading: false, @@ -129,7 +137,12 @@ class App extends Component { HOMESERVER_URL = indexData.homeserver_url || HOMESERVER_URL // TODO only load pack metadata when scrolled into view? for (const packFile of indexData.packs) { - const packRes = await fetch(`${PACKS_BASE_URL}/${packFile}`, { cache }) + let packRes; + if (REMOTE) { + packRes = await fetch(packFile, { cache }) + } else { + packRes = await fetch(`${PACKS_BASE_URL}/${packFile}`, { cache }) + } const packData = await packRes.json() for (const sticker of packData.stickers) { this.stickersByID.set(sticker.id, sticker) From e0d895f22a2ceb27027f5ed01b270ac9e5dc5a04 Mon Sep 17 00:00:00 2001 From: S1m Date: Mon, 20 Sep 2021 08:58:20 +0200 Subject: [PATCH 2/3] Check packfile protocole scheme + rm semicolons --- web/src/index.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/web/src/index.js b/web/src/index.js index 0577b1f..4d1aa76 100644 --- a/web/src/index.js +++ b/web/src/index.js @@ -22,12 +22,10 @@ import * as frequent from "./frequently-used.js" // then ${PACK_BASE_URL}/${packFile} for each packFile in the packs object of the index.json file. const PACKS_BASE_URL = "packs" -let INDEX = `${PACKS_BASE_URL}/index.json`; -let params = new URLSearchParams(document.location.search); -let REMOTE = false; +let INDEX = `${PACKS_BASE_URL}/index.json` +const params = new URLSearchParams(document.location.search) if (params.has('config')) { - INDEX = params.get("config"); - REMOTE = true; + INDEX = params.get("config") } // This is updated from packs/index.json let HOMESERVER_URL = "https://matrix-client.matrix.org" @@ -137,8 +135,8 @@ class App extends Component { HOMESERVER_URL = indexData.homeserver_url || HOMESERVER_URL // TODO only load pack metadata when scrolled into view? for (const packFile of indexData.packs) { - let packRes; - if (REMOTE) { + let packRes + if (packFile.startsWith("https://") || packFile.startsWith("http://")) { packRes = await fetch(packFile, { cache }) } else { packRes = await fetch(`${PACKS_BASE_URL}/${packFile}`, { cache }) From 7939793351d7f24d8f606da2f31630fa1a102f50 Mon Sep 17 00:00:00 2001 From: S1m Date: Thu, 30 Sep 2021 08:52:41 +0200 Subject: [PATCH 3/3] Remove parseQuery and use params --- web/src/index.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/web/src/index.js b/web/src/index.js index 4d1aa76..38a06b4 100644 --- a/web/src/index.js +++ b/web/src/index.js @@ -36,17 +36,12 @@ const makeThumbnailURL = mxc => `${HOMESERVER_URL}/_matrix/media/r0/thumbnail/${ // This is also used to fix scrolling to sections on Element iOS const isMobileSafari = navigator.userAgent.match(/(iPod|iPhone|iPad)/) && navigator.userAgent.match(/AppleWebKit/) -export const parseQuery = str => Object.fromEntries( - str.split("&") - .map(part => part.split("=")) - .map(([key, value = ""]) => [key, value])) - const supportedThemes = ["light", "dark", "black"] class App extends Component { constructor(props) { super(props) - this.defaultTheme = parseQuery(location.search.substr(1)).theme + this.defaultTheme = params.get("theme") this.state = { packs: [], loading: true,