Merge pull request #239 from feross/absolute-path-urls
Resolve posterURL and torrentPath at runtime
This commit is contained in:
@@ -22,6 +22,7 @@ var errors = require('./lib/errors')
|
||||
var config = require('../config')
|
||||
var TorrentPlayer = require('./lib/torrent-player')
|
||||
var torrentPoster = require('./lib/torrent-poster')
|
||||
var util = require('./util')
|
||||
|
||||
// These two dependencies are the slowest-loading, so we lazy load them
|
||||
// This cuts time from icon click to rendered window from ~550ms to ~150ms on my laptop
|
||||
@@ -478,7 +479,8 @@ function addTorrentToList (torrent) {
|
||||
function startTorrentingSummary (torrentSummary) {
|
||||
var s = torrentSummary
|
||||
if (s.torrentPath) {
|
||||
var ret = startTorrentingID(s.torrentPath, s.path)
|
||||
var torrentPath = util.getAbsoluteStaticPath(s.torrentPath)
|
||||
var ret = startTorrentingID(torrentPath, s.path)
|
||||
if (s.infoHash) state.pendingTorrents[s.infoHash] = ret
|
||||
return ret
|
||||
} else if (s.magnetURI) {
|
||||
@@ -614,7 +616,7 @@ function generateTorrentPoster (torrent, torrentSummary) {
|
||||
fs.writeFile(posterFilePath, buf, function (err) {
|
||||
if (err) return onWarning(err)
|
||||
// show the poster
|
||||
torrentSummary.posterURL = 'file:///' + posterFilePath
|
||||
torrentSummary.posterURL = posterFilePath
|
||||
update()
|
||||
})
|
||||
})
|
||||
@@ -874,7 +876,8 @@ function saveTorrentFileAs (torrentSummary) {
|
||||
]
|
||||
}
|
||||
dialog.showSaveDialog(remote.getCurrentWindow(), opts, (savePath) => {
|
||||
fs.readFile(torrentSummary.torrentPath, function (err, torrentFile) {
|
||||
var torrentPath = util.getAbsoluteStaticPath(torrentSummary.torrentPath)
|
||||
fs.readFile(torrentPath, function (err, torrentFile) {
|
||||
if (err) return onError(err)
|
||||
fs.writeFile(savePath, torrentFile, function (err) {
|
||||
if (err) return onError(err)
|
||||
|
||||
@@ -66,8 +66,8 @@ module.exports = {
|
||||
infoHash: '88594aaacbde40ef3e2510c47374ec0aa396c08e',
|
||||
magnetURI: 'magnet:?xt=urn:btih:88594aaacbde40ef3e2510c47374ec0aa396c08e&dn=bbb_sunflower_1080p_30fps_normal.mp4&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80%2Fannounce&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=http%3A%2F%2Fdistribution.bbb3d.renderfarming.net%2Fvideo%2Fmp4%2Fbbb_sunflower_1080p_30fps_normal.mp4',
|
||||
displayName: 'Big Buck Bunny',
|
||||
posterURL: path.join('..', 'static', 'bigBuckBunny.jpg'),
|
||||
torrentPath: path.join('.', 'static', 'bigBuckBunny.torrent'),
|
||||
posterURL: 'bigBuckBunny.jpg',
|
||||
torrentPath: 'bigBuckBunny.torrent',
|
||||
files: [
|
||||
{
|
||||
'name': 'bbb_sunflower_1080p_30fps_normal.mp4',
|
||||
@@ -82,8 +82,8 @@ module.exports = {
|
||||
infoHash: '6a9759bffd5c0af65319979fb7832189f4f3c35d',
|
||||
magnetURI: 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=udp%3A%2F%2Fexodus.desync.com%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4',
|
||||
displayName: 'Sintel',
|
||||
posterURL: path.join('..', 'static', 'sintel.jpg'),
|
||||
torrentPath: path.join('.', 'static', 'sintel.torrent'),
|
||||
posterURL: 'sintel.jpg',
|
||||
torrentPath: 'sintel.torrent',
|
||||
files: [
|
||||
{
|
||||
'name': 'sintel.mp4',
|
||||
@@ -98,8 +98,8 @@ module.exports = {
|
||||
infoHash: '02767050e0be2fd4db9a2ad6c12416ac806ed6ed',
|
||||
magnetURI: 'magnet:?xt=urn:btih:02767050e0be2fd4db9a2ad6c12416ac806ed6ed&dn=tears_of_steel_1080p.webm&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io',
|
||||
displayName: 'Tears of Steel',
|
||||
posterURL: path.join('..', 'static', 'tearsOfSteel.jpg'),
|
||||
torrentPath: path.join('.', 'static', 'tearsOfSteel.torrent'),
|
||||
posterURL: 'tearsOfSteel.jpg',
|
||||
torrentPath: 'tearsOfSteel.torrent',
|
||||
files: [
|
||||
{
|
||||
'name': 'tears_of_steel_1080p.webm',
|
||||
|
||||
9
renderer/util.js
Normal file
9
renderer/util.js
Normal file
@@ -0,0 +1,9 @@
|
||||
var path = require('path')
|
||||
|
||||
var config = require('../config')
|
||||
|
||||
exports.getAbsoluteStaticPath = function (filePath) {
|
||||
return path.isAbsolute(filePath)
|
||||
? filePath
|
||||
: path.join(config.STATIC_PATH, filePath)
|
||||
}
|
||||
@@ -4,6 +4,7 @@ var h = require('virtual-dom/h')
|
||||
var hyperx = require('hyperx')
|
||||
var hx = hyperx(h)
|
||||
|
||||
var util = require('../util')
|
||||
|
||||
// Shows a streaming video player. Standard features + Chromecast + Airplay
|
||||
function Player (state, dispatch) {
|
||||
@@ -153,7 +154,8 @@ function renderCastScreen (state, dispatch) {
|
||||
function cssBackgroundImagePoster (state) {
|
||||
var torrentSummary = getPlayingTorrentSummary(state)
|
||||
if (!torrentSummary || !torrentSummary.posterURL) return ''
|
||||
var cleanURL = torrentSummary.posterURL.replace(/\\/g, '/')
|
||||
var posterURL = util.getAbsoluteStaticPath(torrentSummary.posterURL)
|
||||
var cleanURL = posterURL.replace(/\\/g, '/')
|
||||
return 'radial-gradient(circle at center, ' +
|
||||
'rgba(0,0,0,0.4) 0%, rgba(0,0,0,1) 100%)' +
|
||||
`, url(${cleanURL})`
|
||||
|
||||
@@ -5,6 +5,8 @@ var hyperx = require('hyperx')
|
||||
var hx = hyperx(h)
|
||||
var prettyBytes = require('prettier-bytes')
|
||||
|
||||
var util = require('../util')
|
||||
|
||||
var TorrentPlayer = require('../lib/torrent-player')
|
||||
|
||||
function TorrentList (state, dispatch) {
|
||||
@@ -35,9 +37,10 @@ function TorrentList (state, dispatch) {
|
||||
var gradient = isSelected
|
||||
? 'linear-gradient(to bottom, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.4) 100%)'
|
||||
: 'linear-gradient(to bottom, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0) 100%)'
|
||||
var posterURL = util.getAbsoluteStaticPath(torrentSummary.posterURL)
|
||||
// Work around a Chrome bug (reproduced in vanilla Chrome, not just Electron):
|
||||
// Backslashes in URLS in CSS cause bizarre string encoding issues
|
||||
var cleanURL = torrentSummary.posterURL.replace(/\\/g, '/')
|
||||
var cleanURL = posterURL.replace(/\\/g, '/')
|
||||
style.backgroundImage = gradient + `, url('${cleanURL}')`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user