From eb636568643e892491fd925f7a92fc3feba6a67e Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Fri, 11 Sep 2020 21:06:31 +0200 Subject: viewer: config.json url parameter + index.json configuration github: resolves #160 --- example/config.json | 1 + viewer/src/@types/gallery.d.ts | 3 ++- viewer/src/store/galleryStore.ts | 11 +++++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/example/config.json b/example/config.json index 5827d25..b66bfcd 100644 --- a/example/config.json +++ b/example/config.json @@ -1,4 +1,5 @@ { "galleryRoot": "out/", + "galleryIndex": "index.json", "initialTagDisplayLimit": 10 } diff --git a/viewer/src/@types/gallery.d.ts b/viewer/src/@types/gallery.d.ts index 56feff0..b756331 100644 --- a/viewer/src/@types/gallery.d.ts +++ b/viewer/src/@types/gallery.d.ts @@ -20,7 +20,8 @@ declare namespace Gallery { interface Config { galleryRoot: string; - initialTagDisplayLimit: number; + galleryIndex?: string; + initialTagDisplayLimit?: number; } interface GalleryProperties { diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts index 768adb6..b672551 100644 --- a/viewer/src/store/galleryStore.ts +++ b/viewer/src/store/galleryStore.ts @@ -85,7 +85,7 @@ export default class GalleryStore extends VuexModule { // Fetches the gallery's JSON config @action async fetchConfig() { - return fetch(`${process.env.VUE_APP_DATA_URL}config.json`, { cache: "no-cache" }) + return fetch(`${process.env.VUE_APP_DATA_URL}${GalleryStore.getUrlConfig()}`, { cache: "no-cache" }) .then(response => response.json()) .then(this.setConfig); } @@ -93,7 +93,8 @@ export default class GalleryStore extends VuexModule { // Fetches the gallery's JSON metadata @action async fetchGalleryItems() { const root = this.config?.galleryRoot ?? ""; - return fetch(`${process.env.VUE_APP_DATA_URL}${root}index.json`, { cache: "no-cache" }) + const index = this.config?.galleryIndex ?? "index.json"; + return fetch(`${process.env.VUE_APP_DATA_URL}${root}${index}`, { cache: "no-cache" }) .then(response => response.json()) .then(this.setGalleryIndex) .then(this.indexTags) @@ -121,4 +122,10 @@ export default class GalleryStore extends VuexModule { this.setCurrentSearch(results); return results; } + + private static getUrlConfig() { + let search = window.location.search; + if (search.length > 1) return search.substr(1) + ".json"; + return "config.json"; + } } -- cgit v1.2.3