diff --git a/client/config/env.js b/client/config/env.js index 6b1a1c81..4b55e7d8 100644 --- a/client/config/env.js +++ b/client/config/env.js @@ -1,7 +1,5 @@ const path = require('path'); -const userConfig = require('../../config'); - // Make sure that including paths.js after env.js will read .env variables. delete require.cache[require.resolve('../../shared/config/paths')]; @@ -26,7 +24,6 @@ process.env.NODE_PATH = (process.env.NODE_PATH || '') function getClientEnvironment() { const raw = { NODE_ENV: process.env.NODE_ENV || 'development', - POLL_INTERVAL: userConfig.torrentClientPollInterval, }; // Stringify all values so we can feed into Webpack DefinePlugin const stringified = { diff --git a/client/src/javascript/actions/AuthActions.ts b/client/src/javascript/actions/AuthActions.ts index 0bed4bc2..45d89c26 100644 --- a/client/src/javascript/actions/AuthActions.ts +++ b/client/src/javascript/actions/AuthActions.ts @@ -14,7 +14,7 @@ import ConfigStore from '../stores/ConfigStore'; import FloodActions from './FloodActions'; import SettingActions from './SettingActions'; -const baseURI = ConfigStore.getBaseURI(); +const {baseURI} = ConfigStore; const AuthActions = { authenticate: (options: AuthAuthenticationOptions) => diff --git a/client/src/javascript/actions/ClientActions.ts b/client/src/javascript/actions/ClientActions.ts index e2108ba4..48f889b0 100644 --- a/client/src/javascript/actions/ClientActions.ts +++ b/client/src/javascript/actions/ClientActions.ts @@ -8,7 +8,7 @@ import ConfigStore from '../stores/ConfigStore'; import SettingStore from '../stores/SettingStore'; import AlertStore from '../stores/AlertStore'; -const baseURI = ConfigStore.getBaseURI(); +const {baseURI} = ConfigStore; const ClientActions = { fetchSettings: async (): Promise => diff --git a/client/src/javascript/actions/FeedActions.ts b/client/src/javascript/actions/FeedActions.ts index ed4b4699..9911c5bb 100644 --- a/client/src/javascript/actions/FeedActions.ts +++ b/client/src/javascript/actions/FeedActions.ts @@ -5,7 +5,7 @@ import type {AddFeedOptions, AddRuleOptions, ModifyFeedOptions} from '@shared/ty import ConfigStore from '../stores/ConfigStore'; import FeedStore from '../stores/FeedStore'; -const baseURI = ConfigStore.getBaseURI(); +const {baseURI} = ConfigStore; const FeedActions = { addFeed: (options: AddFeedOptions) => diff --git a/client/src/javascript/actions/FloodActions.ts b/client/src/javascript/actions/FloodActions.ts index f535bdd6..b8fa54f8 100644 --- a/client/src/javascript/actions/FloodActions.ts +++ b/client/src/javascript/actions/FloodActions.ts @@ -17,7 +17,7 @@ interface ActivityStreamOptions { historySnapshot: HistorySnapshot; } -const baseURI = ConfigStore.getBaseURI(); +const {baseURI} = ConfigStore; let activityStreamEventSource: EventSource | null = null; let lastActivityStreamOptions: ActivityStreamOptions; diff --git a/client/src/javascript/actions/SettingActions.ts b/client/src/javascript/actions/SettingActions.ts index 83c1c396..69a8ba9f 100644 --- a/client/src/javascript/actions/SettingActions.ts +++ b/client/src/javascript/actions/SettingActions.ts @@ -7,7 +7,7 @@ import AlertStore from '../stores/AlertStore'; import ConfigStore from '../stores/ConfigStore'; import SettingStore from '../stores/SettingStore'; -const baseURI = ConfigStore.getBaseURI(); +const {baseURI} = ConfigStore; const SettingActions = { fetchSettings: async (): Promise => diff --git a/client/src/javascript/actions/TorrentActions.ts b/client/src/javascript/actions/TorrentActions.ts index bb0b84d7..3be4c8b2 100644 --- a/client/src/javascript/actions/TorrentActions.ts +++ b/client/src/javascript/actions/TorrentActions.ts @@ -24,7 +24,7 @@ import AlertStore from '../stores/AlertStore'; import ConfigStore from '../stores/ConfigStore'; import UIStore from '../stores/UIStore'; -const baseURI = ConfigStore.getBaseURI(); +const {baseURI} = ConfigStore; const emitTorrentAddedAlert = (count: number) => { AlertStore.add({ diff --git a/client/src/javascript/components/AppWrapper.tsx b/client/src/javascript/components/AppWrapper.tsx index 67bab55a..253285a1 100644 --- a/client/src/javascript/components/AppWrapper.tsx +++ b/client/src/javascript/components/AppWrapper.tsx @@ -22,8 +22,7 @@ const AppWrapper: React.FC = (props: AppWrapperProps) => { overlay = ; } - // TODO: disableUsersAndAuth is server's config not user's - if (AuthStore.isAuthenticated && !ClientStatusStore.isConnected && !ConfigStore.getDisableAuth()) { + if (AuthStore.isAuthenticated && !ClientStatusStore.isConnected && !ConfigStore.disableAuth) { overlay = (
diff --git a/client/src/javascript/components/modals/settings-modal/SettingsModal.tsx b/client/src/javascript/components/modals/settings-modal/SettingsModal.tsx index 26c24e1f..0f4e9004 100644 --- a/client/src/javascript/components/modals/settings-modal/SettingsModal.tsx +++ b/client/src/javascript/components/modals/settings-modal/SettingsModal.tsx @@ -128,8 +128,7 @@ class SettingsModal extends React.Component { // TODO: itemsTree is not regenerated as that would override user's selection. // As a result, percentage of contents of an active torrent is not updated. // this.fetchTorrentContents(); - }, ConfigStore.getPollInterval()); + }, ConfigStore.pollInterval); constructor(props: WrappedComponentProps) { super(props); @@ -53,7 +53,7 @@ class TorrentContents extends React.Component { handleDownloadButtonClick = (hash: string, event: React.MouseEvent): void => { event.preventDefault(); - const baseURI = ConfigStore.getBaseURI(); + const {baseURI} = ConfigStore; const link = document.createElement('a'); const {name} = TorrentStore.torrents[hash] || {}; diff --git a/client/src/javascript/components/modals/torrent-details-modal/TorrentPeers.tsx b/client/src/javascript/components/modals/torrent-details-modal/TorrentPeers.tsx index cb4b1b97..b1b69826 100644 --- a/client/src/javascript/components/modals/torrent-details-modal/TorrentPeers.tsx +++ b/client/src/javascript/components/modals/torrent-details-modal/TorrentPeers.tsx @@ -18,7 +18,7 @@ import UIStore from '../../../stores/UIStore'; @observer class TorrentPeers extends React.Component { peers = observable.array([]); - polling = setInterval(() => this.fetchPeers(), ConfigStore.getPollInterval()); + polling = setInterval(() => this.fetchPeers(), ConfigStore.pollInterval); constructor(props: unknown) { super(props); diff --git a/client/src/javascript/components/sidebar/LogoutButton.tsx b/client/src/javascript/components/sidebar/LogoutButton.tsx index 03fac907..3cfa965d 100644 --- a/client/src/javascript/components/sidebar/LogoutButton.tsx +++ b/client/src/javascript/components/sidebar/LogoutButton.tsx @@ -7,7 +7,7 @@ import Logout from '../icons/Logout'; import Tooltip from '../general/Tooltip'; const LogoutButton = () => { - if (ConfigStore.getDisableAuth()) { + if (ConfigStore.disableAuth) { return null; } diff --git a/client/src/javascript/components/torrent-list/TorrentListContextMenu.tsx b/client/src/javascript/components/torrent-list/TorrentListContextMenu.tsx index 39beb64e..3b5184da 100644 --- a/client/src/javascript/components/torrent-list/TorrentListContextMenu.tsx +++ b/client/src/javascript/components/torrent-list/TorrentListContextMenu.tsx @@ -26,7 +26,7 @@ const handleDetailsClick = (torrent: TorrentProperties): void => { const handleTorrentDownload = (torrent: TorrentProperties, event: React.MouseEvent): void => { event.preventDefault(); - const baseURI = ConfigStore.getBaseURI(); + const {baseURI} = ConfigStore; const link = document.createElement('a'); link.download = torrent.isMultiFile ? `${torrent.name}.tar` : torrent.name; link.href = `${baseURI}api/torrents/${torrent.hash}/contents/all/data`; diff --git a/client/src/javascript/stores/ConfigStore.ts b/client/src/javascript/stores/ConfigStore.ts index 13a06bf6..fd88a8da 100644 --- a/client/src/javascript/stores/ConfigStore.ts +++ b/client/src/javascript/stores/ConfigStore.ts @@ -1,22 +1,17 @@ -let disableUsersAndAuth = false; +import {makeAutoObservable} from 'mobx'; class ConfigStore { - static getBaseURI(): string { - const {pathname} = window.location; - return pathname.substr(0, pathname.lastIndexOf('/') + 1); + baseURI = window.location.pathname.substr(0, window.location.pathname.lastIndexOf('/') + 1); + disableAuth = false; + pollInterval = 2000; + + constructor() { + makeAutoObservable(this); } - static getPollInterval(): number { - return Number(process.env.POLL_INTERVAL) || 5000; - } - - static getDisableAuth(): boolean { - return disableUsersAndAuth; - } - - static setDisableAuth(val: boolean): void { - disableUsersAndAuth = val; + setDisableAuth(val: boolean): void { + this.disableAuth = val; } } -export default ConfigStore; +export default new ConfigStore(); diff --git a/client/src/javascript/util/history.ts b/client/src/javascript/util/history.ts index ea666d5f..8382f453 100644 --- a/client/src/javascript/util/history.ts +++ b/client/src/javascript/util/history.ts @@ -3,6 +3,6 @@ import {createBrowserHistory} from 'history'; import stringUtil from '@shared/util/stringUtil'; import ConfigStore from '../stores/ConfigStore'; -const history = createBrowserHistory({basename: stringUtil.withoutTrailingSlash(ConfigStore.getBaseURI())}); +const history = createBrowserHistory({basename: stringUtil.withoutTrailingSlash(ConfigStore.baseURI)}); export default history;