Skip to content

Commit

Permalink
fileDelete
Browse files Browse the repository at this point in the history
  • Loading branch information
ManiMatter committed Aug 23, 2024
1 parent a91bac8 commit 95ec9a3
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/base/bittorrent/torrentimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,17 @@ void TorrentImpl::renameFile(const int index, const Path &path)
doRenameFile(index, targetActualPath);
}

// void TorrentImpl::removeFile(const int index)
// {
// Q_ASSERT((index >= 0) && (index < filesCount()));
// if ((index < 0) || (index >= filesCount())) [[unlikely]]
// return;

// const Path filePath = filePath(index);
// const Path targetActualPath = makeActualPath(index, filePath);
// doRemoveFile(index, targetActualPath);
// }

void TorrentImpl::handleStateUpdate(const lt::torrent_status &nativeStatus)
{
updateStatus(nativeStatus);
Expand Down Expand Up @@ -2526,6 +2537,19 @@ void TorrentImpl::doRenameFile(const int index, const Path &path)
m_nativeHandle.rename_file(nativeIndexes[index], path.toString().toStdString());
}

// void TorrentImpl::doRemoveFile(const int index, const Path &path)
// {
// const QList<lt::file_index_t> nativeIndexes = m_torrentInfo.nativeIndexes();

// Q_ASSERT(index >= 0);
// Q_ASSERT(index < nativeIndexes.size());
// if ((index < 0) || (index >= nativeIndexes.size())) [[unlikely]]
// return;

// ++m_renameCount;
// m_nativeHandle.rename_file(nativeIndexes[index], path.toString().toStdString());
// }

lt::torrent_handle TorrentImpl::nativeHandle() const
{
return m_nativeHandle;
Expand Down
2 changes: 2 additions & 0 deletions src/base/bittorrent/torrentimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ namespace BitTorrent
void forceDHTAnnounce() override;
void forceRecheck() override;
void renameFile(int index, const Path &path) override;
// void removeFile(int index) override;
void prioritizeFiles(const QList<DownloadPriority> &priorities) override;
void setUploadLimit(int limit) override;
void setDownloadLimit(int limit) override;
Expand Down Expand Up @@ -315,6 +316,7 @@ namespace BitTorrent
Path makeUserPath(const Path &path) const;
void adjustStorageLocation();
void doRenameFile(int index, const Path &path);
// void doRemoveFile(int index, const Path &path);
void moveStorage(const Path &newPath, MoveStorageContext context);
void manageActualFilePaths();
void applyFirstLastPiecePriority(bool enabled);
Expand Down
35 changes: 35 additions & 0 deletions src/webui/api/torrentscontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,41 @@ void TorrentsController::filePrioAction()
torrent->prioritizeFiles(priorities);
}

void TorrentsController::removeFileAction()
{
requireParams({u"hash"_s, u"id"_s});

const auto torrentId = BitTorrent::TorrentID::fromString(params()[u"hash"_s]);
bool ok = false;

BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(torrentId);
if (!torrent)
throw APIError(APIErrorType::NotFound);
if (!torrent->hasMetadata())
throw APIError(APIErrorType::Conflict, tr("Torrent's metadata has not yet downloaded"));

const int filesCount = torrent->filesCount();
for (const QString &fileID : params()[u"id"_s].split(u'|'))
{
const int fileId = fileID.toInt(&ok);
if (!ok)
throw APIError(APIErrorType::BadParams, tr("File IDs must be integers"));
if ((fileId < 0) || (fileId >= filesCount))
throw APIError(APIErrorType::Conflict, tr("File ID is not valid"));

try
{
throw APIError(APIErrorType::Conflict, tr("Debugging: The below command is not working"));
// torrent->removeFile(fileId);
}
catch (const RuntimeError &error)
{
throw APIError(APIErrorType::Conflict, error.message());
}

}
}

void TorrentsController::uploadLimitAction()
{
requireParams({u"hashes"_s});
Expand Down
1 change: 1 addition & 0 deletions src/webui/api/torrentscontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private slots:
void removeTrackersAction();
void addPeersAction();
void filePrioAction();
void removeFileAction();
void uploadLimitAction();
void downloadLimitAction();
void setUploadLimitAction();
Expand Down
3 changes: 2 additions & 1 deletion src/webui/webapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#include "base/utils/version.h"
#include "api/isessionmanager.h"

inline const Utils::Version<3, 2> API_VERSION {2, 11, 3};
inline const Utils::Version<3, 2> API_VERSION {2, 11, 4};

class QTimer;

Expand Down Expand Up @@ -198,6 +198,7 @@ class WebApplication final : public ApplicationComponent<QObject>
{{u"torrents"_s, u"removeWebSeeds"_s}, Http::METHOD_POST},
{{u"torrents"_s, u"rename"_s}, Http::METHOD_POST},
{{u"torrents"_s, u"renameFile"_s}, Http::METHOD_POST},
{{u"torrents"_s, u"removeFile"_s}, Http::METHOD_POST},
{{u"torrents"_s, u"renameFolder"_s}, Http::METHOD_POST},
{{u"torrents"_s, u"setAutoManagement"_s}, Http::METHOD_POST},
{{u"torrents"_s, u"setCategory"_s}, Http::METHOD_POST},
Expand Down
24 changes: 23 additions & 1 deletion src/webui/www/private/scripts/prop-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,28 @@ window.qBittorrent.PropFiles ??= (() => {
return true;
};

const removeFile = function(ids, fileIds) {
if (current_hash === "")
return;

clearTimeout(loadTorrentFilesDataTimer);
loadTorrentFilesDataTimer = -1;

new Request({
url: "api/v2/torrents/removeFile",
method: "post",
data: {
"hash": current_hash,
"id": fileIds.join("|")
},
onComplete: function() {
loadTorrentFilesDataTimer = loadTorrentFilesData.delay(1000);
}
}).send();
torrentFilesTable.updateTable(false);
};


const setFilePriority = function(ids, fileIds, priority) {
if (current_hash === "")
return;
Expand Down Expand Up @@ -545,7 +567,7 @@ window.qBittorrent.PropFiles ??= (() => {

new MochaUI.Window({
id: "renamePage",
icon: "images/qbittorrent-tray.svg",
icon: "images/qbittorrent- y.svg",
title: "QBT_TR(Renaming)QBT_TR[CONTEXT=TorrentContentTreeView]",
loadMethod: "iframe",
contentURL: "rename_file.html?hash=" + hash + "&isFolder=" + node.isFolder
Expand Down

0 comments on commit 95ec9a3

Please sign in to comment.