mirror of
https://github.com/zoriya/flood.git
synced 2025-12-06 07:16:18 +00:00
API: torrents: calculate the Duration object in frontend
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import {FormattedMessage} from 'react-intl';
|
||||
import * as React from 'react';
|
||||
|
||||
import type {Duration as DurationType} from '@shared/types/Torrent';
|
||||
import formatUtil from '@shared/util/formatUtil';
|
||||
|
||||
interface DurationProps {
|
||||
suffix?: React.ReactNode;
|
||||
value: -1 | DurationType;
|
||||
value: number;
|
||||
}
|
||||
|
||||
const Duration: React.FC<DurationProps> = (props: DurationProps) => {
|
||||
const {suffix, value: duration} = props;
|
||||
const {suffix, value} = props;
|
||||
|
||||
if (duration == null) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ const Duration: React.FC<DurationProps> = (props: DurationProps) => {
|
||||
suffixElement = <span className="duration--segment">{suffix}</span>;
|
||||
}
|
||||
|
||||
const duration = value === -1 ? -1 : formatUtil.secondsToDuration(value);
|
||||
|
||||
if (duration === -1) {
|
||||
content = <FormattedMessage id="unit.time.infinity" />;
|
||||
} else if (duration.years != null && duration.years > 0) {
|
||||
|
||||
@@ -3,7 +3,6 @@ import {Component} from 'react';
|
||||
import {defineMessages, injectIntl, WrappedComponentProps} from 'react-intl';
|
||||
import dayjs from 'dayjs';
|
||||
import duration from 'dayjs/plugin/duration';
|
||||
import formatUtil from '@shared/util/formatUtil';
|
||||
import {observer} from 'mobx-react';
|
||||
|
||||
import type {TransferDirection} from '@shared/types/TransferData';
|
||||
@@ -71,14 +70,12 @@ class TransferRateDetails extends Component<TransferRateDetailsProps> {
|
||||
});
|
||||
|
||||
if (inspectorPoint?.nearestTimestamp != null) {
|
||||
const currentTime = dayjs(Date.now());
|
||||
const durationSummary = formatUtil.secondsToDuration(
|
||||
dayjs.duration(currentTime.diff(dayjs(inspectorPoint.nearestTimestamp))).asSeconds(),
|
||||
);
|
||||
|
||||
timestamp = (
|
||||
<div className={timestampClasses}>
|
||||
<Duration suffix={intl.formatMessage(messages.ago)} value={durationSummary} />
|
||||
<Duration
|
||||
suffix={intl.formatMessage(messages.ago)}
|
||||
value={dayjs.duration(dayjs(Date.now()).diff(dayjs(inspectorPoint.nearestTimestamp))).asSeconds()}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ function sortTorrents(torrents: Array<TorrentProperties>, sortBy: Readonly<Flood
|
||||
if (p.eta === -1) {
|
||||
return Infinity;
|
||||
}
|
||||
return p.eta.cumSeconds;
|
||||
return p.eta;
|
||||
},
|
||||
} as SortRule);
|
||||
break;
|
||||
|
||||
@@ -24,7 +24,6 @@ import type {SetClientSettingsOptions} from '@shared/types/api/client';
|
||||
|
||||
import ClientGatewayService from '../interfaces/clientGatewayService';
|
||||
import ClientRequestManager from './clientRequestManager';
|
||||
import formatUtil from '../../../shared/util/formatUtil';
|
||||
import {getDomainsFromURLs} from '../../util/torrentPropertiesUtil';
|
||||
import {
|
||||
getTorrentPeerPropertiesFromFlags,
|
||||
@@ -244,7 +243,7 @@ class QBittorrentClientGatewayService extends ClientGatewayService {
|
||||
directory: info.save_path,
|
||||
downRate: info.dlspeed,
|
||||
downTotal: info.downloaded,
|
||||
eta: info.eta === -1 ? -1 : formatUtil.secondsToDuration(info.eta),
|
||||
eta: info.eta,
|
||||
hash: info.hash,
|
||||
isMultiFile: false,
|
||||
isPrivate: false,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import formatUtil from '../../../../shared/util/formatUtil';
|
||||
import truncateTo from './numberUtils';
|
||||
|
||||
import type {TorrentProperties} from '../../../../shared/types/Torrent';
|
||||
@@ -14,7 +13,7 @@ export const getTorrentETAFromProperties = (
|
||||
}
|
||||
|
||||
if (downRate > 0) {
|
||||
return formatUtil.secondsToDuration((sizeBytes - bytesDone) / downRate);
|
||||
return (sizeBytes - bytesDone) / downRate;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
@@ -36,7 +36,8 @@ export interface TorrentProperties {
|
||||
directory: string;
|
||||
downRate: number;
|
||||
downTotal: number;
|
||||
eta: -1 | Duration;
|
||||
// Torrent ETA (seconds), -1 means infinity
|
||||
eta: number;
|
||||
hash: string;
|
||||
isMultiFile: boolean;
|
||||
isPrivate: boolean;
|
||||
|
||||
Reference in New Issue
Block a user