From 75841afcb5d78465f9392012f86339e39b738e30 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sat, 19 Mar 2016 16:30:36 -0700 Subject: [PATCH] ensure Posters/ folder exists --- config.js | 2 +- renderer/index.js | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/config.js b/config.js index fe0ed762..6f6cce73 100644 --- a/config.js +++ b/config.js @@ -6,7 +6,7 @@ module.exports = { APP_NAME: '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'), diff --git a/renderer/index.js b/renderer/index.js index f27e1fb6..5ceae055 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -290,6 +290,7 @@ function loadState (callback) { state.saved.torrents.forEach(function (torrentSummary) { if (torrentSummary.displayName) torrentSummary.name = torrentSummary.displayName }) + saveState() if (callback) callback() }) @@ -461,12 +462,15 @@ function generateTorrentPoster (torrent, torrentSummary) { torrentPoster(torrent, function (err, buf) { if (err) return onWarning(err) // save it for next time - var posterFilePath = path.join(config.CONFIG_POSTER_PATH, torrent.infoHash + '.jpg') - fs.writeFile(posterFilePath, buf, function (err) { + fs.mkdir(config.CONFIG_POSTER_PATH, function (err) { if (err) return onWarning(err) - // show the poster - torrentSummary.posterURL = 'file:///' + posterFilePath - update() + var posterFilePath = path.join(config.CONFIG_POSTER_PATH, torrent.infoHash + '.jpg') + fs.writeFile(posterFilePath, buf, function (err) { + if (err) return onWarning(err) + // show the poster + torrentSummary.posterURL = 'file:///' + posterFilePath + update() + }) }) }) }