This commit is contained in:
Bark 2025-06-17 01:18:42 +05:00 committed by GitHub
commit 65c33f1109
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 75 additions and 26 deletions

View file

@ -1,5 +1,10 @@
# WebAPI Changelog # WebAPI Changelog
## 2.11.9
* [#22863](https://github.com/qbittorrent/qBittorrent/pull/22863)
* Introduce `torrents/bulkFiles`, accepts a list of `hash`es separated with `|` (pipe), returns list of files for all selected torrents
## 2.11.8 ## 2.11.8
* [#21349](https://github.com/qbittorrent/qBittorrent/pull/21349) * [#21349](https://github.com/qbittorrent/qBittorrent/pull/21349)

View file

@ -786,6 +786,46 @@ void TorrentsController::filesAction()
setResult(fileList); setResult(fileList);
} }
// Returns a list of all the files in the list of torrent in JSON format.
// The return value is a JSON-formatted list of dictionaries.
// The dictionary keys are:
// - "index": File index
// - "name": File name
// - "size": File size
// - "progress": File progress
// - "priority": File priority
// - "is_seed": Flag indicating if torrent is seeding/complete
// - "piece_range": Piece index range, the first number is the starting piece index
// and the second number is the ending piece index (inclusive)
// - "torrent_hash": The hash of the torrent from which this file originates
void TorrentsController::bulkFilesAction()
{
requireParams({u"hash"_s});
const auto ids = params()[u"hash"_s].split(u'|', Qt::SkipEmptyParts);
QVariantList fileList;
for (const QString &id : ids)
{
const BitTorrent::Torrent *torrent = BitTorrent::Session::instance()->getTorrent(BitTorrent::TorrentID::fromString(id));
if (!torrent)
continue;
if (!torrent->hasMetadata())
continue; // skip torrents without metadata
auto currentFileList = getFiles(torrent);
// Add torrent ID to each file
for (QJsonValueRef file : currentFileList)
{
QJsonObject fileObj = file.toObject();
fileObj[u"torrent_hash"] = torrent->id().toString();
file = fileObj;
}
fileList.append(currentFileList.toVariantList());
}
setResult(QJsonArray::fromVariantList(fileList));
}
// Returns an array of hashes (of each pieces respectively) for a torrent in JSON format. // Returns an array of hashes (of each pieces respectively) for a torrent in JSON format.
// The return value is a JSON-formatted array of strings (hex strings). // The return value is a JSON-formatted array of strings (hex strings).
void TorrentsController::pieceHashesAction() void TorrentsController::pieceHashesAction()

View file

@ -48,6 +48,7 @@ private slots:
void editWebSeedAction(); void editWebSeedAction();
void removeWebSeedsAction(); void removeWebSeedsAction();
void filesAction(); void filesAction();
void bulkFilesAction();
void pieceHashesAction(); void pieceHashesAction();
void pieceStatesAction(); void pieceStatesAction();
void startAction(); void startAction();

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, 8}; inline const Utils::Version<3, 2> API_VERSION {2, 11, 9};
class APIController; class APIController;
class AuthController; class AuthController;

View file

@ -298,7 +298,8 @@
path: file.name, path: file.name,
original: window.qBittorrent.Filesystem.fileName(file.name), original: window.qBittorrent.Filesystem.fileName(file.name),
renamed: "", renamed: "",
size: file.size size: file.size,
torrentHash: file.torrent_hash
}; };
return row; return row;
@ -375,7 +376,7 @@
}; };
const setupTable = (selectedRows) => { const setupTable = (selectedRows) => {
const url = new URL("api/v2/torrents/files", window.location); const url = new URL("api/v2/torrents/bulkFiles", window.location);
url.search = new URLSearchParams({ url.search = new URLSearchParams({
hash: data.hash hash: data.hash
}); });

View file

@ -397,7 +397,6 @@ window.qBittorrent.ContextMenu ??= (() => {
: this.hideItem("renameFiles"); : this.hideItem("renameFiles");
} }
else { else {
this.hideItem("renameFiles");
this.hideItem("rename"); this.hideItem("rename");
} }

View file

@ -740,15 +740,20 @@ const initializeWindows = () => {
renameFilesFN = () => { renameFilesFN = () => {
const hashes = torrentsTable.selectedRowsIds(); const hashes = torrentsTable.selectedRowsIds();
if (hashes.length === 1) { const hashList = hashes.join("|");
const hash = hashes[0]; const rows = [];
hashes.forEach((hash) => {
const row = torrentsTable.getRow(hash); const row = torrentsTable.getRow(hash);
if (row) { if (row)
rows.push(row);
});
if (rows.length === 0)
return;
new MochaUI.Window({ new MochaUI.Window({
id: "multiRenamePage", id: "multiRenamePage",
icon: "images/qbittorrent-tray.svg", icon: "images/qbittorrent-tray.svg",
title: "QBT_TR(Renaming)QBT_TR[CONTEXT=TransferListWidget]", title: "QBT_TR(Renaming)QBT_TR[CONTEXT=TransferListWidget]",
data: { hash: hash, selectedRows: [] }, data: { hash: hashList, selectedRows: rows },
loadMethod: "xhr", loadMethod: "xhr",
contentURL: "rename_files.html", contentURL: "rename_files.html",
scrollbars: false, scrollbars: false,
@ -760,8 +765,6 @@ const initializeWindows = () => {
height: 420, height: 420,
resizeLimit: { x: [800], y: [420] } resizeLimit: { x: [800], y: [420] }
}); });
}
}
}; };
startVisibleTorrentsFN = () => { startVisibleTorrentsFN = () => {

View file

@ -244,7 +244,7 @@ window.qBittorrent.MultiRename ??= (() => {
await fetch((isFolder ? "api/v2/torrents/renameFolder" : "api/v2/torrents/renameFile"), { await fetch((isFolder ? "api/v2/torrents/renameFolder" : "api/v2/torrents/renameFile"), {
method: "POST", method: "POST",
body: new URLSearchParams({ body: new URLSearchParams({
hash: this.hash, hash: match.data.torrentHash,
oldPath: oldPath, oldPath: oldPath,
newPath: newPath newPath: newPath
}) })