chore: add defaults to setup script

This commit is contained in:
Pitu 2020-12-28 05:06:08 +09:00
parent 4334dda3f6
commit 72d3fad525
1 changed files with 44 additions and 17 deletions

View File

@ -16,7 +16,7 @@ async function start() {
const wizard = [
{
type: 'input',
query: 'Port to run chibisafe in:',
query: 'Port to run chibisafe in: (5000)',
handle: 'SERVER_PORT'
},
{
@ -36,28 +36,28 @@ async function start() {
},
{
type: 'confirm',
query: 'Allow users to download entire albums in ZIP format?',
query: 'Allow users to download entire albums in ZIP format? (true)',
handle: 'GENERATE_ZIPS',
accept: 'y',
deny: 'n'
},
{
type: 'confirm',
query: 'Allow people to upload files without an account?',
query: 'Allow people to upload files without an account? (true)',
handle: 'PUBLIC_MODE',
accept: 'y',
deny: 'n'
},
{
type: 'confirm',
query: 'Allow people to create new accounts?',
query: 'Allow people to create new accounts? (true)',
handle: 'USER_ACCOUNTS',
accept: 'y',
deny: 'n'
},
{
type: 'input',
query: 'Name of the admin account?',
query: 'Name of the admin account? (admin)',
handle: 'ADMIN_ACCOUNT'
},
{
@ -97,32 +97,58 @@ async function start() {
let envfile = '';
const defaultSettings = {
ADMIN_PASSWORD: randomstring.generate(16),
GENERATED_FILENAME_LENGTH: 12,
GENERATED_ALBUM_LENGTH: 6,
_1: '# Server settings',
SERVER_PORT: response.SERVER_PORT || 5000,
WEBSITE_PORT: 5001,
SERVE_WITH_NODE: true,
GENERATE_THUMBNAILS: true,
CHUNK_SIZE: 90,
ROUTE_PREFIX: '/api',
RATE_LIMIT_WINDOW: 2,
RATE_LIMIT_MAX: 5,
BLOCKED_EXTENSIONS: ['.jar', '.exe', '.msi', '.com', '.bat', '.cmd', '.scr', '.ps1', '.sh'],
UPLOAD_FOLDER: 'uploads',
SECRET: randomstring.generate(64),
_2: '# Service settings',
SERVICE_NAME: response.SERVICE_NAME || 'change-me',
DOMAIN: response.DOMAIN || `http://localhost:${response.SERVER_PORT}`,
_3: '# File related settings',
CHUNK_SIZE: 90,
MAX_SIZE: response.MAX_SIZE || 5000,
GENERATE_ZIPS: response.GENERATE_ZIPS || true,
GENERATED_FILENAME_LENGTH: 12,
GENERATED_ALBUM_LENGTH: 6,
MAX_LINKS_PER_ALBUM: 5,
UPLOAD_FOLDER: 'uploads',
BLOCKED_EXTENSIONS: ['.jar', '.exe', '.msi', '.com', '.bat', '.cmd', '.scr', '.ps1', '.sh'],
_4: '# User settings',
PUBLIC_MODE: response.PUBLIC_MODE || true,
USER_ACCOUNTS: response.USER_ACCOUNTS || true,
ADMIN_ACCOUNT: response.ADMIN_ACCOUNT || 'admin',
ADMIN_PASSWORD: randomstring.generate(16),
_5: '# Database connection settings',
DB_CLIENT: response.DB_CLIENT,
DB_HOST: response.DB_HOST || null,
DB_USER: response.DB_USER || null,
DB_PASSWORD: response.DB_PASSWORD || null,
DB_DATABASE: response.DB_DATABASE || null,
_6: '# Social and sharing settings',
META_THEME_COLOR: '#20222b',
META_DESCRIPTION: 'Blazing fast file uploader and bunker written in node! 🚀',
META_KEYWORDS: 'chibisafe,lolisafe,upload,uploader,file,vue,images,ssr,file uploader,free',
META_TWITTER_HANDLE: '@its_pitu'
};
const allSettings = Object.assign(defaultSettings, response);
const keys = Object.keys(defaultSettings);
const keys = Object.keys(allSettings);
// eslint-disable-next-line no-restricted-syntax
for (const item of keys) {
envfile += `${item}=${allSettings[item]}\n`;
let prefix = `${item}=`;
if (item.startsWith('_1')) {
prefix = '';
} else if (item.startsWith('_')) {
prefix = '\n';
}
envfile += `${prefix}${defaultSettings[item]}\n`;
}
jetpack.write('.env', envfile);
jetpack.dir('database');
@ -135,6 +161,7 @@ async function start() {
console.log('== MAKE SURE TO CHANGE IT AFTER YOUR FIRST LOGIN! ==');
console.log('====================================================');
console.log();
setTimeout(() => {}, 1000);
}
start();