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
## 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
* [#21349](https://github.com/qbittorrent/qBittorrent/pull/21349)

View file

@ -786,6 +786,46 @@ void TorrentsController::filesAction()
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.
// The return value is a JSON-formatted array of strings (hex strings).
void TorrentsController::pieceHashesAction()

View file

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

View file

@ -53,7 +53,7 @@
#include "base/utils/version.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 AuthController;

View file

@ -298,7 +298,8 @@
path: file.name,
original: window.qBittorrent.Filesystem.fileName(file.name),
renamed: "",
size: file.size
size: file.size,
torrentHash: file.torrent_hash
};
return row;
@ -375,7 +376,7 @@
};
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({
hash: data.hash
});

View file

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

View file

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

View file

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