Improve bootstrap process

This commit is contained in:
James Long 2022-04-29 10:48:58 -04:00
parent fa32948508
commit c20648c33a
5 changed files with 19 additions and 7 deletions

View file

@ -12,6 +12,5 @@ ADD . .
RUN yarn install --production
RUN mkdir ./server-files
RUN mkdir ./user-files
RUN cp ./sql/default-account.sqlite ./server-files/account.sqlite
CMD ["yarn", "start"]

View file

@ -1,10 +1,20 @@
let fs = require('fs');
let { join } = require('path');
let { openDatabase } = require('./db');
let config = require('./load-config');
let accountDb = null;
function getAccountDb() {
if (accountDb == null) {
accountDb = openDatabase(join(__dirname, 'server-files/account.sqlite'));
let dbPath = join(config.serverFiles, 'account.sqlite');
let needsInit = !fs.existsSync(dbPath);
accountDb = openDatabase(dbPath);
if (needsInit) {
let initSql = fs.readFileSync(join(__dirname, 'sql/account.sql'), 'utf8');
accountDb.exec(initSql);
}
}
return accountDb;

View file

@ -19,7 +19,7 @@ const app = express();
app.use(errorMiddleware);
async function init() {
let fileDir = join(__dirname, process.env.ACTUAL_USER_FILES || config.files);
let fileDir = join(__dirname, process.env.ACTUAL_USER_FILES || config.userFiles);
console.log('Initializing Actual with user file dir:', fileDir);
@ -279,12 +279,12 @@ app.post('/upload-user-file', async (req, res) => {
// supported yet in the self-hosted version because it's unclear if
// it's still needed, given that you own your server
//
// await fs.writeFile(join(config.files, `${fileId}.blob`), req.body);
// await fs.writeFile(join(config.userFiles, `${fileId}.blob`), req.body);
let zip = new AdmZip(req.body);
try {
zip.extractAllTo(join(config.files, fileId), true);
zip.extractAllTo(join(config.userFiles, fileId), true);
} catch (err) {
console.log('Error writing file', err);
res.send(JSON.stringify({ status: 'error' }));
@ -339,7 +339,7 @@ app.get('/download-user-file', async (req, res) => {
let zip = new AdmZip();
try {
zip.addLocalFolder(join(config.files, fileId), '/');
zip.addLocalFolder(join(config.userFiles, fileId), '/');
} catch (e) {
res.status(500).send('Error reading files');
return;

View file

@ -3,11 +3,14 @@ try {
config = require('./config');
} catch (e) {
let fs = require('fs');
let { join } = require('path');
let root = fs.existsSync('/data') ? '/data' : '/';
config = {
mode: 'development',
port: 5006,
files: fs.existsSync('/data') ? '/data' : './user-files'
serverFiles: join(root, 'server-files'),
userFiles: join(root, 'user-files')
};
}

Binary file not shown.