From 76b8a91f7ff22df6137527e1330cbea08af3a793 Mon Sep 17 00:00:00 2001 From: Lev Gorodetskiy Date: Tue, 19 Apr 2022 17:55:39 +0400 Subject: Fold usar transfers --- src/web/src/components/Transfers/TransferGroup.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/Transfers/TransferGroup.js b/src/web/src/components/Transfers/TransferGroup.js index 371f0418..c828829d 100644 --- a/src/web/src/components/Transfers/TransferGroup.js +++ b/src/web/src/components/Transfers/TransferGroup.js @@ -10,6 +10,7 @@ import TransferList from './TransferList'; class TransferGroup extends Component { state = { selections: new Set() } + folded = false onSelectionChange = (directoryName, file, selected) => { const { selections } = this.state; @@ -83,7 +84,11 @@ class TransferGroup extends Component { console.log(error); } } - + + toggleFold = () => { + this.folded = this.folded ? true : false + } + render = () => { const { user, direction } = this.props; @@ -97,8 +102,10 @@ class TransferGroup extends Component { return ( - {user.username} - {user.directories && user.directories + + {(this.folded) ? '↳' : '→'} | {user.username} + + {user.directories && !this.folded && user.directories .map((dir, index) => Date: Tue, 19 Apr 2022 22:33:26 +0400 Subject: Fix folding users --- src/web/src/components/Transfers/TransferGroup.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/Transfers/TransferGroup.js b/src/web/src/components/Transfers/TransferGroup.js index c828829d..baa510c5 100644 --- a/src/web/src/components/Transfers/TransferGroup.js +++ b/src/web/src/components/Transfers/TransferGroup.js @@ -3,14 +3,15 @@ import * as transfers from '../../lib/transfers'; import { Card, - Button + Button, + Icon } from 'semantic-ui-react'; import TransferList from './TransferList'; class TransferGroup extends Component { state = { selections: new Set() } - folded = false + isFolded = false onSelectionChange = (directoryName, file, selected) => { const { selections } = this.state; @@ -85,8 +86,9 @@ class TransferGroup extends Component { } } - toggleFold = () => { - this.folded = this.folded ? true : false + toggleFolded = () => { + console.log('folded:', this.isFolded); + this.isFolded = this.isFolded ? false : true; } render = () => { @@ -102,10 +104,15 @@ class TransferGroup extends Component { return ( - - {(this.folded) ? '↳' : '→'} | {user.username} + + this.toggleFolded()} + /> + {user.username} - {user.directories && !this.folded && user.directories + {user.directories && !this.isFolded && user.directories .map((dir, index) => Date: Tue, 19 Apr 2022 22:44:09 +0400 Subject: Foldable TransferList --- src/web/src/components/Transfers/TransferList.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/web') diff --git a/src/web/src/components/Transfers/TransferList.js b/src/web/src/components/Transfers/TransferList.js index 94b4b050..2cfd3d6d 100644 --- a/src/web/src/components/Transfers/TransferList.js +++ b/src/web/src/components/Transfers/TransferList.js @@ -57,6 +57,8 @@ const formatBytesTransferred = ({ transferred, size }) => { } class TransferList extends Component { + isFolded = false + handleClick = (file) => { const { state, direction } = file; @@ -71,6 +73,11 @@ class TransferList extends Component { } } + toggleFolded = () => { + console.log('folded:', this.isFolded); + this.isFolded = this.isFolded ? false : true; + } + render = () => { const { directoryName, onSelectionChange, files } = this.props; @@ -80,8 +87,14 @@ class TransferList extends Component { size='small' className='filelist-header' > + this.toggleFolded()} + /> {directoryName} + {!this.isFolded && @@ -138,7 +151,7 @@ class TransferList extends Component {
-
+ } ) } -- cgit v1.2.3 From 674cda1bebbe9e135f2844b43c47492c6a527484 Mon Sep 17 00:00:00 2001 From: Lev Gorodetskiy Date: Tue, 19 Apr 2022 23:43:43 +0400 Subject: Use component state --- src/web/src/components/Search/Response.js | 16 +++++++++++++--- src/web/src/components/Transfers/TransferGroup.js | 20 +++++++++++--------- src/web/src/components/Transfers/TransferList.js | 18 ++++++++++-------- 3 files changed, 34 insertions(+), 20 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/Search/Response.js b/src/web/src/components/Search/Response.js index 9b8d0e49..326200ce 100644 --- a/src/web/src/components/Search/Response.js +++ b/src/web/src/components/Search/Response.js @@ -28,7 +28,8 @@ class Response extends Component { state = { tree: buildTree(this.props.response), downloadRequest: undefined, - downloadError: '' + downloadError: '', + isFolded: false } componentDidUpdate = (prevProps) => { @@ -55,11 +56,15 @@ class Response extends Component { }); } + toggleFolded = () => { + this.setState({'isFolded': !this.state.isFolded}); + } + render = () => { let response = this.props.response; let free = response.freeUploadSlots > 0; - let { tree, downloadRequest, downloadError } = this.state; + let { tree, downloadRequest, downloadError, isFolded } = this.state; let selectedFiles = Object.keys(tree) .reduce((list, dict) => list.concat(tree[dict]), []) @@ -71,6 +76,11 @@ class Response extends Component { + this.toggleFolded()} + /> {response.username} Upload Speed: {formatBytes(response.uploadSpeed)}/s, Free Upload Slot: {free ? 'YES' : 'NO'}, Queue Length: {response.queueLength} - {(Object.keys(tree) || []).map((dir, i) => + {(!isFolded && Object.keys(tree) || []).map((dir, i) => { - const { selections } = this.state; + const selections = this.state.selections; const obj = JSON.stringify({ directory: directoryName, filename: file.filename }); selected ? selections.add(obj) : selections.delete(obj); @@ -36,7 +38,7 @@ class TransferGroup extends Component { } removeFileSelection = (file) => { - const { selections } = this.state; + const selections = this.state.selections; const match = Array.from(selections) .map(s => JSON.parse(s)) @@ -87,12 +89,12 @@ class TransferGroup extends Component { } toggleFolded = () => { - console.log('folded:', this.isFolded); - this.isFolded = this.isFolded ? false : true; + this.setState({'isFolded': !this.state.isFolded}); } render = () => { const { user, direction } = this.props; + const isFolded = this.state.isFolded; const selected = this.getSelectedFiles(); const all = selected.length > 1 ? ' Selected' : ''; @@ -106,13 +108,13 @@ class TransferGroup extends Component { this.toggleFolded()} /> {user.username} - {user.directories && !this.isFolded && user.directories + {user.directories && !isFolded && user.directories .map((dir, index) => { } class TransferList extends Component { - isFolded = false - + state = { + isFolded: false + } + handleClick = (file) => { const { state, direction } = file; @@ -74,12 +76,12 @@ class TransferList extends Component { } toggleFolded = () => { - console.log('folded:', this.isFolded); - this.isFolded = this.isFolded ? false : true; + this.setState({'isFolded': !this.state.isFolded}); } render = () => { const { directoryName, onSelectionChange, files } = this.props; + const isFolded = this.state.isFolded; return (
@@ -88,13 +90,13 @@ class TransferList extends Component { className='filelist-header' > this.toggleFolded()} /> {directoryName} - {!this.isFolded && + {!isFolded && -- cgit v1.2.3 From 2de61adb4e89fdbf728de26cd85c8a9020d4231c Mon Sep 17 00:00:00 2001 From: Lev Gorodetskiy Date: Wed, 20 Apr 2022 00:15:11 +0400 Subject: Final touches --- src/web/src/components/Search/Response.js | 7 ------- src/web/src/components/Transfers/TransferList.js | 9 +++++---- 2 files changed, 5 insertions(+), 11 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/Search/Response.js b/src/web/src/components/Search/Response.js index 326200ce..b1b8b871 100644 --- a/src/web/src/components/Search/Response.js +++ b/src/web/src/components/Search/Response.js @@ -83,13 +83,6 @@ class Response extends Component { /> {response.username} - this.props.onHide()} - /> Upload Speed: {formatBytes(response.uploadSpeed)}/s, Free Upload Slot: {free ? 'YES' : 'NO'}, Queue Length: {response.queueLength} diff --git a/src/web/src/components/Transfers/TransferList.js b/src/web/src/components/Transfers/TransferList.js index cdb65733..9ed8832b 100644 --- a/src/web/src/components/Transfers/TransferList.js +++ b/src/web/src/components/Transfers/TransferList.js @@ -7,7 +7,7 @@ import { import { formatBytes, getFileName } from '../../lib/util'; import { - Header, + Card, Table, Icon, List, @@ -85,7 +85,7 @@ class TransferList extends Component { return (
-
@@ -94,8 +94,9 @@ class TransferList extends Component { name={isFolded ? 'chevron right' : 'chevron down'} onClick={() => this.toggleFolded()} /> - {directoryName} -
+ + {directoryName} + {!isFolded && -- cgit v1.2.3 From 64587b7c35cb623803dbc24657808724abe342a9 Mon Sep 17 00:00:00 2001 From: Lev Gorodetskiy Date: Wed, 20 Apr 2022 18:45:52 +0400 Subject: Lint --- src/web/src/components/Search/Response.js | 2 +- src/web/src/components/Transfers/TransferList.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/Search/Response.js b/src/web/src/components/Search/Response.js index b1b8b871..67de2b72 100644 --- a/src/web/src/components/Search/Response.js +++ b/src/web/src/components/Search/Response.js @@ -87,7 +87,7 @@ class Response extends Component { Upload Speed: {formatBytes(response.uploadSpeed)}/s, Free Upload Slot: {free ? 'YES' : 'NO'}, Queue Length: {response.queueLength} - {(!isFolded && Object.keys(tree) || []).map((dir, i) => + {((!isFolded && Object.keys(tree)) || []).map((dir, i) => Date: Wed, 20 Apr 2022 20:07:58 +0400 Subject: Flag to fold search results by default --- src/web/src/components/Search/Response.js | 2 +- src/web/src/components/Search/Search.js | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/Search/Response.js b/src/web/src/components/Search/Response.js index 67de2b72..0cb60586 100644 --- a/src/web/src/components/Search/Response.js +++ b/src/web/src/components/Search/Response.js @@ -29,7 +29,7 @@ class Response extends Component { tree: buildTree(this.props.response), downloadRequest: undefined, downloadError: '', - isFolded: false + isFolded: this.props.isFolded, } componentDidUpdate = (prevProps) => { diff --git a/src/web/src/components/Search/Search.js b/src/web/src/components/Search/Search.js index 713bfe26..88d70c85 100644 --- a/src/web/src/components/Search/Search.js +++ b/src/web/src/components/Search/Search.js @@ -32,7 +32,8 @@ const initialState = { hiddenResults: [], hideLocked: true, fetching: false, - resultFilters: '' + resultFilters: '', + foldResults: false, }; const sortOptions = { @@ -196,7 +197,7 @@ class Search extends Component { } render = () => { - let { searchState, searchStatus, results = [], displayCount, resultSort, hideNoFreeSlots, hideLocked, hiddenResults = [], fetching, resultFilters } = this.state; + let { searchState, searchStatus, results = [], displayCount, resultSort, hideNoFreeSlots, hideLocked, hiddenResults = [], fetching, resultFilters, foldResults } = this.state; let pending = fetching || searchState === 'pending'; const sortedAndFilteredResults = this.sortAndFilterResults(); @@ -259,6 +260,13 @@ class Search extends Component { checked={hideNoFreeSlots} label='Hide Results with No Free Slots' /> + this.setState({ foldResults: !foldResults }, () => this.saveState())} + checked={foldResults} + label='Fold Results' + />
this.hideResult(r)} + isFolded={foldResults} /> )} {remainingCount > 0 ? -- cgit v1.2.3 From 06546e3f86b7c7af5af0e98150e544f1cd3f43f1 Mon Sep 17 00:00:00 2001 From: Lev Gorodetskiy Date: Wed, 20 Apr 2022 23:08:46 +0400 Subject: Fix Fold Results toggle --- src/web/src/components/Search/Response.js | 7 +++++-- src/web/src/components/Search/Search.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/Search/Response.js b/src/web/src/components/Search/Response.js index 0cb60586..996d491a 100644 --- a/src/web/src/components/Search/Response.js +++ b/src/web/src/components/Search/Response.js @@ -29,13 +29,16 @@ class Response extends Component { tree: buildTree(this.props.response), downloadRequest: undefined, downloadError: '', - isFolded: this.props.isFolded, + isFolded: this.props.isInitiallyFolded, } componentDidUpdate = (prevProps) => { if (JSON.stringify(this.props.response) !== JSON.stringify(prevProps.response)) { this.setState({ tree: buildTree(this.props.response) }); } + if (this.props.isInitiallyFolded !== prevProps.isInitiallyFolded) { + this.setState({ isFolded: this.props.isInitiallyFolded }); + } } onFileSelectionChange = (file, state) => { @@ -79,7 +82,7 @@ class Response extends Component { this.toggleFolded()} + onClick={this.toggleFolded} /> {response.username} diff --git a/src/web/src/components/Search/Search.js b/src/web/src/components/Search/Search.js index 88d70c85..3dbcc939 100644 --- a/src/web/src/components/Search/Search.js +++ b/src/web/src/components/Search/Search.js @@ -284,7 +284,7 @@ class Search extends Component { response={r} onDownload={this.props.onDownload} onHide={() => this.hideResult(r)} - isFolded={foldResults} + isInitiallyFolded={foldResults} /> )} {remainingCount > 0 ? -- cgit v1.2.3 From 1f560268681b7eac9b21b7d63a6e6f9dfae0a52c Mon Sep 17 00:00:00 2001 From: Lev Gorodetskiy Date: Wed, 20 Apr 2022 23:28:19 +0400 Subject: Revert directory folding --- src/web/src/components/Transfers/TransferList.js | 26 +++++------------------- 1 file changed, 5 insertions(+), 21 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/Transfers/TransferList.js b/src/web/src/components/Transfers/TransferList.js index e69c9647..94b4b050 100644 --- a/src/web/src/components/Transfers/TransferList.js +++ b/src/web/src/components/Transfers/TransferList.js @@ -7,7 +7,7 @@ import { import { formatBytes, getFileName } from '../../lib/util'; import { - Card, + Header, Table, Icon, List, @@ -57,10 +57,6 @@ const formatBytesTransferred = ({ transferred, size }) => { } class TransferList extends Component { - state = { - isFolded: false - } - handleClick = (file) => { const { state, direction } = file; @@ -75,29 +71,17 @@ class TransferList extends Component { } } - toggleFolded = () => { - this.setState({'isFolded': !this.state.isFolded}); - } - render = () => { const { directoryName, onSelectionChange, files } = this.props; - const isFolded = this.state.isFolded; return (
- - this.toggleFolded()} - /> - - {directoryName} - - {!isFolded && + {directoryName} +
@@ -154,7 +138,7 @@ class TransferList extends Component {
-
} +
) } -- cgit v1.2.3 From f17d21ac2c11405490ed81e897cd6847b0e2b8cb Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 3 May 2022 08:54:10 -0500 Subject: add getUrlBase --- src/web/src/lib/application.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/web') diff --git a/src/web/src/lib/application.js b/src/web/src/lib/application.js index 0c8b8319..da5bbef5 100644 --- a/src/web/src/lib/application.js +++ b/src/web/src/lib/application.js @@ -4,6 +4,10 @@ export const getState = async () => { return (await api.get('/application')).data; }; +export const getUrlBase = async () => { + return (await api.get('/application/urlbase')).data; +} + export const restart = async () => { return api.put('/application'); }; -- cgit v1.2.3 From 5eca39f47ce7a9677325559c9d4ec0e1f2167564 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 3 May 2022 08:56:41 -0500 Subject: force /searches --- src/web/src/components/App.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index 3a22e0c8..19ea8d37 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -1,7 +1,8 @@ import React, { Component } from 'react'; -import { Route, Link, Switch } from "react-router-dom"; +import { Route, Link, Switch, Redirect } from "react-router-dom"; import * as session from '../lib/session'; +import * as application from '../lib/application'; import { connect, disconnect } from '../lib/server'; import { createApplicationHubConnection } from '../lib/hubFactory'; @@ -38,6 +39,7 @@ const initialState = { initialized: false, error: false, retriesExhausted: false, + urlBase: '', }; class App extends Component { @@ -50,7 +52,12 @@ class App extends Component { init = async () => { this.setState({ initialized: false }, async () => { try { - const securityEnabled = await session.getSecurityEnabled(); + const [urlBase, securityEnabled] = await Promise.all([ + application.getUrlBase(), + session.getSecurityEnabled()] + ); + + this.setState({ urlBase }); if (!securityEnabled) { console.debug('application security is not enabled, per api call') @@ -109,7 +116,7 @@ class App extends Component { }; render = () => { - const { login, applicationState = {}, applicationOptions = {}, error, initialized, retriesExhausted } = this.state; + const { login, applicationState = {}, applicationOptions = {}, error, initialized, retriesExhausted, urlBase = '' } = this.state; const { version = {}, server } = applicationState; const { isUpdateAvailable, current, latest } = version; @@ -150,37 +157,37 @@ class App extends Component { {version.isCanary && Canary } - + Search - + Downloads - + Uploads - + Rooms - + Chat - + Users - + Browse @@ -221,7 +228,7 @@ class App extends Component { href="https://github.com/slskd/slskd/releases">See Release Notes } - + System @@ -242,14 +249,15 @@ class App extends Component { + this.withTokenCheck()}/> this.withTokenCheck()}/> this.withTokenCheck()}/> this.withTokenCheck()}/> this.withTokenCheck()}/> this.withTokenCheck()}/> this.withTokenCheck()}/> - this.withTokenCheck()}/> - this.withTokenCheck()}/> + this.withTokenCheck()}/> + -- cgit v1.2.3 From d4b096d2e638c33a19bfd593b3ca1ed956f527ee Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 3 May 2022 08:56:50 -0500 Subject: make panes navigable by url --- src/web/src/components/System/System.js | 43 +++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/System/System.js b/src/web/src/components/System/System.js index 8b0ea4d4..ac6f5dfd 100644 --- a/src/web/src/components/System/System.js +++ b/src/web/src/components/System/System.js @@ -1,24 +1,35 @@ -import React, { Component } from 'react'; +import React from 'react'; +import { useRouteMatch } from "react-router-dom"; + import { Segment, Tab } from 'semantic-ui-react'; + import './System.css'; + import Info from './Info'; import Logs from './Logs'; import Options from './Options'; -class System extends Component { - render = () => { - return ( -
- - }, - { menuItem: 'Options', render: () => }, - { menuItem: 'Logs', render: () => }, - ]}/> - -
- ); - } -} +const System = ({ state = {}, options = {} }) => { + const { params: { tab }} = useRouteMatch(); + + const panes = [ + { route: 'info', menuItem: 'Info', render: () => }, + { route: 'options', menuItem: 'Options', render: () => }, + { route: 'logs', menuItem: 'Logs', render: () => }, + ] + + const activeIndex = panes.findIndex(pane => pane.route === tab) + + return ( +
+ + -1 ? activeIndex : 0} + panes={panes} + /> + +
+ ); +}; export default System; \ No newline at end of file -- cgit v1.2.3 From 12f2aded2257a7dcc9dbb00cbbd8bafc28579ad4 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 3 May 2022 09:23:02 -0500 Subject: navigate on tab click, set initial tab with redirect --- src/web/src/components/System/System.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/System/System.js b/src/web/src/components/System/System.js index ac6f5dfd..ca88c50d 100644 --- a/src/web/src/components/System/System.js +++ b/src/web/src/components/System/System.js @@ -1,5 +1,5 @@ import React from 'react'; -import { useRouteMatch } from "react-router-dom"; +import { useRouteMatch, useHistory, Redirect } from "react-router-dom"; import { Segment, Tab } from 'semantic-ui-react'; @@ -10,7 +10,8 @@ import Logs from './Logs'; import Options from './Options'; const System = ({ state = {}, options = {} }) => { - const { params: { tab }} = useRouteMatch(); + const { params: { tab }, ...route } = useRouteMatch(); + const history = useHistory(); const panes = [ { route: 'info', menuItem: 'Info', render: () => }, @@ -20,12 +21,21 @@ const System = ({ state = {}, options = {} }) => { const activeIndex = panes.findIndex(pane => pane.route === tab) + const onTabChange = (e, { activeIndex }) => { + history.push(panes[activeIndex].route) + } + + if (tab === undefined) { + return + } + return (
-1 ? activeIndex : 0} panes={panes} + onTabChange={onTabChange} />
-- cgit v1.2.3 From 7d4045dfe84e096adcb66250ef849afd6a5d4500 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 3 May 2022 17:47:53 -0500 Subject: remove urlbase? --- src/web/src/components/App.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index 19ea8d37..9c64c1a9 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -157,37 +157,37 @@ class App extends Component { {version.isCanary && Canary } - + Search - + Downloads - + Uploads - + Rooms - + Chat - + Users - + Browse @@ -228,7 +228,7 @@ class App extends Component { href="https://github.com/slskd/slskd/releases">See Release Notes } - + System @@ -256,8 +256,8 @@ class App extends Component { this.withTokenCheck()}/> this.withTokenCheck()}/> this.withTokenCheck()}/> - this.withTokenCheck()}/> - + this.withTokenCheck()}/> + -- cgit v1.2.3 From 536b9c3192929cced4a8925d9dbc8bec85736524 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 3 May 2022 20:47:05 -0500 Subject: retrieve urlBase from window variables --- src/web/src/config.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/web') diff --git a/src/web/src/config.js b/src/web/src/config.js index ea71e9dd..8acec820 100644 --- a/src/web/src/config.js +++ b/src/web/src/config.js @@ -1,5 +1,7 @@ -const rootUrl = process.env.NODE_ENV === 'production' ? '' : 'http://localhost:5000/'; -const baseUrl = `${rootUrl}api/v0`; +const urlBase = window.urlBase || ''; +const rootUrl = process.env.NODE_ENV === 'production' ? urlBase : `http://localhost:5000${urlBase}`; +const apiBaseUrl = `${rootUrl}/api/v0`; +const hubBaseUrl = `${rootUrl}/hub`; const tokenKey = 'slskd-token'; const tokenPassthroughValue = 'n/a'; const activeChatKey = 'slskd-active-chat'; @@ -7,8 +9,10 @@ const activeRoomKey = 'slskd-active-room'; const activeUserInfoKey = 'slskd-active-user'; export { + urlBase, rootUrl, - baseUrl, + apiBaseUrl, + hubBaseUrl, tokenKey, tokenPassthroughValue, activeChatKey, -- cgit v1.2.3 From ab2b78f4466ee4c0535a775ca5f717c9b549055a Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 3 May 2022 20:47:25 -0500 Subject: use api and hub baseurls --- src/web/src/lib/api.js | 4 ++-- src/web/src/lib/hubFactory.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/web') diff --git a/src/web/src/lib/api.js b/src/web/src/lib/api.js index 73e75373..0e7d8050 100644 --- a/src/web/src/lib/api.js +++ b/src/web/src/lib/api.js @@ -1,8 +1,8 @@ import axios from 'axios'; -import { baseUrl } from '../config'; +import { apiBaseUrl } from '../config'; import * as session from './session'; -axios.defaults.baseURL = baseUrl; +axios.defaults.baseURL = apiBaseUrl; const api = axios.create({ withCredentials: true diff --git a/src/web/src/lib/hubFactory.js b/src/web/src/lib/hubFactory.js index a64c5c40..246e9d03 100644 --- a/src/web/src/lib/hubFactory.js +++ b/src/web/src/lib/hubFactory.js @@ -4,7 +4,7 @@ import { LogLevel } from '@microsoft/signalr' -import { rootUrl } from '../config'; +import { hubBaseUrl } from '../config'; import * as session from '../lib/session'; export const createHubConnection = ({ url }) => @@ -18,6 +18,6 @@ export const createHubConnection = ({ url }) => .configureLogging(LogLevel.Warning) .build(); -export const createApplicationHubConnection = () => createHubConnection({ url: `${rootUrl}hub/application` }); +export const createApplicationHubConnection = () => createHubConnection({ url: `${hubBaseUrl}/application` }); -export const createLogsHubConnection = () => createHubConnection({ url: `${rootUrl}hub/logs` }); \ No newline at end of file +export const createLogsHubConnection = () => createHubConnection({ url: `${hubBaseUrl}/logs` }); \ No newline at end of file -- cgit v1.2.3 From 449fc05acf88e742849c2d83bc86fbf2fd77e5e4 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 3 May 2022 20:47:40 -0500 Subject: remove getUrlBase --- src/web/src/lib/application.js | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/web') diff --git a/src/web/src/lib/application.js b/src/web/src/lib/application.js index da5bbef5..0c8b8319 100644 --- a/src/web/src/lib/application.js +++ b/src/web/src/lib/application.js @@ -4,10 +4,6 @@ export const getState = async () => { return (await api.get('/application')).data; }; -export const getUrlBase = async () => { - return (await api.get('/application/urlbase')).data; -} - export const restart = async () => { return api.put('/application'); }; -- cgit v1.2.3 From f62e6e4b63fabd32e32f3307f968f4e414a59152 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 3 May 2022 20:48:07 -0500 Subject: explicitly append urlBase --- src/web/src/components/App.js | 46 +++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 26 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index 9c64c1a9..09f3f742 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -2,8 +2,8 @@ import React, { Component } from 'react'; import { Route, Link, Switch, Redirect } from "react-router-dom"; import * as session from '../lib/session'; -import * as application from '../lib/application'; import { connect, disconnect } from '../lib/server'; +import { urlBase } from '../config'; import { createApplicationHubConnection } from '../lib/hubFactory'; @@ -39,7 +39,6 @@ const initialState = { initialized: false, error: false, retriesExhausted: false, - urlBase: '', }; class App extends Component { @@ -52,12 +51,7 @@ class App extends Component { init = async () => { this.setState({ initialized: false }, async () => { try { - const [urlBase, securityEnabled] = await Promise.all([ - application.getUrlBase(), - session.getSecurityEnabled()] - ); - - this.setState({ urlBase }); + const securityEnabled = await session.getSecurityEnabled(); if (!securityEnabled) { console.debug('application security is not enabled, per api call') @@ -116,7 +110,7 @@ class App extends Component { }; render = () => { - const { login, applicationState = {}, applicationOptions = {}, error, initialized, retriesExhausted, urlBase = '' } = this.state; + const { login, applicationState = {}, applicationOptions = {}, error, initialized, retriesExhausted } = this.state; const { version = {}, server } = applicationState; const { isUpdateAvailable, current, latest } = version; @@ -157,37 +151,37 @@ class App extends Component { {version.isCanary && Canary } - + Search - + Downloads - + Uploads - + Rooms - + Chat - + Users - + Browse @@ -228,7 +222,7 @@ class App extends Component { href="https://github.com/slskd/slskd/releases">See Release Notes } - + System @@ -249,15 +243,15 @@ class App extends Component { - this.withTokenCheck()}/> - this.withTokenCheck()}/> - this.withTokenCheck()}/> - this.withTokenCheck()}/> - this.withTokenCheck()}/> - this.withTokenCheck()}/> - this.withTokenCheck()}/> - this.withTokenCheck()}/> - + this.withTokenCheck()}/> + this.withTokenCheck()}/> + this.withTokenCheck()}/> + this.withTokenCheck()}/> + this.withTokenCheck()}/> + this.withTokenCheck()}/> + this.withTokenCheck()}/> + this.withTokenCheck()}/> + -- cgit v1.2.3 From dd76dd55f13aaab06249b64fe897287356bdeb02 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 3 May 2022 21:21:17 -0500 Subject: remove homepage --- src/web/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/web') diff --git a/src/web/package.json b/src/web/package.json index a8810d47..54fc6e0b 100644 --- a/src/web/package.json +++ b/src/web/package.json @@ -2,7 +2,6 @@ "name": "web", "version": "0.1.0", "private": true, - "homepage": ".", "dependencies": { "@codemirror/highlight": "^0.19.7", "@codemirror/legacy-modes": "^0.19.0", @@ -52,4 +51,4 @@ "not op_mini all" ] } -} +} \ No newline at end of file -- cgit v1.2.3 From ab66d41d8676ceda951f0bb1b7d940c09f2f1c2d Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 3 May 2022 21:21:31 -0500 Subject: add urlBase script to index --- src/web/public/index.html | 1 + src/web/src/config.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/web') diff --git a/src/web/public/index.html b/src/web/public/index.html index e452c8c8..fa11b640 100644 --- a/src/web/public/index.html +++ b/src/web/public/index.html @@ -10,3 +10,4 @@
+ \ No newline at end of file diff --git a/src/web/src/config.js b/src/web/src/config.js index 8acec820..6f899564 100644 --- a/src/web/src/config.js +++ b/src/web/src/config.js @@ -1,5 +1,5 @@ -const urlBase = window.urlBase || ''; -const rootUrl = process.env.NODE_ENV === 'production' ? urlBase : `http://localhost:5000${urlBase}`; +const urlBase = (window.urlBase === '/' ? '' : window.urlBase) || ''; +const rootUrl = process.env.NODE_ENV === 'production' ? urlBase : `http://localhost:5000/${urlBase}`; const apiBaseUrl = `${rootUrl}/api/v0`; const hubBaseUrl = `${rootUrl}/hub`; const tokenKey = 'slskd-token'; -- cgit v1.2.3 From e52d636f8a2069394653992384ef7f3cdcafea5d Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 3 May 2022 22:46:23 -0500 Subject: add homepage back --- src/web/package.json | 1 + 1 file changed, 1 insertion(+) (limited to 'src/web') diff --git a/src/web/package.json b/src/web/package.json index 54fc6e0b..62b72a55 100644 --- a/src/web/package.json +++ b/src/web/package.json @@ -2,6 +2,7 @@ "name": "web", "version": "0.1.0", "private": true, + "homepage": ".", "dependencies": { "@codemirror/highlight": "^0.19.7", "@codemirror/legacy-modes": "^0.19.0", -- cgit v1.2.3 From eb1c6098957d992037ae20929fdc5ec5e1fa9520 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 5 May 2022 20:34:38 -0500 Subject: remove urlbase script --- src/web/public/index.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/web') diff --git a/src/web/public/index.html b/src/web/public/index.html index fa11b640..5b30bc65 100644 --- a/src/web/public/index.html +++ b/src/web/public/index.html @@ -9,5 +9,4 @@
- - \ No newline at end of file + \ No newline at end of file -- cgit v1.2.3 From 2391114fbcadba7378451c8a066fb466269fdb13 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 7 May 2022 13:55:22 -0500 Subject: docs --- src/slskd/Program.cs | 14 +++++--------- src/web/package.json | 2 +- src/web/public/index.html | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) (limited to 'src/web') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 91ce72f7..ecf028b4 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -612,7 +612,7 @@ namespace slskd // inject urlBase into any html files we serve, and rewrite links to ./static or /static to // prepend the url base. app.UsePathBase(urlBase); - app.UseHTMLRewrite("((\\.)?\\/static)", $"{urlBase}/static"); + app.UseHTMLRewrite("((\\.)?\\/static)", $"{(urlBase == "/" ? string.Empty : urlBase)}/static"); app.UseHTMLInjection($""); Log.Information("Using base url {UrlBase}", urlBase); @@ -683,14 +683,11 @@ namespace slskd } // if we made it this far, the caller is either looking for a route that was synthesized with a SPA router, or is genuinely confused. - // optimistically search the dictionary of static files to see if we have a file that matches, and serve it if so. + // if the request is for a directory, modify the request to redirect it to the index, otherwise leave it alone and let it 404 in the next + // middleware app.Use(async (context, next) => { - var path = context.Request.Path.ToString(); - - // if there is no extension, the caller is looking for a directory (an index file) - // modify the request to get the canonical default index - if (Path.GetExtension(path) == string.Empty) + if (Path.GetExtension(context.Request.Path.ToString()) == string.Empty) { context.Request.Path = "/"; } @@ -698,8 +695,7 @@ namespace slskd await next(); }); - // the request path may have been rewritten above, in which case we're likely to have better luck finding - // a match with the file server middleware. let it try, and if it fails let it return a 404. + // either serve the index, or 404 app.UseFileServer(fileServerOptions); return app; diff --git a/src/web/package.json b/src/web/package.json index 62b72a55..a8810d47 100644 --- a/src/web/package.json +++ b/src/web/package.json @@ -52,4 +52,4 @@ "not op_mini all" ] } -} \ No newline at end of file +} diff --git a/src/web/public/index.html b/src/web/public/index.html index 5b30bc65..e452c8c8 100644 --- a/src/web/public/index.html +++ b/src/web/public/index.html @@ -9,4 +9,4 @@
- \ No newline at end of file + -- cgit v1.2.3 From 1bfbb7bd0d4ab9647174b52aaae794d497341893 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 7 May 2022 15:36:30 -0500 Subject: Update src/web/src/components/Search/Response.js --- src/web/src/components/Search/Response.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/web') diff --git a/src/web/src/components/Search/Response.js b/src/web/src/components/Search/Response.js index 996d491a..8d134047 100644 --- a/src/web/src/components/Search/Response.js +++ b/src/web/src/components/Search/Response.js @@ -60,7 +60,7 @@ class Response extends Component { } toggleFolded = () => { - this.setState({'isFolded': !this.state.isFolded}); + this.setState({ isFolded: !this.state.isFolded }); } render = () => { -- cgit v1.2.3