feat: added more config checks

pull/243/head
Josh Moore 1 year ago
parent 97fa3acb1a
commit 15ee35d996

@ -40,6 +40,25 @@ const Checkers: UserConfigTypeChecker = {
idSize: numChecker,
gfySize: numChecker,
maximumFileSize: numChecker,
s3: {
endpoint: basicStringChecker,
bucket: basicStringChecker,
region: (val) => val == null || basicStringChecker(val),
credentials: {
accessKey: basicStringChecker,
secretKey: basicStringChecker
}
},
sql: {
mySql: {
host: basicStringChecker,
user: basicStringChecker,
password: basicStringChecker,
database: basicStringChecker
}
}
}
export class UserConfig {
@ -69,6 +88,14 @@ export class UserConfig {
if (!Checkers.gfySize(config.gfySize)) throw new Error('Invalid Gfy size');
if (!Checkers.maximumFileSize(config.maximumFileSize)) throw new Error('Invalid maximum file size');
if (config.s3 != null) {
if (!Checkers.s3.endpoint(config.s3.endpoint)) throw new Error('Invalid S3 Endpoint');
if (!Checkers.s3.bucket(config.s3.bucket)) throw new Error('Invalid S3 Bucket');
if (!Checkers.s3.region(config.s3.region)) throw new Error('Invalid S3 Region');
if (!Checkers.s3.credentials.accessKey(config.s3.credentials.accessKey)) throw new Error('Invalid S3 Access key');
if (!Checkers.s3.credentials.secretKey(config.s3.credentials.secretKey)) throw new Error('Invalid S3 Secret key');
}
// All is fine, carry on!
return config;
}

17
common/types.d.ts vendored

@ -61,6 +61,23 @@ declare module 'ass' {
idSize: (val: any) => boolean;
gfySize: (val: any) => boolean;
maximumFileSize: (val: any) => boolean;
s3: {
endpoint: (val: any) => boolean;
bucket: (val: any) => boolean;
region: (val: any) => boolean;
credentials: {
accessKey: (val: any) => boolean;
secretKey: (val: any) => boolean;
}
}
sql: {
mySql: {
host: (val: any) => boolean;
user: (val: any) => boolean;
password: (val: any) => boolean;
database: (val: any) => boolean;
}
}
}
interface BusBoyFile {

Loading…
Cancel
Save