v3.0.0/src/setup.js

142 lines
3.3 KiB
JavaScript
Raw Normal View History

2020-07-07 01:02:59 +02:00
/* eslint-disable no-console */
2019-02-21 15:49:29 +01:00
const randomstring = require('randomstring');
2019-02-19 15:52:24 +01:00
const jetpack = require('fs-jetpack');
2019-02-19 03:30:10 +01:00
const qoa = require('qoa');
2020-07-07 01:02:59 +02:00
2019-02-19 03:30:10 +01:00
qoa.config({
prefix: '>',
2020-12-24 09:40:50 +01:00
underlineQuery: false
2019-02-19 03:30:10 +01:00
});
async function start() {
2019-02-21 15:49:29 +01:00
console.log();
console.log('You can manually edit .env file after the wizard to edit values');
console.log();
2019-02-19 03:30:10 +01:00
const wizard = [
{
type: 'input',
2020-12-25 12:45:22 +01:00
query: 'Port to run chibisafe in:',
2020-12-24 09:40:50 +01:00
handle: 'SERVER_PORT'
2019-02-19 03:30:10 +01:00
},
{
type: 'input',
2020-12-25 12:45:22 +01:00
query: 'Full domain this instance is gonna be running on (Ex: https://chibisafe.moe):',
2020-12-24 09:40:50 +01:00
handle: 'DOMAIN'
2019-02-19 15:52:24 +01:00
},
{
type: 'input',
2020-12-25 12:45:22 +01:00
query: 'Name of the service? (Ex: chibisafe):',
2020-12-24 09:40:50 +01:00
handle: 'SERVICE_NAME'
2019-02-19 03:30:10 +01:00
},
{
type: 'input',
query: 'Maximum allowed upload file size in MB (Ex: 100):',
2020-12-24 09:40:50 +01:00
handle: 'MAX_SIZE'
2019-02-19 03:30:10 +01:00
},
{
type: 'confirm',
query: 'Allow users to download entire albums in ZIP format?',
2019-02-19 15:52:24 +01:00
handle: 'GENERATE_ZIPS',
2019-02-19 03:30:10 +01:00
accept: 'y',
2020-12-24 09:40:50 +01:00
deny: 'n'
2019-02-19 03:30:10 +01:00
},
{
type: 'confirm',
2020-07-18 09:58:29 +02:00
query: 'Allow people to upload files without an account?',
2019-02-19 15:52:24 +01:00
handle: 'PUBLIC_MODE',
2019-02-19 03:30:10 +01:00
accept: 'y',
2020-12-24 09:40:50 +01:00
deny: 'n'
2019-02-19 03:30:10 +01:00
},
{
type: 'confirm',
2020-07-18 09:58:29 +02:00
query: 'Allow people to create new accounts?',
2019-02-19 15:52:24 +01:00
handle: 'USER_ACCOUNTS',
2019-02-19 03:30:10 +01:00
accept: 'y',
2020-12-24 09:40:50 +01:00
deny: 'n'
2019-02-19 03:30:10 +01:00
},
2019-02-21 15:49:29 +01:00
{
type: 'input',
query: 'Name of the admin account?',
2020-12-24 09:40:50 +01:00
handle: 'ADMIN_ACCOUNT'
2019-02-21 15:49:29 +01:00
},
2019-02-19 03:30:10 +01:00
{
type: 'secure',
2019-02-28 16:36:06 +01:00
query: 'Type a secure password for the admin account:',
2020-12-24 09:40:50 +01:00
handle: 'ADMIN_PASSWORD'
2019-02-21 15:49:29 +01:00
},
2019-02-22 01:31:55 +01:00
{
type: 'interactive',
query: 'Which predefined database do you want to use?',
handle: 'DB_CLIENT',
symbol: '>',
menu: [
'sqlite3',
2019-02-22 01:31:55 +01:00
'pg',
2020-12-24 09:40:50 +01:00
'mysql'
]
2019-02-22 01:31:55 +01:00
},
2019-02-21 15:49:29 +01:00
{
type: 'input',
2019-02-22 01:31:55 +01:00
query: 'Database host (Ignore if you selected sqlite3):',
2020-12-24 09:40:50 +01:00
handle: 'DB_HOST'
2019-02-21 15:49:29 +01:00
},
{
type: 'input',
2019-02-22 01:31:55 +01:00
query: 'Database user (Ignore if you selected sqlite3):',
2020-12-24 09:40:50 +01:00
handle: 'DB_USER'
2019-02-21 15:49:29 +01:00
},
{
type: 'input',
2019-02-22 01:31:55 +01:00
query: 'Database password (Ignore if you selected sqlite3):',
2020-12-24 09:40:50 +01:00
handle: 'DB_PASSWORD'
2019-02-21 15:49:29 +01:00
},
{
type: 'input',
2019-02-22 01:31:55 +01:00
query: 'Database name (Ignore if you selected sqlite3):',
2020-12-24 09:40:50 +01:00
handle: 'DB_DATABASE'
}
2019-02-19 03:30:10 +01:00
];
const response = await qoa.prompt(wizard);
2019-02-19 15:52:24 +01:00
let envfile = '';
const defaultSettings = {
2020-07-18 09:58:29 +02:00
GENERATED_FILENAME_LENGTH: 12,
GENERATED_ALBUM_LENGTH: 6,
WEBSITE_PORT: 5001,
SERVE_WITH_NODE: true,
GENERATE_THUMBNAILS: true,
2019-02-19 15:52:24 +01:00
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',
2019-02-21 15:49:29 +01:00
SECRET: randomstring.generate(64),
2019-03-12 08:43:14 +01:00
MAX_LINKS_PER_ALBUM: 5,
META_THEME_COLOR: '#20222b',
META_DESCRIPTION: 'Blazing fast file uploader and bunker written in node! 🚀',
2020-12-25 12:45:22 +01:00
META_KEYWORDS: 'chibisafe,lolisafe,upload,uploader,file,vue,images,ssr,file uploader,free',
2020-12-24 09:40:50 +01:00
META_TWITTER_HANDLE: '@its_pitu'
2019-02-19 15:52:24 +01:00
};
const allSettings = Object.assign(defaultSettings, response);
const keys = Object.keys(allSettings);
2020-07-07 01:02:59 +02:00
// eslint-disable-next-line no-restricted-syntax
2019-02-19 15:52:24 +01:00
for (const item of keys) {
envfile += `${item}=${allSettings[item]}\n`;
}
jetpack.write('.env', envfile);
jetpack.dir('database');
2019-02-19 15:52:24 +01:00
console.log();
2019-02-21 15:49:29 +01:00
console.log('=============================================');
console.log('== .env file generated successfully. ==');
console.log('=============================================');
2019-02-19 15:52:24 +01:00
console.log();
2019-02-19 03:30:10 +01:00
}
start();