WebUI: Implement Share limit action

PR #22989.
Closes #22984.
This commit is contained in:
Mark Yu 2025-07-20 04:39:31 -04:00 committed by GitHub
commit 8f709b5fbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 41 additions and 8 deletions

View file

@ -1,5 +1,12 @@
# WebAPI Changelog # WebAPI Changelog
## 2.12.0
* [#22989](https://github.com/qbittorrent/qBittorrent/pull/22989)
* `sync/maindata` returns one new field: `share_limit_action`
* `torrents/setShareLimits` now requires a new `shareLimitAction` param that sets a torrent's shareLimitAction property
* possible values `Default`, `Stop`, `Remove`, `RemoveWithContent` and `EnableSuperSeeding`
## 2.11.10 ## 2.11.10
* [#22932](https://github.com/qbittorrent/qBittorrent/pull/22932) * [#22932](https://github.com/qbittorrent/qBittorrent/pull/22932)

View file

@ -171,6 +171,7 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent)
{KEY_TORRENT_POPULARITY, torrent.popularity()}, {KEY_TORRENT_POPULARITY, torrent.popularity()},
{KEY_TORRENT_SEEDING_TIME_LIMIT, torrent.seedingTimeLimit()}, {KEY_TORRENT_SEEDING_TIME_LIMIT, torrent.seedingTimeLimit()},
{KEY_TORRENT_INACTIVE_SEEDING_TIME_LIMIT, torrent.inactiveSeedingTimeLimit()}, {KEY_TORRENT_INACTIVE_SEEDING_TIME_LIMIT, torrent.inactiveSeedingTimeLimit()},
{KEY_TORRENT_SHARE_LIMIT_ACTION, Utils::String::fromEnum(torrent.shareLimitAction())},
{KEY_TORRENT_LAST_SEEN_COMPLETE_TIME, Utils::DateTime::toSecsSinceEpoch(torrent.lastSeenComplete())}, {KEY_TORRENT_LAST_SEEN_COMPLETE_TIME, Utils::DateTime::toSecsSinceEpoch(torrent.lastSeenComplete())},
{KEY_TORRENT_AUTO_TORRENT_MANAGEMENT, torrent.isAutoTMMEnabled()}, {KEY_TORRENT_AUTO_TORRENT_MANAGEMENT, torrent.isAutoTMMEnabled()},
{KEY_TORRENT_TIME_ACTIVE, torrent.activeTime()}, {KEY_TORRENT_TIME_ACTIVE, torrent.activeTime()},

View file

@ -85,6 +85,7 @@ inline const QString KEY_TORRENT_MAX_INACTIVE_SEEDING_TIME = u"max_inactive_seed
inline const QString KEY_TORRENT_RATIO_LIMIT = u"ratio_limit"_s; inline const QString KEY_TORRENT_RATIO_LIMIT = u"ratio_limit"_s;
inline const QString KEY_TORRENT_SEEDING_TIME_LIMIT = u"seeding_time_limit"_s; inline const QString KEY_TORRENT_SEEDING_TIME_LIMIT = u"seeding_time_limit"_s;
inline const QString KEY_TORRENT_INACTIVE_SEEDING_TIME_LIMIT = u"inactive_seeding_time_limit"_s; inline const QString KEY_TORRENT_INACTIVE_SEEDING_TIME_LIMIT = u"inactive_seeding_time_limit"_s;
inline const QString KEY_TORRENT_SHARE_LIMIT_ACTION = u"share_limit_action"_s;
inline const QString KEY_TORRENT_LAST_SEEN_COMPLETE_TIME = u"seen_complete"_s; inline const QString KEY_TORRENT_LAST_SEEN_COMPLETE_TIME = u"seen_complete"_s;
inline const QString KEY_TORRENT_LAST_ACTIVITY_TIME = u"last_activity"_s; inline const QString KEY_TORRENT_LAST_ACTIVITY_TIME = u"last_activity"_s;
inline const QString KEY_TORRENT_TOTAL_SIZE = u"total_size"_s; inline const QString KEY_TORRENT_TOTAL_SIZE = u"total_size"_s;

View file

@ -497,6 +497,7 @@ void SyncController::updateFreeDiskSpace(const qint64 freeDiskSpace)
// - "max_seeding_time": Upload max seeding time // - "max_seeding_time": Upload max seeding time
// - "ratio_limit": Upload share ratio limit // - "ratio_limit": Upload share ratio limit
// - "seeding_time_limit": Upload seeding time limit // - "seeding_time_limit": Upload seeding time limit
// - "share_limit_action": Action to execute when the limit is reached
// - "seen_complete": Indicates the time when the torrent was last seen complete/whole // - "seen_complete": Indicates the time when the torrent was last seen complete/whole
// - "last_activity": Last time when a chunk was downloaded/uploaded // - "last_activity": Last time when a chunk was downloaded/uploaded
// - "total_size": Size including unwanted data // - "total_size": Size including unwanted data

View file

@ -1360,18 +1360,21 @@ void TorrentsController::setDownloadLimitAction()
void TorrentsController::setShareLimitsAction() void TorrentsController::setShareLimitsAction()
{ {
requireParams({u"hashes"_s, u"ratioLimit"_s, u"seedingTimeLimit"_s, u"inactiveSeedingTimeLimit"_s}); requireParams({u"hashes"_s, u"ratioLimit"_s, u"seedingTimeLimit"_s, u"inactiveSeedingTimeLimit"_s, u"shareLimitAction"_s});
const qreal ratioLimit = params()[u"ratioLimit"_s].toDouble(); const qreal ratioLimit = params()[u"ratioLimit"_s].toDouble();
const qlonglong seedingTimeLimit = params()[u"seedingTimeLimit"_s].toLongLong(); const qlonglong seedingTimeLimit = params()[u"seedingTimeLimit"_s].toLongLong();
const qlonglong inactiveSeedingTimeLimit = params()[u"inactiveSeedingTimeLimit"_s].toLongLong(); const qlonglong inactiveSeedingTimeLimit = params()[u"inactiveSeedingTimeLimit"_s].toLongLong();
const BitTorrent::ShareLimitAction shareLimitAction = Utils::String::toEnum(params()[u"shareLimitAction"_s], BitTorrent::ShareLimitAction::Default);
const QStringList hashes = params()[u"hashes"_s].split(u'|'); const QStringList hashes = params()[u"hashes"_s].split(u'|');
applyToTorrents(hashes, [ratioLimit, seedingTimeLimit, inactiveSeedingTimeLimit](BitTorrent::Torrent *const torrent) applyToTorrents(hashes, [ratioLimit, seedingTimeLimit, inactiveSeedingTimeLimit, shareLimitAction](BitTorrent::Torrent *const torrent)
{ {
torrent->setRatioLimit(ratioLimit); torrent->setRatioLimit(ratioLimit);
torrent->setSeedingTimeLimit(seedingTimeLimit); torrent->setSeedingTimeLimit(seedingTimeLimit);
torrent->setInactiveSeedingTimeLimit(inactiveSeedingTimeLimit); torrent->setInactiveSeedingTimeLimit(inactiveSeedingTimeLimit);
torrent->setShareLimitAction(shareLimitAction);
}); });
setResult(QString()); setResult(QString());

View file

@ -53,7 +53,7 @@
#include "base/utils/version.h" #include "base/utils/version.h"
#include "api/isessionmanager.h" #include "api/isessionmanager.h"
inline const Utils::Version<3, 2> API_VERSION {2, 11, 10}; inline const Utils::Version<3, 2> API_VERSION {2, 12, 0};
class APIController; class APIController;
class AuthController; class AuthController;

View file

@ -385,7 +385,7 @@ const initializeWindows = () => {
const hash = hashes[i]; const hash = hashes[i];
const row = torrentsTable.getRow(hash).full_data; const row = torrentsTable.getRow(hash).full_data;
const origValues = `${row.ratio_limit}|${row.seeding_time_limit}|${row.inactive_seeding_time_limit}|${row.max_ratio}` const origValues = `${row.ratio_limit}|${row.seeding_time_limit}|${row.inactive_seeding_time_limit}|${row.max_ratio}`
+ `|${row.max_seeding_time}|${row.max_inactive_seeding_time}`; + `|${row.max_seeding_time}|${row.max_inactive_seeding_time}|${row.share_limit_action}`;
// initialize value // initialize value
if (shareRatio === null) if (shareRatio === null)
@ -414,8 +414,8 @@ const initializeWindows = () => {
maximizable: false, maximizable: false,
paddingVertical: 0, paddingVertical: 0,
paddingHorizontal: 0, paddingHorizontal: 0,
width: window.qBittorrent.Dialog.limitWidthToViewport(424), width: window.qBittorrent.Dialog.limitWidthToViewport(500),
height: 220 height: 250
}); });
}; };

