diff --git a/public/assets/components/breadcrumb.js b/public/assets/components/breadcrumb.js index 11623786..4b59649d 100644 --- a/public/assets/components/breadcrumb.js +++ b/public/assets/components/breadcrumb.js @@ -3,6 +3,7 @@ import { animate, slideYOut, slideYIn, opacityOut } from "../lib/animate.js"; import { forwardURLParams } from "../lib/path.js"; import assert from "../lib/assert.js"; import { settingsSave } from "../lib/store.js"; +import { get as getConfig } from "../model/config.js"; import { loadCSS } from "../helpers/loader.js"; import { extractPath, isDir, isNativeFileUpload } from "../pages/filespage/helper.js"; @@ -79,7 +80,7 @@ class ComponentBreadcrumb extends HTMLElement { // STEP2: setup the actual content assert.type(this.querySelector(`[data-bind="path"]`), HTMLElement).innerHTML = pathChunks.map((chunk, idx) => { - const label = idx === 0 ? (window.CONFIG["name"] || "Filestash") : chunk; + const label = idx === 0 ? getConfig("name", "Filestash") : chunk; const link = pathChunks.slice(0, idx + 1).join("/") + "/"; const limitSize = (word, highlight = false) => { if (highlight === true && word.length > 30) { diff --git a/public/assets/model/config.d.ts b/public/assets/model/config.d.ts new file mode 100644 index 00000000..f86c844f --- /dev/null +++ b/public/assets/model/config.d.ts @@ -0,0 +1,14 @@ +interface Config { + [key: string]: any; + thumbnailer: string[]; +} + +export function init(): Promise; + +export function get(): Config; + +export function get(key: string, defaultValue?: T): T; + +export function getVersion(): string; + +export function query(): any; \ No newline at end of file diff --git a/public/assets/model/config.js b/public/assets/model/config.js index df933d8a..a5819524 100644 --- a/public/assets/model/config.js +++ b/public/assets/model/config.js @@ -9,21 +9,23 @@ const config$ = ajax({ rxjs.map(({ responseJSON }) => responseJSON.result), ); +let CONFIG = {}; + export async function init() { const config = await config$.toPromise(); - window.CONFIG = config; + CONFIG = config; return config; } +export function get(key, defaultValue) { + if (key) return CONFIG[key] || defaultValue; + return CONFIG; +} + +export function getVersion() { + return get("version", "na"); +} + export function query() { return config$; } - -export function get(key) { - if (key) return window.CONFIG[key]; - return window.CONFIG; -} - -export function getVersion() { - return get("version"); -} diff --git a/public/assets/pages/ctrl_logout.js b/public/assets/pages/ctrl_logout.js index 8cab6f13..c6e170bf 100644 --- a/public/assets/pages/ctrl_logout.js +++ b/public/assets/pages/ctrl_logout.js @@ -3,18 +3,16 @@ import { toHref } from "../lib/skeleton/router.js"; import rxjs, { effect } from "../lib/rx.js"; import { deleteSession } from "../model/session.js"; +import { init as setup_config, get as getConfig } from "../model/config.js"; import ctrlError from "./ctrl_error.js"; import $loader from "../components/loader.js"; -import { init as setup_config } from "../model/config.js"; export default function(render) { render($loader); effect(deleteSession().pipe( rxjs.mergeMap(setup_config), - rxjs.tap(() => { - window.CONFIG["logout"] ? location.href = window.CONFIG["logout"] : navigate(toHref("/")); - }), + rxjs.tap(() => getConfig("logout") ? location.href = getConfig("logout") : navigate(toHref("/"))), rxjs.catchError(ctrlError(render)), )); } diff --git a/public/assets/pages/ctrl_viewerpage.js b/public/assets/pages/ctrl_viewerpage.js index 4c9e1bc5..a40cc841 100644 --- a/public/assets/pages/ctrl_viewerpage.js +++ b/public/assets/pages/ctrl_viewerpage.js @@ -3,6 +3,7 @@ import rxjs, { effect } from "../lib/rx.js"; import { ApplicationError } from "../lib/error.js"; import { basename } from "../lib/path.js"; import assert from "../lib/assert.js"; +import { get as getConfig } from "../model/config.js"; import { loadCSS } from "../helpers/loader.js"; import WithShell, { init as initShell } from "../components/decorator_shell_filemanager.js"; import { init as initMenubar } from "./viewerpage/component_menubar.js"; @@ -55,7 +56,7 @@ export default WithShell(async function(render) { render($page); // feature: render viewer application - effect(rxjs.of(window.CONFIG["mime"] || {}).pipe( + effect(rxjs.of(getConfig("mime", {})).pipe( rxjs.map((mimes) => opener(basename(getCurrentPath()), mimes)), rxjs.mergeMap(([opener, opts]) => rxjs.from(loadModule(opener)).pipe(rxjs.tap((module) => { module.default(createRender($page), { ...opts, acl$: options(), getFilename, getDownloadUrl }); @@ -78,7 +79,7 @@ export async function init() { return Promise.all([ loadCSS(import.meta.url, "./ctrl_viewerpage.css"), initShell(), initMenubar(), initCache(), - rxjs.of(window.CONFIG["mime"] || {}).pipe( + rxjs.of(getConfig("mime", {})).pipe( rxjs.map((mimes) => opener(basename(getCurrentPath()), mimes)), rxjs.mergeMap(([opener]) => loadModule(opener)), rxjs.mergeMap((module) => typeof module.init === "function"? module.init() : rxjs.EMPTY), diff --git a/public/assets/pages/filespage/ctrl_submenu.js b/public/assets/pages/filespage/ctrl_submenu.js index fbbffa7e..2f97c823 100644 --- a/public/assets/pages/filespage/ctrl_submenu.js +++ b/public/assets/pages/filespage/ctrl_submenu.js @@ -2,9 +2,10 @@ import { createElement, createRender, createFragment, onDestroy } from "../../li import rxjs, { effect, onClick, preventDefault } from "../../lib/rx.js"; import { animate, slideXIn, slideYIn } from "../../lib/animate.js"; import { basename, forwardURLParams } from "../../lib/path.js"; -import { loadCSS } from "../../helpers/loader.js"; import assert from "../../lib/assert.js"; import { qs, qsa } from "../../lib/dom.js"; +import { get as getConfig } from "../../model/config.js"; +import { loadCSS } from "../../helpers/loader.js"; import t from "../../locales/index.js"; import "../../components/dropdown.js"; @@ -112,7 +113,7 @@ function componentLeft(render, { $scroll }) { -