setup autocalled from ass.js & handles initial auth & other tasks

pull/29/head
tycrek 3 years ago
parent 03d5cb450b
commit 423fa4a78c
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -1,13 +1,19 @@
let doSetup = null;
try {
// Check if config.json exists
require('./config.json');
} catch (err) {
console.error('No config.json found! Please run \'npm run setup\'');
process.exit(1);
doSetup = require('./setup').doSetup;
}
// Run first time setup if using Docker (pseudo-process, setup will be run with docker exec)
if (doSetup) {
doSetup();
return;
}
// Load the config
const { host, port, useSsl, diskFilePath, isProxied, s3enabled } = require('./config.json');
const { host, port, useSsl, isProxied, s3enabled } = require('./config.json');
//#region Imports
const fs = require('fs-extra');
@ -40,9 +46,6 @@ const users = require('./auth');
const data = require('./data');
//#endregion
// Create thumbnails directory
fs.ensureDirSync(path(diskFilePath, 'thumbnails'));
// Enable/disable Express features
app.enable('case sensitive routing');
app.disable('x-powered-by');
@ -97,10 +100,4 @@ log
.info('Frontend', ASS_PREMIUM.enabled ? ASS_PREMIUM.brand : 'disabled', `${ASS_PREMIUM.enabled ? `${getTrueHttp()}${getTrueDomain()}${ASS_PREMIUM.endpoint}` : ''}`)
.info('Index redirect', ASS_PREMIUM.enabled && ASS_PREMIUM.index ? `enable` : 'disabled')
.blank()
.callback(() => {
if (process.argv[2] && process.argv[2] === '--docker-compose')
fs.ensureDir(require('path').join(process.cwd(), 'share')).then(() => log
.info('docker-compose', 'Exiting in 5 seconds...')
.callback(() => setTimeout(() => process.exit(0), 5000)))
})
.express().Host(app, port, host, () => log.success('Ready for uploads', `Storing resources ${s3enabled ? 'in S3' : 'on disk'}`));

@ -3,16 +3,7 @@
*/
const fs = require('fs-extra');
const { log, path, arrayEquals, generateToken } = require('./utils');
// Make sure auth.json exists and generate the first key
if (!fs.existsSync(path('auth.json'))) {
let users = {};
users[generateToken()] = { username: 'ass', count: 0 };
fs.writeJsonSync(path('auth.json'), { users }, { spaces: 4 });
log.debug('File created', 'auth.json')
.success('!! Important', `Save this token in a secure spot: ${Object.keys(users)[0]}`)
}
const { log, path, arrayEquals } = require('./utils');
const users = require('./auth.json').users || {};

@ -27,6 +27,7 @@ function doSetup() {
const TLog = require('@tycrek/log');
const fs = require('fs-extra');
const prompt = require('prompt');
const token = require('./generators/token');
const log = new TLog({ timestamp: { enabled: false } });
@ -196,7 +197,34 @@ function doSetup() {
// Confirm
.then(() => prompt.get(confirmSchema))
.then(({ confirm }) => (confirm ? fs.writeJson(path('config.json'), results, { spaces: 4 }) : process.exit(1)))
.then(() => log.blank().success('Config has been saved!'))
// Other setup tasks
.then(() => {
// Make sure auth.json exists and generate the first key
let users = {};
users[token()] = { username: 'ass', count: 0 };
fs.writeJsonSync(path('auth.json'), { users }, { spaces: 4 });
log.debug('File created', 'auth.json')
.success('!! Important', `Save this token in a secure spot: ${Object.keys(users)[0]}`)
let existingData = {}
try {
existingData = fs.readJsonSync(path('data.json'));
} catch (ex) {
log.warn('data.json', 'File empty, fixing')
}
// All 3 as a Promise.all
return Promise.all([
fs.ensureDir(path('share')),
fs.ensureDir(path(results.diskFilePath, 'thumbnails')),
fs.writeJson(path('data.json'), existingData, { spaces: 4 })
]);
})
// Complete & exit
.then(() => log.blank().success('Setup complete').callback(() => process.exit(0)))
.catch((err) => log.blank().error(err));
}

Loading…
Cancel
Save