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)); }