Refactor main.js: torrent list controller
This commit is contained in:
@@ -116,6 +116,12 @@ function getApproxNumTorrents (state) {
|
||||
|
||||
// An uncaught error happened in the main process or in one of the windows
|
||||
function logUncaughtError (procName, err) {
|
||||
console.error('uncaught error', procName, err)
|
||||
|
||||
// Not initialized yet? Ignore.
|
||||
// Hopefully uncaught errors immediately on startup are fixed in dev
|
||||
if (!telemetry) return
|
||||
|
||||
var message, stack
|
||||
if (typeof err === 'string') {
|
||||
message = err
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
module.exports = {
|
||||
getPosterPath,
|
||||
getTorrentPath
|
||||
getTorrentPath,
|
||||
getByKey,
|
||||
getTorrentID
|
||||
}
|
||||
|
||||
var path = require('path')
|
||||
@@ -22,3 +24,22 @@ function getPosterPath (torrentSummary) {
|
||||
// Backslashes in URLS in CSS cause bizarre string encoding issues
|
||||
return posterPath.replace(/\\/g, '/')
|
||||
}
|
||||
|
||||
// Expects a torrentSummary
|
||||
// Returns a torrentID: filename, magnet URI, or infohash
|
||||
function getTorrentID (torrentSummary) {
|
||||
var s = torrentSummary
|
||||
if (s.torrentFileName) { // Load torrent file from disk
|
||||
return getTorrentPath(s)
|
||||
} else { // Load torrent from DHT
|
||||
return s.magnetURI || s.infoHash
|
||||
}
|
||||
}
|
||||
|
||||
// Expects a torrentKey or infoHash
|
||||
// Returns the corresponding torrentSummary, or undefined
|
||||
function getByKey (state, torrentKey) {
|
||||
if (!torrentKey) return undefined
|
||||
return state.saved.torrents.find((x) =>
|
||||
x.torrentKey === torrentKey || x.infoHash === torrentKey)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user