Skip to content

Commit

Permalink
use electron userData path
Browse files Browse the repository at this point in the history
  • Loading branch information
naomiaro committed Apr 3, 2019
1 parent 0f1f5ad commit af11abd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions app.js
Expand Up @@ -9,6 +9,8 @@
var http = require('http');
var busboy = require('connect-busboy');
var app = express();
const electron = require('electron');
const USER_DATA_FOLDER = electron.app.getPath('userData');

// Setup node_modules for templates
app.use('/node_modules', express.static(path.join(__dirname, 'node_modules')));
Expand All @@ -23,6 +25,7 @@
app.use(bodyParser.urlencoded({limit: '500mb', extended: true}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(USER_DATA_FOLDER)));
app.use(busboy()); // for file upload

// load routes
Expand Down
10 changes: 7 additions & 3 deletions routes/editor.js
@@ -1,11 +1,13 @@
var express = require('express');
const electron = require('electron');
const path = require('path');
const fs = require('fs');
var router = express.Router();
var Storyboard = require('../models/storyboard');
var storyboard = new Storyboard();
var archiver = require('archiver');

const USER_DATA_FOLDER = electron.app.getPath('userData');
const PUBLIC_FOLDER = path.resolve(__dirname, '..', 'public');
const DATA_FOLDER = path.resolve(__dirname, '..', 'data');
const MANIFEST = require(path.resolve(PUBLIC_FOLDER, 'manifest'));
Expand Down Expand Up @@ -80,7 +82,7 @@ router.get('/download', function (req, res) {
const storyName = storyboard.filename.split('.')[0];

// write to dist/index.html
fs.writeFile(path.resolve(PUBLIC_FOLDER, 'dist', 'index.html'), html, function (err) {
fs.writeFile(path.resolve(USER_DATA_FOLDER, 'index.html'), html, function (err) {
if (err) {
console.log(err);
return res.send(err);
Expand Down Expand Up @@ -116,13 +118,15 @@ router.get('/download', function (req, res) {

archive.pipe(res);

const uploadPath = path.join(USER_DATA_FOLDER, 'uploads', storyName);

archive
.file(path.resolve(PUBLIC_FOLDER, 'dist', 'index.html'), {name: 'index.html'})
.file(path.resolve(USER_DATA_FOLDER, 'index.html'), {name: 'index.html'})
.file(path.resolve(PUBLIC_FOLDER, MANIFEST['app.css']), {name: MANIFEST['app.css']})
.file(path.resolve(PUBLIC_FOLDER, MANIFEST['app.js']), {name: MANIFEST['app.js']})
.file(path.resolve(DATA_FOLDER, 'stories', `${storyName}.json`), {name: `${storyName}.json`})
.directory(path.resolve(PUBLIC_FOLDER, 'img'), 'img')
.directory(path.resolve(PUBLIC_FOLDER, 'uploads', storyName), path.join('uploads', storyName))
.directory(uploadPath, path.join('uploads', storyName))
.finalize();
});
});
Expand Down
4 changes: 3 additions & 1 deletion routes/upload.js
Expand Up @@ -3,7 +3,9 @@ const router = express.Router();
const path = require('path');
const fs = require('fs');
const mkdirp = require('mkdirp');
const electron = require('electron');

const USER_DATA_FOLDER = electron.app.getPath('userData');
const Preferences = require('../models/preferences');
const preferences = new Preferences(path.join(__dirname, '../data/preferences.json'));

Expand All @@ -14,7 +16,7 @@ router.post('/', function (req, res) {
}

const story = data.storyboard.split('.')[0];
const uploadPath = path.join(__dirname,'../public/uploads/', story);
const uploadPath = path.join(USER_DATA_FOLDER, 'uploads', story);

mkdirp(uploadPath, function (err) {
if (err) {
Expand Down

0 comments on commit af11abd

Please sign in to comment.