TorrentSummary.getFileOrFolder

This commit is contained in:
DC
2016-07-15 02:31:59 -07:00
parent a489397f84
commit b950829de3
2 changed files with 14 additions and 3 deletions

View File

@@ -2,7 +2,8 @@ module.exports = {
getPosterPath,
getTorrentPath,
getByKey,
getTorrentID
getTorrentID,
getFileOrFolder
}
var path = require('path')
@@ -43,3 +44,13 @@ function getByKey (state, torrentKey) {
return state.saved.torrents.find((x) =>
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])
}