TorrentSummary.getFileOrFolder
This commit is contained in:
@@ -245,7 +245,7 @@ function deleteFile (path) {
|
|||||||
|
|
||||||
// Delete all files in a torrent
|
// Delete all files in a torrent
|
||||||
function moveItemToTrash (torrentSummary) {
|
function moveItemToTrash (torrentSummary) {
|
||||||
var filePath = path.join(torrentSummary.path, torrentSummary.files[0].path.split('/')[0])
|
var filePath = TorrentSummary.getFileOrFolder(torrentSummary)
|
||||||
ipcRenderer.send('moveItemToTrash', filePath)
|
ipcRenderer.send('moveItemToTrash', filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,7 +255,7 @@ function showItemInFolder (torrentSummary) {
|
|||||||
|
|
||||||
function saveTorrentFileAs (torrentSummary) {
|
function saveTorrentFileAs (torrentSummary) {
|
||||||
var downloadPath = this.state.saved.prefs.downloadPath
|
var downloadPath = this.state.saved.prefs.downloadPath
|
||||||
var newFileName = `${path.parse(torrentSummary.name).name}.torrent`
|
var newFileName = path.parse(torrentSummary.name).name + '.torrent'
|
||||||
var opts = {
|
var opts = {
|
||||||
title: 'Save Torrent File',
|
title: 'Save Torrent File',
|
||||||
defaultPath: path.join(downloadPath, newFileName),
|
defaultPath: path.join(downloadPath, newFileName),
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ module.exports = {
|
|||||||
getPosterPath,
|
getPosterPath,
|
||||||
getTorrentPath,
|
getTorrentPath,
|
||||||
getByKey,
|
getByKey,
|
||||||
getTorrentID
|
getTorrentID,
|
||||||
|
getFileOrFolder
|
||||||
}
|
}
|
||||||
|
|
||||||
var path = require('path')
|
var path = require('path')
|
||||||
@@ -43,3 +44,13 @@ function getByKey (state, torrentKey) {
|
|||||||
return state.saved.torrents.find((x) =>
|
return state.saved.torrents.find((x) =>
|
||||||
x.torrentKey === torrentKey || x.infoHash === torrentKey)
|
x.torrentKey === torrentKey || x.infoHash === torrentKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the path to either the file (in a single-file torrent) or the root
|
||||||
|
// folder (in multi-file torrent)
|
||||||
|
// WARNING: assumes that multi-file torrents consist of a SINGLE folder.
|
||||||
|
// TODO: make this assumption explicit, enforce it in the `create-torrent`
|
||||||
|
// module. Store root folder explicitly to avoid hacky path processing below.
|
||||||
|
function getFileOrFolder (torrentSummary) {
|
||||||
|
var ts = torrentSummary
|
||||||
|
return path.join(ts.path, ts.files[0].path.split('/')[0])
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user