zipline/server/validateConfig.js
2022-01-03 15:56:33 -08:00

40 lines
No EOL
1.2 KiB
JavaScript

const Logger = require('../src/lib/logger');
const yup = require('yup');
const validator = yup.object({
core: yup.object({
secure: yup.bool().default(false),
secret: yup.string().min(8).required(),
host: yup.string().default('0.0.0.0'),
port: yup.number().default(3000),
database_url: yup.string().required(),
logger: yup.boolean().default(true),
stats_interval: yup.number().default(1800),
}).required(),
uploader: yup.object({
route: yup.string().required(),
length: yup.number().default(6),
directory: yup.string().required(),
admin_limit: yup.number().default(104900000),
user_limit: yup.number().default(104900000),
disabled_extensions: yup.array().default([]),
}).required(),
urls: yup.object({
route: yup.string().required(),
length: yup.number().default(6),
}).required(),
ratelimit: yup.object({
user: yup.number().default(0),
admin: yup.number().default(0),
}),
});
module.exports = config => {
try {
return validator.validateSync(config, { abortEarly: false });
} catch (e) {
throw `${e.errors.length} errors occured\n${e.errors.map(x => '\t' + x).join('\n')}`;
}
};