Fix startup issue

This commit is contained in:
calzoneman 2016-08-10 22:37:33 -07:00
parent 33f775051d
commit 17aad006f7
2 changed files with 8 additions and 5 deletions

View File

@ -18,11 +18,6 @@ module.exports = {
exists || fs.mkdir(chandumppath); 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"); var gdvttpath = path.join(__dirname, "../google-drive-subtitles");
fs.exists(gdvttpath, function (exists) { fs.exists(gdvttpath, function (exists) {
exists || fs.mkdir(gdvttpath); exists || fs.mkdir(gdvttpath);

View File

@ -2,6 +2,7 @@ import path from 'path';
import fs from 'fs'; import fs from 'fs';
import crypto from 'crypto'; import crypto from 'crypto';
const STATE_FOLDER_PATH = path.resolve(__dirname, '..', '..', '..', 'state');
const SALT_PATH = path.resolve(__dirname, '..', '..', '..', 'state', 'ipsessionsalt.json'); const SALT_PATH = path.resolve(__dirname, '..', '..', '..', 'state', 'ipsessionsalt.json');
const NO_EXPIRATION = new Date('Fri, 31 Dec 9999 23:59:59 GMT'); const NO_EXPIRATION = new Date('Fri, 31 Dec 9999 23:59:59 GMT');
@ -10,6 +11,13 @@ try {
SALT = require(SALT_PATH); SALT = require(SALT_PATH);
} catch (error) { } catch (error) {
SALT = crypto.randomBytes(32).toString('base64'); 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)); fs.writeFileSync(SALT_PATH, JSON.stringify(SALT));
} }