client: add "Download .torrent" context menu item

This commit is contained in:
Jesse Chan
2020-12-28 17:13:45 +08:00
parent 1a0f3d0b45
commit a9e85ee7d7
5 changed files with 47 additions and 22 deletions

View File

@@ -31,19 +31,6 @@ const InlineTorrentPropertyCheckbox: FC<{property: keyof TorrentProperties}> = o
),
);
const handleTorrentDownload = (hash: TorrentProperties['hash']): void => {
const {baseURI} = ConfigStore;
const link = document.createElement('a');
link.download = '';
link.href = `${baseURI}api/torrents/${hash}/contents/all/data`;
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
const getContextMenuItems = (torrent: TorrentProperties): Array<ContextMenuItem> => {
const changePriorityFuncRef = createRef<() => number>();
@@ -129,11 +116,38 @@ const getContextMenuItems = (torrent: TorrentProperties): Array<ContextMenuItem>
},
{
type: 'action',
action: 'torrentDownload',
label: TorrentContextMenuActions.torrentDownload.id,
action: 'downloadContents',
label: TorrentContextMenuActions.downloadContents.id,
clickHandler: (e) => {
e.preventDefault();
handleTorrentDownload(getLastSelectedTorrent());
const link = document.createElement('a');
link.download = '';
link.href = `${ConfigStore.baseURI}api/torrents/${getLastSelectedTorrent()}/contents/all/data`;
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
},
},
{
type: 'action',
action: 'downloadMetainfo',
label: TorrentContextMenuActions.downloadMetainfo.id,
clickHandler: (e) => {
e.preventDefault();
const link = document.createElement('a');
link.download = '';
link.href = `${ConfigStore.baseURI}api/torrents/${TorrentStore.selectedTorrents.join(',')}/metainfo`;
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
},
},
{

View File

@@ -23,8 +23,11 @@ const TorrentContextMenuActions = {
torrentDetails: {
id: 'torrents.list.context.details',
},
torrentDownload: {
id: 'torrents.list.context.download',
downloadContents: {
id: 'torrents.list.context.download.contents',
},
downloadMetainfo: {
id: 'torrents.list.context.download.metainfo',
},
generateMagnet: {
id: 'torrents.list.context.generate.magnet',

View File

@@ -2209,10 +2209,16 @@
"value": "Torrent Details"
}
],
"torrents.list.context.download": [
"torrents.list.context.download.contents": [
{
"type": 0,
"value": "Download"
"value": "Download Contents"
}
],
"torrents.list.context.download.metainfo": [
{
"type": 0,
"value": "Download .torrent"
}
],
"torrents.list.context.generate.magnet": [

View File

@@ -316,7 +316,8 @@
"torrents.list.context.generate.magnet": "Generate Magnet Link",
"torrents.list.context.move": "Set Torrent Location",
"torrents.list.context.pause": "Pause",
"torrents.list.context.download": "Download",
"torrents.list.context.download.contents": "Download Contents",
"torrents.list.context.download.metainfo": "Download .torrent",
"torrents.list.context.initial.seeding": "Initial Seeding",
"torrents.list.context.priority": "Priority",
"torrents.list.context.remove": "Remove",

View File

@@ -57,7 +57,8 @@ const defaultFloodSettings: Readonly<FloodSettings> = {
{id: 'move', visible: true},
{id: 'setTrackers', visible: false},
{id: 'torrentDetails', visible: true},
{id: 'torrentDownload', visible: true},
{id: 'downloadContents', visible: true},
{id: 'downloadMetainfo', visible: false},
{id: 'generateMagnet', visible: false},
{id: 'setInitialSeeding', visible: false},
{id: 'setSequential', visible: false},