Config: Start working on the config refactor
This commit is contained in:
		
							parent
							
								
									466c72d65f
								
							
						
					
					
						commit
						bb2d3715ea
					
				| @ -1,19 +1,4 @@ | ||||
| import { Config, Snowflake } from "@fosscord/server-util"; | ||||
| import crypto from "crypto"; | ||||
| 
 | ||||
| export default { | ||||
| 	init() { | ||||
| 		return Config.init({ api: DefaultOptions }); | ||||
| 	}, | ||||
| 	get(): DefaultOptions { | ||||
| 		return Config.getAll().api; | ||||
| 	}, | ||||
| 	set(val: any) { | ||||
| 		return Config.setAll({ api: val }); | ||||
| 	}, | ||||
| 	getAll: Config.getAll, | ||||
| 	setAll: Config.setAll, | ||||
| }; | ||||
| import Ajv, {JTDSchemaType} from "ajv/dist/jtd" | ||||
| 
 | ||||
| export interface RateLimitOptions { | ||||
| 	count: number; | ||||
| @ -64,7 +49,7 @@ export interface DefaultOptions { | ||||
| 					login?: RateLimitOptions; | ||||
| 					register?: RateLimitOptions; | ||||
| 				}; | ||||
| 				channel?: {}; | ||||
| 				channel?: string; | ||||
| 				// TODO: rate limit configuration for all routes
 | ||||
| 			}; | ||||
| 		}; | ||||
| @ -107,85 +92,139 @@ export interface DefaultOptions { | ||||
| 	}; | ||||
| } | ||||
| 
 | ||||
