1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
const randomstring = require('randomstring');
const jetpack = require('fs-jetpack');
const qoa = require('qoa');
qoa.config({
prefix: '>',
underlineQuery: false
});
async function start() {
const confirm = await qoa.confirm({
type: 'confirm',
query: 'Would you like to run the setup wizard now?',
handle: 'run',
accept: 'y',
deny: 'n'
});
if (!confirm.run) process.exit(0);
console.log();
console.log('You can manually edit .env file after the wizard to edit values');
console.log();
const wizard = [
{
type: 'input',
query: 'Port to run the API in:',
handle: 'SERVER_PORT'
},
{
type: 'input',
query: 'Port to run the Website in:',
handle: 'WEBSITE_PORT'
},
{
type: 'input',
query: 'Full domain this instance is gonna be running on (Ex: https://lolisafe.moe):',
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: 'MAX_SIZE'
},
{
type: 'confirm',
query: 'Generate thumbnails for images/videos? (Requires ffmpeg installed and in your PATH)',
handle: 'GENERATE_THUMBNAILS',
accept: 'y',
deny: 'n'
},
{
type: 'confirm',
query: 'Allow users to download entire albums in ZIP format?',
handle: 'GENERATE_ZIPS',
accept: 'y',
deny: 'n'
},
{
type: 'confirm',
query: 'Strip EXIF information from uploaded images if possible?',
handle: 'STRIP_EXIF',
accept: 'y',
deny: 'n'
},
{
type: 'confirm',
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: 'USER_ACCOUNTS',
accept: 'y',
deny: 'n'
},
{
type: 'input',
query: 'Name of the admin account?',
handle: 'ADMIN_ACCOUNT'
},
{
type: 'secure',
query: 'Type a secure password for the root user:',
handle: 'ADMIN_PASSWORD'
},
{
type: 'input',
query: 'Database host',
handle: 'DB_HOST'
},
{
type: 'input',
query: 'Database user',
handle: 'DB_USER'
},
{
type: 'input',
query: 'Database password',
handle: 'DB_PASSWORD'
},
{
type: 'input',
query: 'Database name',
handle: 'DB_DATABASE'
}
];
const response = await qoa.prompt(wizard);
let envfile = '';
const defaultSettings = {
CHUNK_SIZE: 90,
ROUTE_PREFIX: '/api',
RATE_LIMIT_WINDOW: 2,
RATE_LIMIT_MAX: 5,
DB_CLIENT: 'pg',
BLOCKED_EXTENSIONS: ['.jar', '.exe', '.msi', '.com', '.bat', '.cmd', '.scr', '.ps1', '.sh'],
UPLOAD_FOLDER: 'uploads',
SECRET: randomstring.generate(64),
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('=============================================');
console.log('== .env file generated successfully. ==');
console.log('=============================================');
console.log('== Run `yarn migrate` and `yarn seed` next ==');
console.log('=============================================');
console.log();
}
start();
|