Use initialization form for variable

This commit is contained in:
Chocobo1 2024-01-06 15:04:30 +08:00
parent 54bcabeca4
commit 8bdb83d973

View file

@ -413,7 +413,7 @@ void TorrentsController::propertiesAction()
requireParams({u"hash"_s}); requireParams({u"hash"_s});
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_s]); const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_s]);
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); const BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id);
if (!torrent) if (!torrent)
throw APIError(APIErrorType::NotFound); throw APIError(APIErrorType::NotFound);
@ -422,61 +422,59 @@ void TorrentsController::propertiesAction()
return dateTime.isValid() ? dateTime.toSecsSinceEpoch() : -1; return dateTime.isValid() ? dateTime.toSecsSinceEpoch() : -1;
}; };
QJsonObject dataDict; const BitTorrent::InfoHash infoHash = torrent->infoHash();
const qlonglong totalDownload = torrent->totalDownload();
dataDict[KEY_TORRENT_INFOHASHV1] = torrent->infoHash().v1().toString(); const qlonglong totalUpload = torrent->totalUpload();
dataDict[KEY_TORRENT_INFOHASHV2] = torrent->infoHash().v2().toString();
dataDict[KEY_TORRENT_NAME] = torrent->name();
dataDict[KEY_TORRENT_ID] = torrent->id().toString();
dataDict[KEY_PROP_TIME_ELAPSED] = torrent->activeTime();
dataDict[KEY_PROP_SEEDING_TIME] = torrent->finishedTime();
dataDict[KEY_PROP_ETA] = torrent->eta();
dataDict[KEY_PROP_CONNECT_COUNT] = torrent->connectionsCount();
dataDict[KEY_PROP_CONNECT_COUNT_LIMIT] = torrent->connectionsLimit();
dataDict[KEY_PROP_DOWNLOADED] = torrent->totalDownload();
dataDict[KEY_PROP_DOWNLOADED_SESSION] = torrent->totalPayloadDownload();
dataDict[KEY_PROP_UPLOADED] = torrent->totalUpload();
dataDict[KEY_PROP_UPLOADED_SESSION] = torrent->totalPayloadUpload();
dataDict[KEY_PROP_DL_SPEED] = torrent->downloadPayloadRate();
const qlonglong dlDuration = torrent->activeTime() - torrent->finishedTime(); const qlonglong dlDuration = torrent->activeTime() - torrent->finishedTime();
dataDict[KEY_PROP_DL_SPEED_AVG] = torrent->totalDownload() / ((dlDuration == 0) ? -1 : dlDuration);
dataDict[KEY_PROP_UP_SPEED] = torrent->uploadPayloadRate();
const qlonglong ulDuration = torrent->activeTime(); const qlonglong ulDuration = torrent->activeTime();
dataDict[KEY_PROP_UP_SPEED_AVG] = torrent->totalUpload() / ((ulDuration == 0) ? -1 : ulDuration); const int downloadLimit = torrent->downloadLimit();
dataDict[KEY_PROP_DL_LIMIT] = torrent->downloadLimit() <= 0 ? -1 : torrent->downloadLimit(); const int uploadLimit = torrent->uploadLimit();
dataDict[KEY_PROP_UP_LIMIT] = torrent->uploadLimit() <= 0 ? -1 : torrent->uploadLimit();
dataDict[KEY_PROP_WASTED] = torrent->wastedSize();
dataDict[KEY_PROP_SEEDS] = torrent->seedsCount();
dataDict[KEY_PROP_SEEDS_TOTAL] = torrent->totalSeedsCount();
dataDict[KEY_PROP_PEERS] = torrent->leechsCount();
dataDict[KEY_PROP_PEERS_TOTAL] = torrent->totalLeechersCount();
const qreal ratio = torrent->realRatio(); const qreal ratio = torrent->realRatio();
dataDict[KEY_PROP_RATIO] = ratio > BitTorrent::Torrent::MAX_RATIO ? -1 : ratio;
dataDict[KEY_PROP_REANNOUNCE] = torrent->nextAnnounce();
dataDict[KEY_PROP_TOTAL_SIZE] = torrent->totalSize();
dataDict[KEY_PROP_PIECES_NUM] = torrent->piecesCount();
dataDict[KEY_PROP_PIECE_SIZE] = torrent->pieceLength();
dataDict[KEY_PROP_PIECES_HAVE] = torrent->piecesHave();
dataDict[KEY_PROP_CREATED_BY] = torrent->creator();
dataDict[KEY_PROP_ISPRIVATE] = torrent->isPrivate();
dataDict[KEY_PROP_ADDITION_DATE] = toTimeStamp(torrent->addedTime());
if (torrent->hasMetadata())
{
dataDict[KEY_PROP_LAST_SEEN] = toTimeStamp(torrent->lastSeenComplete());
dataDict[KEY_PROP_COMPLETION_DATE] = toTimeStamp(torrent->completedTime());
dataDict[KEY_PROP_CREATION_DATE] = toTimeStamp(torrent->creationDate());
}
else
{
dataDict[KEY_PROP_LAST_SEEN] = -1;
dataDict[KEY_PROP_COMPLETION_DATE] = -1;
dataDict[KEY_PROP_CREATION_DATE] = -1;
}
dataDict[KEY_PROP_SAVE_PATH] = torrent->savePath().toString();
dataDict[KEY_PROP_DOWNLOAD_PATH] = torrent->downloadPath().toString();
dataDict[KEY_PROP_COMMENT] = torrent->comment();
setResult(dataDict); const QJsonObject ret
{
{KEY_TORRENT_INFOHASHV1, infoHash.v1().toString()},
{KEY_TORRENT_INFOHASHV2, infoHash.v2().toString()},
{KEY_TORRENT_NAME, torrent->name()},
{KEY_TORRENT_ID, torrent->id().toString()},
{KEY_PROP_TIME_ELAPSED, torrent->activeTime()},
{KEY_PROP_SEEDING_TIME, torrent->finishedTime()},
{KEY_PROP_ETA, torrent->eta()},
{KEY_PROP_CONNECT_COUNT, torrent->connectionsCount()},
{KEY_PROP_CONNECT_COUNT_LIMIT, torrent->connectionsLimit()},
{KEY_PROP_DOWNLOADED, totalDownload},
{KEY_PROP_DOWNLOADED_SESSION, torrent->totalPayloadDownload()},
{KEY_PROP_UPLOADED, totalUpload},
{KEY_PROP_UPLOADED_SESSION, torrent->totalPayloadUpload()},
{KEY_PROP_DL_SPEED, torrent->downloadPayloadRate()},
{KEY_PROP_DL_SPEED_AVG, ((dlDuration > 0) ? (totalDownload / dlDuration) : -1)},
{KEY_PROP_UP_SPEED, torrent->uploadPayloadRate()},
{KEY_PROP_UP_SPEED_AVG, ((ulDuration > 0) ? (totalUpload / ulDuration) : -1)},
{KEY_PROP_DL_LIMIT, ((downloadLimit > 0) ? downloadLimit : -1)},
{KEY_PROP_UP_LIMIT, ((uploadLimit > 0) ? uploadLimit : -1)},
{KEY_PROP_WASTED, torrent->wastedSize()},
{KEY_PROP_SEEDS, torrent->seedsCount()},
{KEY_PROP_SEEDS_TOTAL, torrent->totalSeedsCount()},
{KEY_PROP_PEERS, torrent->leechsCount()},
{KEY_PROP_PEERS_TOTAL, torrent->totalLeechersCount()},
{KEY_PROP_RATIO, ((ratio > BitTorrent::Torrent::MAX_RATIO) ? -1 : ratio)},
{KEY_PROP_REANNOUNCE, torrent->nextAnnounce()},
{KEY_PROP_TOTAL_SIZE, torrent->totalSize()},
{KEY_PROP_PIECES_NUM, torrent->piecesCount()},
{KEY_PROP_PIECE_SIZE, torrent->pieceLength()},
{KEY_PROP_PIECES_HAVE, torrent->piecesHave()},
{KEY_PROP_CREATED_BY, torrent->creator()},
{KEY_PROP_ISPRIVATE, torrent->isPrivate()},
{KEY_PROP_ADDITION_DATE, toTimeStamp(torrent->addedTime())},
{KEY_PROP_LAST_SEEN, toTimeStamp(torrent->lastSeenComplete())},
{KEY_PROP_COMPLETION_DATE, toTimeStamp(torrent->completedTime())},
{KEY_PROP_CREATION_DATE, toTimeStamp(torrent->creationDate())},
{KEY_PROP_SAVE_PATH, torrent->savePath().toString()},
{KEY_PROP_DOWNLOAD_PATH, torrent->downloadPath().toString()},
{KEY_PROP_COMMENT, torrent->comment()}
};
setResult(ret);
} }
// Returns the trackers for a torrent in JSON format. // Returns the trackers for a torrent in JSON format.