Skip to content

Commit 336366d

Browse files
authored
WebUI: add 'Copy path' action to torrent content menu
Supersedes #23934. PR #24678.
1 parent bdb3651 commit 336366d

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/webui/www/private/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ <h1>QBT_TR(JavaScript Required! You must enable JavaScript for the WebUI to work
287287
<ul id="torrentFilesMenu" class="contextMenu">
288288
<li><a href="#Rename"><img src="images/edit-rename.svg" alt="QBT_TR(Rename...)QBT_TR[CONTEXT=PropertiesWidget]"> QBT_TR(Rename...)QBT_TR[CONTEXT=PropertiesWidget]</a></li>
289289
<li><a href="#Download"><img src="images/download.svg" alt="QBT_TR(Download)QBT_TR[CONTEXT=PropertiesWidget]"> QBT_TR(Download)QBT_TR[CONTEXT=PropertiesWidget]</a></li>
290+
<li><a href="#CopyPath"><img src="images/edit-copy.svg" alt="QBT_TR(Copy path)QBT_TR[CONTEXT=PropertiesWidget]"> QBT_TR(Copy path)QBT_TR[CONTEXT=PropertiesWidget]</a></li>
290291
<li><a href="#CopyURL"><img src="images/edit-copy.svg" alt="QBT_TR(Copy URL)QBT_TR[CONTEXT=PropertiesWidget]"> QBT_TR(Copy URL)QBT_TR[CONTEXT=PropertiesWidget]</a></li>
291292
<li class="separator">
292293
<a href="#FilePrio" class="arrow-right"><span style="display: inline-block; width: 16px;"></span> QBT_TR(Priority)QBT_TR[CONTEXT=PropertiesWidget]</a>

src/webui/www/private/scripts/filesystem.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ window.qBittorrent.Filesystem ??= (() => {
3535
const exports = () => {
3636
return {
3737
PathSeparator: PathSeparator,
38+
ServerPathSeparator: ServerPathSeparator,
3839
fileExtension: fileExtension,
3940
fileName: fileName,
4041
folderName: folderName
@@ -43,6 +44,12 @@ window.qBittorrent.Filesystem ??= (() => {
4344

4445
const PathSeparator = "/";
4546

47+
/**
48+
* The native path separator used on the server
49+
*/
50+
const ServerPathSeparator = (window.qBittorrent?.Cache.buildInfo.get().platform === "windows")
51+
? "\\" : PathSeparator;
52+
4653
/**
4754
* Returns the file extension part of a file name.
4855
*/

src/webui/www/private/scripts/torrent-content.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,27 @@ window.qBittorrent.TorrentContent ??= (() => {
469469
const url = getSelectedFileUrl();
470470
await window.qBittorrent.Misc.downloadFileStream(url);
471471
},
472+
CopyPath: async (element, ref) => {
473+
const torrentID = torrentsTable.getCurrentTorrentID();
474+
const torrentRow = torrentsTable.getRow(torrentID);
475+
const savePath = torrentsTable.getRowData(torrentRow, true).save_path;
476+
477+
const files = [];
478+
for (const rowID of torrentFilesTable.selectedRowsIds()) {
479+
const names = [];
480+
for (let node = torrentFilesTable.getNode(rowID);; node = node.parent) {
481+
names.push(node.name);
482+
if (node.depth <= 0)
483+
break;
484+
}
485+
names.push(savePath);
486+
names.reverse();
487+
488+
files.push(names.join(window.qBittorrent.Filesystem.ServerPathSeparator));
489+
}
490+
491+
await clipboardCopy(files.join("\n"));
492+
},
472493
CopyURL: async (element, ref) => {
473494
const url = getSelectedFileUrl();
474495
await clipboardCopy(url);

0 commit comments

Comments
 (0)