From 89a271818ed25b0a17a17dd1d6804e34d1f2ec0f Mon Sep 17 00:00:00 2001 From: Pitu Date: Tue, 19 Feb 2019 23:52:24 +0900 Subject: Switch config to .env --- src/wizard.js | 85 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 18 deletions(-) (limited to 'src/wizard.js') diff --git a/src/wizard.js b/src/wizard.js index c9fdbc0..affa759 100644 --- a/src/wizard.js +++ b/src/wizard.js @@ -1,3 +1,4 @@ +const jetpack = require('fs-jetpack'); const qoa = require('qoa'); qoa.config({ prefix: '>', @@ -18,69 +19,117 @@ async function start() { { type: 'input', query: 'Port to run the API in:', - handle: 'serverPort' + handle: 'SERVER_PORT' }, { type: 'input', query: 'Port to run the Website in:', - handle: 'websitePort' + handle: 'WEBSITE_PORT' }, { type: 'input', query: 'Full domain this instance is gonna be running on (Ex: https://lolisafe.moe):', - handle: 'fullDomain' + handle: 'DOMAIN' + }, + { + type: 'input', + query: 'Name of the service? (Ex: lolisafe):', + handle: 'SERVICE_NAME' }, { type: 'input', query: 'Maximum allowed upload file size in MB (Ex: 100):', - handle: 'maxSize' + handle: 'MAX_SIZE' }, { type: 'confirm', query: 'Generate thumbnails for images/videos? (Requires ffmpeg installed and in your PATH)', - handle: 'generateThumbnails', + handle: 'GENERATE_THUMBNAILS', accept: 'y', deny: 'n' }, { type: 'confirm', query: 'Allow users to download entire albums in ZIP format?', - handle: 'generateZips', + handle: 'GENERATE_ZIPS', accept: 'y', deny: 'n' }, { - type: 'interactive', - query: 'How would you like to serve the uploaded files?', - handle: 'serveWithNode', - menu: [ - 'With NGINX (Faster but needs a bit more setup)', - 'With node' - ] + type: 'confirm', + query: 'Strip EXIF information from uploaded images if possible?', + handle: 'STRIP_EXIF', + accept: 'y', + deny: 'n' }, { type: 'confirm', - query: 'Run lolisafe in public mode?', - handle: 'publicMode', + query: 'Serve files with node?', + handle: 'SERVE_WITH_NODE', + accept: 'y', + deny: 'n' + }, + { + type: 'input', + query: 'Base number of characters for generated file URLs (12 should be good enough):', + handle: 'GENERATED_FILENAME_LENGTH' + }, + { + type: 'input', + query: 'Base number of characters for generated album URLs (6 should be enough):', + handle: 'GENERATED_ALBUM_LENGTH' + }, + { + type: 'confirm', + query: 'Run lolisafe in public mode? (People will be able to upload without an account)', + handle: 'PUBLIC_MODE', accept: 'y', deny: 'n' }, { type: 'confirm', query: 'Enable user signup for new accounts?', - handle: 'enableUserAccounts', + handle: 'USER_ACCOUNTS', accept: 'y', deny: 'n' }, { type: 'secure', query: 'Type a secure password for the root user:', - handle: 'rootPassword' + handle: 'ROOT_PASSWORD' } ]; const response = await qoa.prompt(wizard); - console.log(response); + let envfile = ''; + + const defaultSettings = { + CHUNK_SIZE: 90, + ROUTE_PREFIX: '/api', + RATE_LIMIT_WINDOW: 2, + RATE_LIMIT_MAX: 5, + DB_CLIENT: 'pg', + DB_HOST: 'localhost', + DB_USER: '', + DB_PASSWORD: '', + DB_DATABASE: '', + BLOCKED_EXTENSIONS: ['.jar', '.exe', '.msi', '.com', '.bat', '.cmd', '.scr', '.ps1', '.sh'], + UPLOAD_FOLDER: 'uploads', + SECRET: 'SuperSecretPassphraseHere', + MAX_LINKS_PER_ALBUM: 5 + }; + + const allSettings = Object.assign(defaultSettings, response); + + const keys = Object.keys(allSettings); + for (const item of keys) { + envfile += `${item}=${allSettings[item]}\n`; + } + jetpack.write('.env', envfile); + + console.log(); + console.log('== .env file generated successfully. You can now run lolisafe =='); + console.log(); } start(); -- cgit v1.2.3