mirror of
https://github.com/c0re100/qBittorrent-Enhanced-Edition.git
synced 2025-01-08 11:57:51 +08:00
Improve "last activity" calculation in WebAPI (#15339)
Co-authored-by: 秦风 <mayli.he@gmail.com> Co-authored-by: Chocobo1 <Chocobo1@users.noreply.github.com>
This commit is contained in:
parent
d0d0bed333
commit
8d822f2cb4
@ -97,6 +97,14 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent)
|
||||
return (ratio > BitTorrent::Torrent::MAX_RATIO) ? -1 : ratio;
|
||||
};
|
||||
|
||||
const auto getLastActivityTime = [&torrent]() -> qlonglong
|
||||
{
|
||||
const qlonglong timeSinceActivity = torrent.timeSinceActivity();
|
||||
return (timeSinceActivity < 0)
|
||||
? torrent.addedTime().toSecsSinceEpoch()
|
||||
: (QDateTime::currentDateTime().toSecsSinceEpoch() - timeSinceActivity);
|
||||
};
|
||||
|
||||
return {
|
||||
{KEY_TORRENT_ID, torrent.id().toString()},
|
||||
{KEY_TORRENT_INFOHASHV1, torrent.infoHash().v1().toString()},
|
||||
@ -145,7 +153,7 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent)
|
||||
{KEY_TORRENT_AUTO_TORRENT_MANAGEMENT, torrent.isAutoTMMEnabled()},
|
||||
{KEY_TORRENT_TIME_ACTIVE, torrent.activeTime()},
|
||||
{KEY_TORRENT_SEEDING_TIME, torrent.seedingTime()},
|
||||
{KEY_TORRENT_LAST_ACTIVITY_TIME, (QDateTime::currentDateTime().toSecsSinceEpoch() - torrent.timeSinceActivity())},
|
||||
{KEY_TORRENT_LAST_ACTIVITY_TIME, getLastActivityTime()},
|
||||
{KEY_TORRENT_AVAILABILITY, torrent.distributedCopies()},
|
||||
|
||||
{KEY_TORRENT_TOTAL_SIZE, torrent.totalSize()}
|
||||
|
Loading…
Reference in New Issue
Block a user