From 17aad006f757a6efcfff0c222943e1d30931f046 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Wed, 10 Aug 2016 22:37:33 -0700 Subject: [PATCH] Fix startup issue --- src/server.js | 5 ----- src/web/middleware/ipsessioncookie.js | 8 ++++++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/server.js b/src/server.js index 3a5c328a..593e21b4 100644 --- a/src/server.js +++ b/src/server.js @@ -18,11 +18,6 @@ module.exports = { exists || fs.mkdir(chandumppath); }); - var statepath = path.join(__dirname, "../state"); - fs.exists(statepath, function (exists) { - exists || fs.mkdir(statepath); - }); - var gdvttpath = path.join(__dirname, "../google-drive-subtitles"); fs.exists(gdvttpath, function (exists) { exists || fs.mkdir(gdvttpath); diff --git a/src/web/middleware/ipsessioncookie.js b/src/web/middleware/ipsessioncookie.js index 4bef5c0f..779c1da2 100644 --- a/src/web/middleware/ipsessioncookie.js +++ b/src/web/middleware/ipsessioncookie.js @@ -2,6 +2,7 @@ import path from 'path'; import fs from 'fs'; import crypto from 'crypto'; +const STATE_FOLDER_PATH = path.resolve(__dirname, '..', '..', '..', 'state'); const SALT_PATH = path.resolve(__dirname, '..', '..', '..', 'state', 'ipsessionsalt.json'); const NO_EXPIRATION = new Date('Fri, 31 Dec 9999 23:59:59 GMT'); @@ -10,6 +11,13 @@ try { SALT = require(SALT_PATH); } catch (error) { SALT = crypto.randomBytes(32).toString('base64'); + try { + fs.mkdirSync(STATE_FOLDER_PATH); + } catch (error) { + if (error.code !== 'EEXIST') { + throw error; + } + } fs.writeFileSync(SALT_PATH, JSON.stringify(SALT)); }