| export const DefaultOptions: DefaultOptions = { | ||||
| const schema: JTDSchemaType<DefaultOptions, {rateLimitOptions: RateLimitOptions}> = { | ||||
| 	definitions: { | ||||
| 		rateLimitOptions: { | ||||
| 			properties: { | ||||
| 				count: {type: "int32"}, | ||||
| 				timespan: {type: "int32"} | ||||
| 			} | ||||
| 		} | ||||
| 	}, | ||||
| 	properties: { | ||||
| 		general: { | ||||
| 		instance_id: Snowflake.generate(), | ||||
| 			properties: { | ||||
| 				instance_id: {type: "string"} | ||||
| 			} | ||||
| 		}, | ||||
| 		permissions: { | ||||
| 			properties: { | ||||
| 				user: { | ||||
| 			createGuilds: true, | ||||
| 		}, | ||||
| 					properties: { | ||||
| 						createGuilds: {type: "boolean"} | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		}, | ||||
| 		limits: { | ||||
| 			properties: { | ||||
| 				user: { | ||||
| 			maxGuilds: 100, | ||||
| 			maxUsername: 32, | ||||
| 			maxFriends: 1000, | ||||
| 					properties: { | ||||
| 						maxGuilds: {type: "int32"}, | ||||
| 						maxFriends: {type: "int32"}, | ||||
| 						maxUsername: {type: "int32"} | ||||
| 					} | ||||
| 				}, | ||||
| 				guild: { | ||||
| 			maxRoles: 250, | ||||
| 			maxMembers: 250000, | ||||
| 			maxChannels: 500, | ||||
| 			maxChannelsInCategory: 50, | ||||
| 			hideOfflineMember: 1000, | ||||
| 					properties: { | ||||
| 						maxRoles: {type: "int32"}, | ||||
| 						maxMembers: {type: "int32"}, | ||||
| 						maxChannels: {type: "int32"}, | ||||
| 						maxChannelsInCategory: {type: "int32"}, | ||||
| 						hideOfflineMember: {type: "int32"} | ||||
| 					} | ||||
| 				}, | ||||
| 				message: { | ||||
| 			characters: 2000, | ||||
| 			ttsCharacters: 200, | ||||
| 			maxReactions: 20, | ||||
| 			maxAttachmentSize: 8388608, | ||||
| 			maxBulkDelete: 100, | ||||
| 					properties: { | ||||
| 						characters: {type: "int32"}, | ||||
| 						ttsCharacters: {type: "int32"}, | ||||
| 						maxReactions: {type: "int32"}, | ||||
| 						maxAttachmentSize: {type: "int32"}, | ||||
| 						maxBulkDelete: {type: "int32"} | ||||
| 					} | ||||
| 				}, | ||||
| 				channel: { | ||||
| 			maxPins: 50, | ||||
| 			maxTopic: 1024, | ||||
| 					properties: { | ||||
| 						maxPins: {type: "int32"}, | ||||
| 						maxTopic: {type: "int32"}, | ||||
| 					}, | ||||
| 				}, | ||||
| 				rate: { | ||||
| 					properties: { | ||||
| 						ip: { | ||||
| 				enabled: true, | ||||
| 				count: 1000, | ||||
| 				timespan: 1000 * 60 * 10, | ||||
| 							properties: { | ||||
| 								enabled: {type: "boolean"}, | ||||
| 								count: {type: "int32"}, | ||||
| 								timespan: {type: "int32"}, | ||||
| 							} | ||||
| 						}, | ||||
| 			routes: {}, | ||||
| 						routes: { | ||||
| 							optionalProperties: { | ||||
| 								auth: { | ||||
| 									optionalProperties: { | ||||
| 										login: {ref: 'rateLimitOptions'}, | ||||
| 										register: {ref: 'rateLimitOptions'} | ||||
| 									} | ||||
| 								}, | ||||
| 								channel: {type: "string"} | ||||
| 							} | ||||
| 						} | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		}, | ||||
| 		security: { | ||||
| 		jwtSecret: crypto.randomBytes(256).toString("base64"), | ||||
| 		forwadedFor: null, | ||||
| 		// forwadedFor: "X-Forwarded-For" // nginx/reverse proxy
 | ||||
| 		// forwadedFor: "CF-Connecting-IP" // cloudflare:
 | ||||
| 			properties: { | ||||
| 				jwtSecret: {type: "string"}, | ||||
| 				forwadedFor: {type: "string", nullable: true}, | ||||
| 				captcha: { | ||||
| 			enabled: false, | ||||
| 			service: null, | ||||
| 			sitekey: null, | ||||
| 			secret: null, | ||||
| 		}, | ||||
| 					properties: { | ||||
| 						enabled: {type: "boolean"}, | ||||
| 						service: {enum: ['hcaptcha', 'recaptcha'], nullable: true}, | ||||
| 						sitekey: {type: "string", nullable: true}, | ||||
| 						secret: {type: "string", nullable: true} | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		}, | ||||
| 		login: { | ||||
| 		requireCaptcha: false, | ||||
| 			properties: { | ||||
| 				requireCaptcha: {type: "boolean"} | ||||
| 			} | ||||
| 		}, | ||||
| 		register: { | ||||
| 			properties: { | ||||
| 				email: { | ||||
| 			required: true, | ||||
| 			allowlist: false, | ||||
| 			blocklist: true, | ||||
| 			domains: [], // TODO: efficiently save domain blocklist in database
 | ||||
| 			// domains: fs.readFileSync(__dirname + "/blockedEmailDomains.txt", { encoding: "utf8" }).split("\n"),
 | ||||
| 					properties: { | ||||
| 						required: {type: "boolean"}, | ||||
| 						allowlist: {type: "boolean"}, | ||||
| 						blocklist: {type: "boolean"}, | ||||
| 						domains: { elements: { | ||||
| 							type: "string" | ||||
| 						} | ||||
| 					} | ||||
| 				} | ||||
| 			}, | ||||
| 			dateOfBirth: { | ||||
| 			required: true, | ||||
| 			minimum: 13, | ||||
| 				properties: { | ||||
| 					required: {type: "boolean"}, | ||||
| 					minimum: {type: "int32"} | ||||
| 				} | ||||
| 			}, | ||||
| 		requireInvite: false, | ||||
| 		requireCaptcha: true, | ||||
| 		allowNewRegistration: true, | ||||
| 		allowMultipleAccounts: true, | ||||
| 			requireCaptcha: {type: "boolean"}, | ||||
| 			requireInvite: {type: "boolean"}, | ||||
| 			allowNewRegistration: {type: "boolean"}, | ||||
| 			allowMultipleAccounts: {type: "boolean"}, | ||||
| 			password: { | ||||
| 			minLength: 8, | ||||
| 			minNumbers: 2, | ||||
| 			minUpperCase: 2, | ||||
| 			minSymbols: 0, | ||||
| 			blockInsecureCommonPasswords: false, | ||||
| 		}, | ||||
| 	}, | ||||
| }; | ||||
| 				properties: { | ||||
| 					minLength: {type: "int32"}, | ||||
| 					minNumbers: {type: "int32"}, | ||||
| 					minUpperCase: {type: "int32"}, | ||||
| 					minSymbols: {type: "int32"}, | ||||
| 					blockInsecureCommonPasswords: {type: "boolean"} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Diego Magdaleno
						Diego Magdaleno