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 Ajv, {JTDSchemaType} from "ajv/dist/jtd" | ||||||
| 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, |  | ||||||
| }; |  | ||||||
| 
 | 
 | ||||||
| export interface RateLimitOptions { | export interface RateLimitOptions { | ||||||
| 	count: number; | 	count: number; | ||||||
| @ -64,7 +49,7 @@ export interface DefaultOptions { | |||||||
| 					login?: RateLimitOptions; | 					login?: RateLimitOptions; | ||||||
| 					register?: RateLimitOptions; | 					register?: RateLimitOptions; | ||||||
| 				}; | 				}; | ||||||
| 				channel?: {}; | 				channel?: string; | ||||||
| 				// TODO: rate limit configuration for all routes
 | 				// TODO: rate limit configuration for all routes
 | ||||||
| 			}; | 			}; | ||||||
| 		}; | 		}; | ||||||
| @ -107,85 +92,139 @@ export interface DefaultOptions { | |||||||
| 	}; | 	}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export const DefaultOptions: DefaultOptions = { | const schema: JTDSchemaType<DefaultOptions, {rateLimitOptions: RateLimitOptions}> = { | ||||||
| 	general: { | 	definitions: { | ||||||
| 		instance_id: Snowflake.generate(), | 		rateLimitOptions: { | ||||||
|  | 			properties: { | ||||||
|  | 				count: {type: "int32"}, | ||||||
|  | 				timespan: {type: "int32"} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
| 	}, | 	}, | ||||||
| 	permissions: { | 	properties: { | ||||||
| 		user: { | 		general: { | ||||||
| 			createGuilds: true, | 			properties: { | ||||||
|  | 				instance_id: {type: "string"} | ||||||
|  | 			} | ||||||
| 		}, | 		}, | ||||||
| 	}, | 		permissions: { | ||||||
| 	limits: { | 			properties: { | ||||||
| 		user: { | 				user: { | ||||||
| 			maxGuilds: 100, | 					properties: { | ||||||
| 			maxUsername: 32, | 						createGuilds: {type: "boolean"} | ||||||
| 			maxFriends: 1000, | 					} | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
| 		}, | 		}, | ||||||
| 		guild: { | 		limits: { | ||||||
| 			maxRoles: 250, | 			properties: { | ||||||
| 			maxMembers: 250000, | 				user: { | ||||||
| 			maxChannels: 500, | 					properties: { | ||||||
| 			maxChannelsInCategory: 50, | 						maxGuilds: {type: "int32"}, | ||||||
| 			hideOfflineMember: 1000, | 						maxFriends: {type: "int32"}, | ||||||
|  | 						maxUsername: {type: "int32"} | ||||||
|  | 					} | ||||||
|  | 				}, | ||||||
|  | 				guild: { | ||||||
|  | 					properties: { | ||||||
|  | 						maxRoles: {type: "int32"}, | ||||||
|  | 						maxMembers: {type: "int32"}, | ||||||
|  | 						maxChannels: {type: "int32"}, | ||||||
|  | 						maxChannelsInCategory: {type: "int32"}, | ||||||
|  | 						hideOfflineMember: {type: "int32"} | ||||||
|  | 					} | ||||||
|  | 				}, | ||||||
|  | 				message: { | ||||||
|  | 					properties: { | ||||||
|  | 						characters: {type: "int32"}, | ||||||
|  | 						ttsCharacters: {type: "int32"}, | ||||||
|  | 						maxReactions: {type: "int32"}, | ||||||
|  | 						maxAttachmentSize: {type: "int32"}, | ||||||
|  | 						maxBulkDelete: {type: "int32"} | ||||||
|  | 					} | ||||||
|  | 				}, | ||||||
|  | 				channel: { | ||||||
|  | 					properties: { | ||||||
|  | 						maxPins: {type: "int32"}, | ||||||
|  | 						maxTopic: {type: "int32"}, | ||||||
|  | 					}, | ||||||
|  | 				}, | ||||||
|  | 				rate: { | ||||||
|  | 					properties: { | ||||||
|  | 						ip: { | ||||||
|  | 							properties: { | ||||||
|  | 								enabled: {type: "boolean"}, | ||||||
|  | 								count: {type: "int32"}, | ||||||
|  | 								timespan: {type: "int32"}, | ||||||
|  | 							} | ||||||
|  | 						}, | ||||||
|  | 						routes: { | ||||||
|  | 							optionalProperties: { | ||||||
|  | 								auth: { | ||||||
|  | 									optionalProperties: { | ||||||
|  | 										login: {ref: 'rateLimitOptions'}, | ||||||
|  | 										register: {ref: 'rateLimitOptions'} | ||||||
|  | 									} | ||||||
|  | 								}, | ||||||
|  | 								channel: {type: "string"} | ||||||
|  | 							} | ||||||
|  | 						} | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
| 		}, | 		}, | ||||||
| 		message: { | 		security: { | ||||||
| 			characters: 2000, | 			properties: { | ||||||
| 			ttsCharacters: 200, | 				jwtSecret: {type: "string"}, | ||||||
| 			maxReactions: 20, | 				forwadedFor: {type: "string", nullable: true}, | ||||||
| 			maxAttachmentSize: 8388608, | 				captcha: { | ||||||
| 			maxBulkDelete: 100, | 					properties: { | ||||||
|  | 						enabled: {type: "boolean"}, | ||||||
|  | 						service: {enum: ['hcaptcha', 'recaptcha'], nullable: true}, | ||||||
|  | 						sitekey: {type: "string", nullable: true}, | ||||||
|  | 						secret: {type: "string", nullable: true} | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
| 		}, | 		}, | ||||||
| 		channel: { | 		login: { | ||||||
| 			maxPins: 50, | 			properties: { | ||||||
| 			maxTopic: 1024, | 				requireCaptcha: {type: "boolean"} | ||||||
|  | 			} | ||||||
| 		}, | 		}, | ||||||
| 		rate: { | 		register: { | ||||||
| 			ip: { | 			properties: { | ||||||
| 				enabled: true, | 				email: { | ||||||
| 				count: 1000, | 					properties: { | ||||||
| 				timespan: 1000 * 60 * 10, | 						required: {type: "boolean"}, | ||||||
|  | 						allowlist: {type: "boolean"}, | ||||||
|  | 						blocklist: {type: "boolean"}, | ||||||
|  | 						domains: { elements: { | ||||||
|  | 							type: "string" | ||||||
|  | 						} | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
| 			}, | 			}, | ||||||
| 			routes: {}, | 			dateOfBirth: { | ||||||
| 		}, | 				properties: { | ||||||
| 	}, | 					required: {type: "boolean"}, | ||||||
| 	security: { | 					minimum: {type: "int32"} | ||||||
| 		jwtSecret: crypto.randomBytes(256).toString("base64"), | 				} | ||||||
| 		forwadedFor: null, | 			}, | ||||||
| 		// forwadedFor: "X-Forwarded-For" // nginx/reverse proxy
 | 			requireCaptcha: {type: "boolean"}, | ||||||
| 		// forwadedFor: "CF-Connecting-IP" // cloudflare:
 | 			requireInvite: {type: "boolean"}, | ||||||
| 		captcha: { | 			allowNewRegistration: {type: "boolean"}, | ||||||
| 			enabled: false, | 			allowMultipleAccounts: {type: "boolean"}, | ||||||
| 			service: null, | 			password: { | ||||||
| 			sitekey: null, | 				properties: { | ||||||
| 			secret: null, | 					minLength: {type: "int32"}, | ||||||
| 		}, | 					minNumbers: {type: "int32"}, | ||||||
| 	}, | 					minUpperCase: {type: "int32"}, | ||||||
| 	login: { | 					minSymbols: {type: "int32"}, | ||||||
| 		requireCaptcha: false, | 					blockInsecureCommonPasswords: {type: "boolean"} | ||||||
| 	}, | 				} | ||||||
| 	register: { | 			} | ||||||
| 		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"),
 |  | ||||||
| 		}, |  | ||||||
| 		dateOfBirth: { |  | ||||||
| 			required: true, |  | ||||||
| 			minimum: 13, |  | ||||||
| 		}, |  | ||||||
| 		requireInvite: false, |  | ||||||
| 		requireCaptcha: true, |  | ||||||
| 		allowNewRegistration: true, |  | ||||||
| 		allowMultipleAccounts: true, |  | ||||||
| 		password: { |  | ||||||
| 			minLength: 8, |  | ||||||
| 			minNumbers: 2, |  | ||||||
| 			minUpperCase: 2, |  | ||||||
| 			minSymbols: 0, |  | ||||||
| 			blockInsecureCommonPasswords: false, |  | ||||||
| 		}, |  | ||||||
| 	}, |  | ||||||
| }; |  | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Diego Magdaleno
						Diego Magdaleno