2021-06-23 11:20:20 -07:00
|
|
|
const Logger = require('../src/lib/logger');
|
2021-09-17 21:38:24 -07:00
|
|
|
const yup = require('yup');
|
2021-06-23 11:20:20 -07:00
|
|
|
|
|
|
|
|
2021-09-17 21:38:24 -07:00
|
|
|
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(),
|
2022-01-03 15:17:47 -08:00
|
|
|
logger: yup.boolean().default(true),
|
2022-01-03 15:56:33 -08:00
|
|
|
stats_interval: yup.number().default(1800),
|
2021-09-17 21:38:24 -07:00
|
|
|
}).required(),
|
|
|
|
uploader: yup.object({
|
2022-02-12 20:35:36 -08:00
|
|
|
route: yup.string().default('/u'),
|
|
|
|
embed_route: yup.string().default('/a'),
|
2021-09-17 21:38:24 -07:00
|
|
|
length: yup.number().default(6),
|
2022-02-12 20:35:36 -08:00
|
|
|
directory: yup.string().default('./uploads'),
|
2021-09-17 21:38:24 -07:00
|
|
|
admin_limit: yup.number().default(104900000),
|
|
|
|
user_limit: yup.number().default(104900000),
|
|
|
|
disabled_extensions: yup.array().default([]),
|
|
|
|
}).required(),
|
2021-09-24 20:31:45 -07:00
|
|
|
urls: yup.object({
|
2022-02-12 20:35:36 -08:00
|
|
|
route: yup.string().default('/go'),
|
2021-09-24 20:31:45 -07:00
|
|
|
length: yup.number().default(6),
|
|
|
|
}).required(),
|
2022-01-03 15:17:47 -08:00
|
|
|
ratelimit: yup.object({
|
|
|
|
user: yup.number().default(0),
|
|
|
|
admin: yup.number().default(0),
|
|
|
|
}),
|
2021-09-17 21:38:24 -07:00
|
|
|
});
|
2021-06-23 11:20:20 -07:00
|
|
|
|
2021-09-24 20:31:45 -07:00
|
|
|
|
|
|
|
module.exports = config => {
|
2021-09-17 21:38:24 -07:00
|
|
|
try {
|
2021-09-24 20:31:45 -07:00
|
|
|
return validator.validateSync(config, { abortEarly: false });
|
2021-09-17 21:38:24 -07:00
|
|
|
} catch (e) {
|
|
|
|
throw `${e.errors.length} errors occured\n${e.errors.map(x => '\t' + x).join('\n')}`;
|
|
|
|
}
|
2021-06-23 11:20:20 -07:00
|
|
|
};
|