ensure Posters/ folder exists

This commit is contained in:
Feross Aboukhadijeh
2016-03-19 16:30:36 -07:00
parent 7738aa2f16
commit 75841afcb5
2 changed files with 10 additions and 6 deletions

View File

@@ -6,7 +6,7 @@ module.exports = {
APP_NAME: 'WebTorrent', APP_NAME: 'WebTorrent',
CONFIG_PATH: applicationConfigPath('WebTorrent'), CONFIG_PATH: applicationConfigPath('WebTorrent'),
CONFIG_POSTER_PATH: path.join(applicationConfigPath('WebTorrent'), 'posters'), CONFIG_POSTER_PATH: path.join(applicationConfigPath('WebTorrent'), 'Posters'),
INDEX: 'file://' + path.join(__dirname, 'renderer', 'index.html'), INDEX: 'file://' + path.join(__dirname, 'renderer', 'index.html'),

View File

@@ -290,6 +290,7 @@ function loadState (callback) {
state.saved.torrents.forEach(function (torrentSummary) { state.saved.torrents.forEach(function (torrentSummary) {
if (torrentSummary.displayName) torrentSummary.name = torrentSummary.displayName if (torrentSummary.displayName) torrentSummary.name = torrentSummary.displayName
}) })
saveState()
if (callback) callback() if (callback) callback()
}) })
@@ -461,12 +462,15 @@ function generateTorrentPoster (torrent, torrentSummary) {
torrentPoster(torrent, function (err, buf) { torrentPoster(torrent, function (err, buf) {
if (err) return onWarning(err) if (err) return onWarning(err)
// save it for next time // save it for next time
var posterFilePath = path.join(config.CONFIG_POSTER_PATH, torrent.infoHash + '.jpg') fs.mkdir(config.CONFIG_POSTER_PATH, function (err) {
fs.writeFile(posterFilePath, buf, function (err) {
if (err) return onWarning(err) if (err) return onWarning(err)
// show the poster var posterFilePath = path.join(config.CONFIG_POSTER_PATH, torrent.infoHash + '.jpg')
torrentSummary.posterURL = 'file:///' + posterFilePath fs.writeFile(posterFilePath, buf, function (err) {
update() if (err) return onWarning(err)
// show the poster
torrentSummary.posterURL = 'file:///' + posterFilePath
update()
})
}) })
}) })
} }