aboutsummaryrefslogtreecommitdiffstats
path: root/src/web
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-06-21 10:41:53 -0500
committerGitHub <noreply@github.com>2026-06-21 10:41:53 -0500
commit7497db57e8a44769d1a098ad189247ea4e980a1d (patch)
tree189ff962d5125fe2526e4f79dccb009379725fdf /src/web
parent8e152ed6eccd5650179f2875eef4aa21243c8c15 (diff)
parent28fa7202724da10075dbddc3244d5d5528b4bdad (diff)
downloadslskd-7497db57e8a44769d1a098ad189247ea4e980a1d.tar.gz
Merge pull request #1769 from slskd/reports
Collect and broadcast real-time transfer metrics, add a footer to the UI to display them
Diffstat (limited to 'src/web')
-rw-r--r--src/web/package-lock.json17
-rw-r--r--src/web/package.json1
-rw-r--r--src/web/src/components/App.css53
-rw-r--r--src/web/src/components/App.jsx259
-rw-r--r--src/web/src/components/AppFooter.jsx83
-rw-r--r--src/web/src/lib/hubFactory.js3
-rw-r--r--src/web/src/lib/util.js16
-rw-r--r--src/web/src/lib/util.test.js11
8 files changed, 317 insertions, 126 deletions
diff --git a/src/web/package-lock.json b/src/web/package-lock.json
index e64bc38d..191d1cca 100644
--- a/src/web/package-lock.json
+++ b/src/web/package-lock.json
@@ -28,6 +28,7 @@
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
+ "@babel/plugin-syntax-import-assertions": "^7.29.7",
"@craco/craco": "^7.0.0",
"@semantic-ui-react/craco-less": "^3.0.0",
"@semantic-ui-react/css-patch": "^1.0.0",
@@ -510,10 +511,11 @@
}
},
"node_modules/@babel/helper-plugin-utils": {
- "version": "7.22.5",
- "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.22.5.tgz",
- "integrity": "sha512-uLls06UVKgFG9QD4OeFYLEGteMIAa5kpTPcFL28yuCIIzsf6ZyKZMllKVOCZFhiZ5ptnwX4mtKdWCBE/uT4amg==",
+ "version": "7.29.7",
+ "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.29.7.tgz",
+ "integrity": "sha512-G7sHYigPY17oO5SYWnfD/0MTBwVR781S/JI643e/JhUYgVgWE/61SoW3NH9KWUKyKq5LVh3npif99Wkt6j86Jw==",
"dev": true,
+ "license": "MIT",
"engines": {
"node": ">=6.9.0"
}
@@ -1014,12 +1016,13 @@
}
},
"node_modules/@babel/plugin-syntax-import-assertions": {
- "version": "7.22.5",
- "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-assertions/-/plugin-syntax-import-assertions-7.22.5.tgz",
- "integrity": "sha512-rdV97N7KqsRzeNGoWUOK6yUsWarLjE5Su/Snk9IYPU9CwkWHs4t+rTGOvffTR8XGkJMTAdLfO0xVnXm8wugIJg==",
+ "version": "7.29.7",
+ "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-assertions/-/plugin-syntax-import-assertions-7.29.7.tgz",
+ "integrity": "sha512-/An1OCBN93thpBAGyfsK2pcf0jvju1SAtKkL2Ny++B5Sy6sqgzXDQH1cZxWbF96Wuk+bn41MDA9bLd4VVAw6rw==",
"dev": true,
+ "license": "MIT",
"dependencies": {
- "@babel/helper-plugin-utils": "^7.22.5"
+ "@babel/helper-plugin-utils": "^7.29.7"
},
"engines": {
"node": ">=6.9.0"
diff --git a/src/web/package.json b/src/web/package.json
index 00491c52..8fe233f4 100644
--- a/src/web/package.json
+++ b/src/web/package.json
@@ -33,6 +33,7 @@
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
+ "@babel/plugin-syntax-import-assertions": "^7.29.7",
"@craco/craco": "^7.0.0",
"@semantic-ui-react/craco-less": "^3.0.0",
"@semantic-ui-react/css-patch": "^1.0.0",
diff --git a/src/web/src/components/App.css b/src/web/src/components/App.css
index 054fe1c4..1e2000f9 100644
--- a/src/web/src/components/App.css
+++ b/src/web/src/components/App.css
@@ -123,6 +123,13 @@ body {
.pushable > .pusher.app-content {
min-height: calc(100% - 71px);
background: var(--background-color);
+ display: flex;
+ flex-direction: column;
+}
+
+.app-content-body {
+ flex: 1;
+ padding-bottom: 40px; /* footer */
}
.navigation {
@@ -264,4 +271,50 @@ body {
.message {
padding: 8px 12px 8px 12px !important;
+}
+
+.footer.ui.menu {
+ position: fixed !important;
+ bottom: 0 !important;
+ left: 0 !important;
+ right: 0 !important;
+ z-index: 1000 !important;
+ margin: 0 !important;
+ border-radius: 0 !important;
+}
+
+.footer-logo {
+ height: 18px;
+ width: 18px !important;
+ vertical-align: middle;
+}
+
+.footer-version {
+ margin-left: 6px;
+ font-family: monospace;
+ font-size: 14px;
+ opacity: 0.7;
+ margin-top: 1px;
+}
+
+.footer-license {
+ margin-left: 6px;
+ font-family: monospace;
+ font-size: 14px;
+ opacity: 0.5;
+ margin-top: 1px;
+}
+
+.footer-stat-detail {
+ margin-left: 6px;
+ font-size: 14px;
+ opacity: 0.7;
+}
+
+.footer-download,
+.footer-upload {
+ white-space: pre;
+ font-family: monospace;
+ font-size: 14px;
+ margin-top: 1px;
} \ No newline at end of file
diff --git a/src/web/src/components/App.jsx b/src/web/src/components/App.jsx
index 92fe925b..9839bf35 100644
--- a/src/web/src/components/App.jsx
+++ b/src/web/src/components/App.jsx
@@ -1,12 +1,16 @@
import 'react-toastify/dist/ReactToastify.css';
import './App.css';
import { urlBase } from '../config';
-import { createApplicationHubConnection } from '../lib/hubFactory';
+import {
+ createApplicationHubConnection,
+ createMetricsHubConnection,
+} from '../lib/hubFactory';
import * as relayAPI from '../lib/relay';
import { connect, disconnect } from '../lib/server';
import * as session from '../lib/session';
import { isPassthroughEnabled } from '../lib/token';
import AppContext from './AppContext';
+import AppFooter from './AppFooter';
import Browse from './Browse/Browse';
import Chat from './Chat/Chat';
import LoginForm from './LoginForm';
@@ -40,6 +44,7 @@ const initialState = {
pending: false,
},
retriesExhausted: false,
+ transferMetrics: {},
};
const ModeSpecificConnectButton = ({
@@ -151,6 +156,7 @@ class App extends Component {
super(props);
this.state = initialState;
+ this.hubConnections = {};
}
componentDidMount() {
@@ -203,7 +209,19 @@ class App extends Component {
this.setState({ error: false, retriesExhausted: false }),
);
+ await this.hubConnections.appHub?.stop();
+ this.hubConnections.appHub = appHub;
await appHub.start();
+
+ const metricsHub = createMetricsHubConnection();
+
+ metricsHub.on('Update', (metrics) => {
+ this.setState({ transferMetrics: metrics });
+ });
+
+ await this.hubConnections.metricsHub?.stop();
+ this.hubConnections.metricsHub = metricsHub;
+ await metricsHub.start();
}
const savedTheme = this.getSavedTheme();
@@ -260,6 +278,10 @@ class App extends Component {
logout = () => {
session.logout();
+
+ this.hubConnections?.appHub?.stop();
+ this.hubConnections?.metricsHub?.stop();
+
this.setState({ login: { ...initialState.login } });
};
@@ -280,6 +302,7 @@ class App extends Component {
(window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
: 'light'),
+ transferMetrics = {},
} = this.state;
const {
connectionWatchdog = {},
@@ -522,124 +545,132 @@ class App extends Component {
</Menu>
</Sidebar>
<Sidebar.Pusher className="app-content">
- <AppContext.Provider
- // eslint-disable-next-line no-warning-comments
- // TODO: needs useMemo, but class component. yolo for now.
- // eslint-disable-next-line react/jsx-no-constructed-context-values
- value={{ options: applicationOptions, state: applicationState }}
- >
- {isAgent ? (
- <Switch>
- <Route
- path={`${urlBase}/system/:tab?`}
- render={(props) =>
- this.withTokenCheck(
- <System
- {...props}
- options={applicationOptions}
- state={applicationState}
- />,
- )
- }
- />
- <Redirect
- from="*"
- to={`${urlBase}/system`}
- />
- </Switch>
- ) : (
- <Switch>
- <Route
- path={`${urlBase}/searches/:id?`}
- render={(props) =>
- this.withTokenCheck(
- <div className="view">
- <Searches
- server={applicationState.server}
+ <div className="app-content-body">
+ <AppContext.Provider
+ // eslint-disable-next-line no-warning-comments
+ // TODO: needs useMemo, but class component. yolo for now.
+ // eslint-disable-next-line react/jsx-no-constructed-context-values
+ value={{ options: applicationOptions, state: applicationState }}
+ >
+ {isAgent ? (
+ <Switch>
+ <Route
+ path={`${urlBase}/system/:tab?`}
+ render={(props) =>
+ this.withTokenCheck(
+ <System
{...props}
- />
- </div>,
- )
- }
- />
- <Route
- path={`${urlBase}/browse`}
- render={(props) =>
- this.withTokenCheck(<Browse {...props} />)
- }
- />
- <Route
- path={`${urlBase}/users`}
- render={(props) =>
- this.withTokenCheck(<Users {...props} />)
- }
- />
- <Route
- path={`${urlBase}/chat`}
- render={(props) =>
- this.withTokenCheck(
- <Chat
- {...props}
- state={applicationState}
- />,
- )
- }
- />
- <Route
- path={`${urlBase}/rooms`}
- render={(props) =>
- this.withTokenCheck(<Rooms {...props} />)
- }
- />
- <Route
- path={`${urlBase}/uploads`}
- render={(props) =>
- this.withTokenCheck(
- <div className="view">
- <Transfers
+ options={applicationOptions}
+ state={applicationState}
+ />,
+ )
+ }
+ />
+ <Redirect
+ from="*"
+ to={`${urlBase}/system`}
+ />
+ </Switch>
+ ) : (
+ <Switch>
+ <Route
+ path={`${urlBase}/searches/:id?`}
+ render={(props) =>
+ this.withTokenCheck(
+ <div className="view">
+ <Searches
+ server={applicationState.server}
+ {...props}
+ />
+ </div>,
+ )
+ }
+ />
+ <Route
+ path={`${urlBase}/browse`}
+ render={(props) =>
+ this.withTokenCheck(<Browse {...props} />)
+ }
+ />
+ <Route
+ path={`${urlBase}/users`}
+ render={(props) =>
+ this.withTokenCheck(<Users {...props} />)
+ }
+ />
+ <Route
+ path={`${urlBase}/chat`}
+ render={(props) =>
+ this.withTokenCheck(
+ <Chat
{...props}
- direction="upload"
- />
- </div>,
- )
- }
- />
- <Route
- path={`${urlBase}/downloads`}
- render={(props) =>
- this.withTokenCheck(
- <div className="view">
- <Transfers
+ state={applicationState}
+ />,
+ )
+ }
+ />
+ <Route
+ path={`${urlBase}/rooms`}
+ render={(props) =>
+ this.withTokenCheck(<Rooms {...props} />)
+ }
+ />
+ <Route
+ path={`${urlBase}/uploads`}
+ render={(props) =>
+ this.withTokenCheck(
+ <div className="view">
+ <Transfers
+ {...props}
+ direction="upload"
+ />
+ </div>,
+ )
+ }
+ />
+ <Route
+ path={`${urlBase}/downloads`}
+ render={(props) =>
+ this.withTokenCheck(
+ <div className="view">
+ <Transfers
+ {...props}
+ direction="download"
+ server={applicationState.server}
+ />
+ </div>,
+ )
+ }
+ />
+ <Route
+ path={`${urlBase}/system/:tab?`}
+ render={(props) =>
+ this.withTokenCheck(
+ <System
{...props}
- direction="download"
- server={applicationState.server}
- />
- </div>,
- )
- }
- />
- <Route
- path={`${urlBase}/system/:tab?`}
- render={(props) =>
- this.withTokenCheck(
- <System
- {...props}
- options={applicationOptions}
- state={applicationState}
- theme={theme}
- />,
- )
- }
- />
- <Redirect
- from="*"
- to={`${urlBase}/searches`}
- />
- </Switch>
- )}
- </AppContext.Provider>
+ options={applicationOptions}
+ state={applicationState}
+ theme={theme}
+ />,
+ )
+ }
+ />
+ <Redirect
+ from="*"
+ to={`${urlBase}/searches`}
+ />
+ </Switch>
+ )}
+ </AppContext.Provider>
+ </div>
</Sidebar.Pusher>
</Sidebar.Pushable>
+ <AppFooter
+ server={server}
+ transferMetrics={transferMetrics}
+ user={user}
+ version={version}
+ />
<ToastContainer
autoClose={5_000}
closeOnClick
diff --git a/src/web/src/components/AppFooter.jsx b/src/web/src/components/AppFooter.jsx
new file mode 100644
index 00000000..261b5c11
--- /dev/null
+++ b/src/web/src/components/AppFooter.jsx
@@ -0,0 +1,83 @@
+import { formatBytes } from '../lib/util';
+import React from 'react';
+import { Icon, Menu } from 'semantic-ui-react';
+
+const formatSpeed = (bytesPerSecond) => {
+ if (!bytesPerSecond || bytesPerSecond < 1) {
+ return ' 0 B/s';
+ }
+
+ return `${formatBytes(bytesPerSecond, 1, 4, ' ')}/s`;
+};
+
+const AppFooter = ({
+ server = {},
+ transferMetrics = {},
+ user = {},
+ version = {},
+}) => {
+ const { isConnected } = server;
+ const { username } = user;
+ const { current } = version;
+ // const { downloads, uploads } = transferMetrics ?? {};
+ const downloadSpeed = transferMetrics?.downloads?.inProgress?.averageSpeed;
+ const downloadActive = transferMetrics?.downloads?.inProgress?.files ?? 0;
+ const downloadQueued = transferMetrics?.downloads?.queued?.files ?? 0;
+ const uploadSpeed = transferMetrics?.uploads?.inProgress?.averageSpeed;
+ const uploadActive = transferMetrics?.uploads?.inProgress?.files ?? 0;
+ const uploadQueued = transferMetrics?.uploads?.queued?.files ?? 0;
+
+ return (
+ <Menu
+ className="footer"
+ inverted
+ >
+ <Menu.Item>
+ <Icon
+ color={isConnected ? 'green' : 'red'}
+ name="circle"
+ />
+ {isConnected ? username : 'Disconnected'}
+ </Menu.Item>
+ <Menu.Item>
+ <Icon
+ color="blue"
+ name="arrow down"
+ />
+ <span className="footer-download">{formatSpeed(downloadSpeed)}</span>
+ <span className="footer-stat-detail">
+ {downloadActive} active &middot; {downloadQueued} queued
+ </span>
+ </Menu.Item>
+ <Menu.Item>
+ <Icon
+ color="orange"
+ name="arrow up"
+ />
+ <span className="footer-upload">{formatSpeed(uploadSpeed)}</span>
+ <span className="footer-stat-detail">
+ {uploadActive} active &middot; {uploadQueued} queued
+ </span>
+ </Menu.Item>
+ <Menu.Menu position="right">
+ <Menu.Item
+ as="a"
+ href="https://github.com/slskd/slskd"
+ rel="noreferrer"
+ target="_blank"
+ >
+ <img
+ alt=""
+ className="footer-logo"
+ src="/favicon.ico"
+ />
+ slskd
+ {current && <span className="footer-version">{current}</span>}
+ <span className="footer-license">AGPLv3</span>
+ </Menu.Item>
+ </Menu.Menu>
+ </Menu>
+ );
+};
+
+export default AppFooter;
diff --git a/src/web/src/lib/hubFactory.js b/src/web/src/lib/hubFactory.js
index d5264e03..3b5e36f7 100644
--- a/src/web/src/lib/hubFactory.js
+++ b/src/web/src/lib/hubFactory.js
@@ -27,3 +27,6 @@ export const createLogsHubConnection = () =>
export const createSearchHubConnection = () =>
createHubConnection({ url: `${hubBaseUrl}/search` });
+
+export const createMetricsHubConnection = () =>
+ createHubConnection({ url: `${hubBaseUrl}/metrics` });
diff --git a/src/web/src/lib/util.js b/src/web/src/lib/util.js
index 755546de..caced7ac 100644
--- a/src/web/src/lib/util.js
+++ b/src/web/src/lib/util.js
@@ -19,8 +19,13 @@ export const formatBytesAsUnit = (bytes, unit, decimals = 2) => {
return Number.parseFloat((bytes / k ** sizes[unit]).toFixed(dm));
};
-export const formatBytes = (bytes, decimals = 2) => {
- if (bytes === 0) return '0 B';
+export const formatBytes = (
+ bytes,
+ decimals = 2,
+ padding = 0,
+ paddingCharacter = ' ',
+) => {
+ if (bytes === 0 || bytes < 1) return '0 B';
const k = 1_024;
const dm = decimals < 0 ? 0 : decimals;
@@ -28,9 +33,10 @@ export const formatBytes = (bytes, decimals = 2) => {
const index = Math.floor(Math.log(bytes) / Math.log(k));
- return (
- Number.parseFloat((bytes / k ** index).toFixed(dm)) + ' ' + sizes[index]
- );
+ const number = Number.parseFloat((bytes / k ** index).toFixed(dm));
+ const padded = number.toString().padStart(padding, paddingCharacter);
+
+ return padded + ' ' + sizes[index];
};
export const formatDate = (date) => {
diff --git a/src/web/src/lib/util.test.js b/src/web/src/lib/util.test.js
index 9bf79fab..0113a290 100644
--- a/src/web/src/lib/util.test.js
+++ b/src/web/src/lib/util.test.js
@@ -5,3 +5,14 @@ describe('formatBytesAsUnit', () => {
expect(utils.formatBytesAsUnit(1_234_567, 'MB', 2)).toBe(1.18);
});
});
+
+describe('formatBytes', () => {
+ it('returns 0 B for values under one byte', () => {
+ expect(utils.formatBytes(0.5)).toBe('0 B');
+ });
+
+ it('formats byte values for one and above', () => {
+ expect(utils.formatBytes(1)).toBe('1 B');
+ expect(utils.formatBytes(1_024)).toBe('1 KB');
+ });
+});