2023-12-07 16:33:37 +00:00
|
|
|
import {
|
|
|
|
|
TorrentStats,
|
|
|
|
|
STATE_INITIALIZING,
|
|
|
|
|
STATE_PAUSED,
|
|
|
|
|
STATE_ERROR,
|
|
|
|
|
} from "../api-types";
|
|
|
|
|
import { formatBytes } from "../helper/formatBytes";
|
|
|
|
|
|
|
|
|
|
export const Speed: React.FC<{ statsResponse: TorrentStats }> = ({
|
|
|
|
|
statsResponse,
|
|
|
|
|
}) => {
|
|
|
|
|
switch (statsResponse.state) {
|
|
|
|
|
case STATE_PAUSED:
|
|
|
|
|
return "Paused";
|
|
|
|
|
case STATE_INITIALIZING:
|
|
|
|
|
return "Checking files";
|
|
|
|
|
case STATE_ERROR:
|
|
|
|
|
return "Error";
|
|
|
|
|
}
|
|
|
|
|
// Unknown state
|
|
|
|
|
if (statsResponse.state != "live" || statsResponse.live === null) {
|
|
|
|
|
return statsResponse.state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{!statsResponse.finished && (
|
|
|
|
|
<div className="download-speed">
|
2023-12-07 16:43:41 +00:00
|
|
|
↓ {statsResponse.live.download_speed?.human_readable}
|
2023-12-07 16:33:37 +00:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<div className="upload-speed">
|
2023-12-07 16:43:41 +00:00
|
|
|
↑ {statsResponse.live.upload_speed?.human_readable}
|
2023-12-07 16:33:37 +00:00
|
|
|
{statsResponse.live.snapshot.uploaded_bytes > 0 && (
|
|
|
|
|
<span>
|
|
|
|
|
({formatBytes(statsResponse.live.snapshot.uploaded_bytes)})
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|