View file

@ -12,8 +12,11 @@
const UseGlobalLimit = -2; const UseGlobalLimit = -2;
const NoLimit = -1; const NoLimit = -1;
let limitReachedActionsEl;
window.addEventListener("DOMContentLoaded", (event) => { window.addEventListener("DOMContentLoaded", (event) => {
limitReachedActionsEl = document.getElementById("limitReachedActions");
window.addEventListener("keydown", (event) => { window.addEventListener("keydown", (event) => {
switch (event.key) { switch (event.key) {
case "Enter": case "Enter":
@ -36,7 +39,8 @@
inactiveSeedingTimeLimit: Number(origValues[2]), inactiveSeedingTimeLimit: Number(origValues[2]),
maxRatio: Number(origValues[3]), maxRatio: Number(origValues[3]),
maxSeedingTime: Number(origValues[4]), maxSeedingTime: Number(origValues[4]),
maxInactiveSeedingTime: Number(origValues[5]) maxInactiveSeedingTime: Number(origValues[5]),
shareLimitAction: String(origValues[6])
}; };
// select default when orig values not passed. using double equals to compare string and int // select default when orig values not passed. using double equals to compare string and int
@ -65,6 +69,8 @@
document.getElementById("setInactiveMinutes").checked = true; document.getElementById("setInactiveMinutes").checked = true;
document.getElementById("inactiveMinutes").value = values.inactiveSeedingTimeLimit; document.getElementById("inactiveMinutes").value = values.inactiveSeedingTimeLimit;
} }
limitReachedActionsEl.value = values.shareLimitAction;
} }
shareLimitChanged(); shareLimitChanged();
@ -81,6 +87,7 @@
let ratioLimitValue = 0.00; let ratioLimitValue = 0.00;
let seedingTimeLimitValue = 0; let seedingTimeLimitValue = 0;
let inactiveSeedingTimeLimitValue = 0; let inactiveSeedingTimeLimitValue = 0;
let shareLimitActionValue = "Default";
if (shareLimit === "default") { if (shareLimit === "default") {
ratioLimitValue = seedingTimeLimitValue = inactiveSeedingTimeLimitValue = UseGlobalLimit; ratioLimitValue = seedingTimeLimitValue = inactiveSeedingTimeLimitValue = UseGlobalLimit;
@ -92,6 +99,7 @@
ratioLimitValue = document.getElementById("setRatio").checked ? document.getElementById("ratio").value : -1; ratioLimitValue = document.getElementById("setRatio").checked ? document.getElementById("ratio").value : -1;
seedingTimeLimitValue = document.getElementById("setTotalMinutes").checked ? document.getElementById("totalMinutes").value : -1; seedingTimeLimitValue = document.getElementById("setTotalMinutes").checked ? document.getElementById("totalMinutes").value : -1;
inactiveSeedingTimeLimitValue = document.getElementById("setInactiveMinutes").checked ? document.getElementById("inactiveMinutes").value : -1; inactiveSeedingTimeLimitValue = document.getElementById("setInactiveMinutes").checked ? document.getElementById("inactiveMinutes").value : -1;
shareLimitActionValue = limitReachedActionsEl.value;
} }
else { else {
return; return;
@ -103,7 +111,8 @@
hashes: searchParams.get("hashes"), hashes: searchParams.get("hashes"),
ratioLimit: ratioLimitValue, ratioLimit: ratioLimitValue,
seedingTimeLimit: seedingTimeLimitValue, seedingTimeLimit: seedingTimeLimitValue,
inactiveSeedingTimeLimit: inactiveSeedingTimeLimitValue inactiveSeedingTimeLimit: inactiveSeedingTimeLimitValue,
shareLimitAction: shareLimitActionValue
}) })
}) })
.then((response) => { .then((response) => {
@ -140,6 +149,7 @@
document.getElementById("setRatio").disabled = !customShareLimit; document.getElementById("setRatio").disabled = !customShareLimit;
document.getElementById("setTotalMinutes").disabled = !customShareLimit; document.getElementById("setTotalMinutes").disabled = !customShareLimit;
document.getElementById("setInactiveMinutes").disabled = !customShareLimit; document.getElementById("setInactiveMinutes").disabled = !customShareLimit;
limitReachedActionsEl.disabled = !customShareLimit;
enableInputBoxes(); enableInputBoxes();
@ -182,6 +192,16 @@
<label id="inactiveMinutesLabel" for="setInactiveMinutes">QBT_TR(inactive minutes)QBT_TR[CONTEXT=UpDownRatioDialog]</label> <label id="inactiveMinutesLabel" for="setInactiveMinutes">QBT_TR(inactive minutes)QBT_TR[CONTEXT=UpDownRatioDialog]</label>
<input type="number" id="inactiveMinutes" value="0" step="1" min="0" class="shareLimitInput" aria-labelledby="inactiveMinutesLabel"> <input type="number" id="inactiveMinutes" value="0" step="1" min="0" class="shareLimitInput" aria-labelledby="inactiveMinutesLabel">
</div> </div>
<div style="margin-left: 40px; margin-bottom: 5px;">
<label id="actionListLabel" for="limitReachedActions">QBT_TR(Action when the limit is reached)QBT_TR[CONTEXT=UpDownRatioDialog]</label>
<select id="limitReachedActions" aria-labelledby="actionListLabel">
<option value="Default">QBT_TR(Default)QBT_TR[CONTEXT=UpDownRatioDialog]</option>
<option value="Stop">QBT_TR(Stop torrent)QBT_TR[CONTEXT=UpDownRatioDialog]</option>
<option value="Remove">QBT_TR(Remove torrent)QBT_TR[CONTEXT=UpDownRatioDialog]</option>
<option value="RemoveWithContent">QBT_TR(Remove torrent and its content)QBT_TR[CONTEXT=UpDownRatioDialog]</option>
<option value="EnableSuperSeeding">QBT_TR(Enable super seeding for torrent)QBT_TR[CONTEXT=UpDownRatioDialog]</option>
</select>
</div>
<div style="text-align: center; padding-top: 10px;"> <div style="text-align: center; padding-top: 10px;">
<input type="button" value="QBT_TR(Save)QBT_TR[CONTEXT=HttpServer]" id="save"> <input type="button" value="QBT_TR(Save)QBT_TR[CONTEXT=HttpServer]" id="save">
</div> </div>