forked from tdjsnelling/sqtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidateConfig.js
More file actions
69 lines (65 loc) · 2.21 KB
/
Copy pathvalidateConfig.js
File metadata and controls
69 lines (65 loc) · 2.21 KB
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
import * as yup from 'yup'
import config from '../../../config'
const httpRegex = /http(s)?:\/\/.*/
const mongoRegex = /mongodb:\/\/.*/
const configSchema = yup
.object({
envs: yup
.object({
SQ_SITE_NAME: yup.string().min(1).max(20).required(),
SQ_SITE_DESCRIPTION: yup.string().min(1).max(80).required(),
SQ_ALLOW_REGISTER: yup
.string()
.oneOf(['open', 'invite', 'closed'])
.required(),
SQ_ALLOW_ANONYMOUS_UPLOADS: yup.boolean().required(),
SQ_MINIMUM_RATIO: yup.number().min(0).required(),
SQ_BP_EARNED_PER_GB: yup.number().min(0).required(),
SQ_BP_COST_PER_INVITE: yup.number().min(0).required(),
SQ_BP_COST_PER_GB: yup.number().min(0).required(),
SQ_TORRENT_CATEGORIES: yup
.array()
.of(yup.string())
.min(1)
.test('items-unique', 'Categories must be unique', (value) =>
value.every(
(category) => value.filter((c) => c === category).length === 1
)
)
.required(),
SQ_BASE_URL: yup.string().matches(httpRegex).required(),
SQ_API_URL: yup.string().matches(httpRegex).required(),
SQ_TRACKER_URL: yup.string().matches(httpRegex).required(),
SQ_MONGO_URL: yup.string().matches(mongoRegex).required(),
SQ_MAIL_FROM_ADDRESS: yup.string().email().required(),
SQ_SMTP_HOST: yup.string().required(),
SQ_SMTP_PORT: yup.number().integer().min(1).max(65535).required(),
SQ_SMTP_SECURE: yup.boolean().required(),
})
.strict()
.noUnknown()
.required(),
secrets: yup
.object({
SQ_JWT_SECRET: yup.string().required(),
SQ_ADMIN_EMAIL: yup.string().email().required(),
SQ_SMTP_USER: yup.string().required(),
SQ_SMTP_PASS: yup.string().required(),
})
.strict()
.noUnknown()
.required(),
})
.strict()
.noUnknown()
.required()
const validateConfig = async () => {
try {
await configSchema.validate(config)
console.log('[sq] configuration is valid')
} catch (e) {
console.error('[sq] ERROR: invalid configuration:', e.message)
process.exit(1)
}
}
export default validateConfig