WebAPI: Omit file names in parseMetadata response

This allows us to bypass any issues related to non-ascii file names.
This commit is contained in:
Thomas Piccirello 2025-08-10 10:19:39 -07:00
commit 6b1a88fc4d
No known key found for this signature in database
3 changed files with 11 additions and 12 deletions

View file

@ -10,6 +10,8 @@
* `torrents/editTracker` endpoint now supports setting a tracker's tier via `tier` parameter * `torrents/editTracker` endpoint now supports setting a tracker's tier via `tier` parameter
* `torrents/editTracker` endpoint always responds with a 204 when successful * `torrents/editTracker` endpoint always responds with a 204 when successful
* `torrents/editTracker` endpoint `origUrl` parameter renamed to `url` * `torrents/editTracker` endpoint `origUrl` parameter renamed to `url`
* [#23085](https://github.com/qbittorrent/qBittorrent/pull/23085)
* `torrents/parseMetadata` now responds with an array of metadata in the same order as the files in the request. It previously responded with an object keyed off of the submitted file name.
## 2.12.1 ## 2.12.1
* [#23031](https://github.com/qbittorrent/qBittorrent/pull/23031) * [#23031](https://github.com/qbittorrent/qBittorrent/pull/23031)

View file

@ -2099,16 +2099,14 @@ void TorrentsController::parseMetadataAction()
if (uploadedTorrents.isEmpty()) if (uploadedTorrents.isEmpty())
throw APIError(APIErrorType::BadParams, tr("Must specify torrent file(s)")); throw APIError(APIErrorType::BadParams, tr("Must specify torrent file(s)"));
QJsonObject result; QJsonArray result;
for (auto it = uploadedTorrents.constBegin(); it != uploadedTorrents.constEnd(); ++it) for (auto it = uploadedTorrents.constBegin(); it != uploadedTorrents.constEnd(); ++it)
{ {
if (const auto loadResult = BitTorrent::TorrentDescriptor::load(it.value())) if (const auto loadResult = BitTorrent::TorrentDescriptor::load(it.value()))
{ {
const BitTorrent::TorrentDescriptor &torrentDescr = loadResult.value(); const BitTorrent::TorrentDescriptor &torrentDescr = loadResult.value();
m_torrentMetadataCache.insert(torrentDescr.infoHash().toTorrentID(), torrentDescr); m_torrentMetadataCache.insert(torrentDescr.infoHash().toTorrentID(), torrentDescr);
result.append(serializeTorrentInfo(torrentDescr));
const QString &fileName = it.key();
result.insert(fileName, serializeTorrentInfo(torrentDescr));
} }
else else
{ {

View file

@ -175,9 +175,11 @@ window.qBittorrent.Client ??= (() => {
const uploadTorrentFiles = (files) => { const uploadTorrentFiles = (files) => {
const fileNames = []; const fileNames = [];
const formData = new FormData(); const formData = new FormData();
for (const file of files) { for (let i = 0; i < files.length; ++i) {
const file = files[i];
fileNames.push(file.name); fileNames.push(file.name);
formData.append("file", file); // send dummy file name as file name won't be used and may not be encoded properly
formData.append("file", file, i);
} }
fetch("api/v2/torrents/parseMetadata", { fetch("api/v2/torrents/parseMetadata", {
@ -191,12 +193,9 @@ window.qBittorrent.Client ??= (() => {
} }
const json = await response.json(); const json = await response.json();
for (const fileName of fileNames) { for (let i = 0; i < json.length; ++i) {
let title = fileName; const metadata = json[i];
const metadata = json[fileName]; const title = metadata.name || fileNames[i];
if (metadata !== undefined)
title = metadata.name;
const hash = metadata.infohash_v2 || metadata.infohash_v1; const hash = metadata.infohash_v2 || metadata.infohash_v1;
createAddTorrentWindow(title, hash, metadata); createAddTorrentWindow(title, hash, metadata);
} }