mirror of
https://github.com/YuzuZensai/Minikura.git
synced 2026-03-30 21:27:36 +00:00
✨ feat: initial prototype
This commit is contained in:
9
apps/backend/src/schemas/bootstrap.schema.ts
Normal file
9
apps/backend/src/schemas/bootstrap.schema.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const bootstrapSchema = z.object({
|
||||
name: z.string().min(1, "Name is required"),
|
||||
email: z.string().email("Valid email is required"),
|
||||
password: z.string().min(8, "Password must be at least 8 characters"),
|
||||
});
|
||||
|
||||
export type BootstrapInput = z.infer<typeof bootstrapSchema>;
|
||||
143
apps/backend/src/schemas/server.schema.ts
Normal file
143
apps/backend/src/schemas/server.schema.ts
Normal file
@@ -0,0 +1,143 @@
|
||||
import { MinecraftServerJarType, ReverseProxyServerType, ServerType, ServiceType } from "@minikura/db";
|
||||
import { z } from "zod";
|
||||
import { GameMode, ServerDifficulty } from "../domain/entities/enums";
|
||||
|
||||
export const serverIdSchema = z.object({
|
||||
id: z
|
||||
.string()
|
||||
.min(1, "Server ID is required")
|
||||
.regex(/^[a-zA-Z0-9-_]+$/, "ID must be alphanumeric with - or _"),
|
||||
});
|
||||
|
||||
export const createServerSchema = z.object({
|
||||
id: z
|
||||
.string()
|
||||
.min(1, "Server ID is required")
|
||||
.regex(/^[a-zA-Z0-9-_]+$/, "ID must be alphanumeric with - or _"),
|
||||
description: z.string().nullable().optional(),
|
||||
listen_port: z.number().int().min(1).max(65535),
|
||||
type: z.nativeEnum(ServerType),
|
||||
service_type: z.nativeEnum(ServiceType).optional(),
|
||||
node_port: z.union([z.number().int().min(30000).max(32767), z.null()]).optional(),
|
||||
env_variables: z
|
||||
.array(
|
||||
z.object({
|
||||
key: z.string().min(1),
|
||||
value: z.string(),
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
memory: z.number().int().min(256).optional(),
|
||||
memory_request: z.number().int().min(256).optional(),
|
||||
cpu_request: z.string().optional(),
|
||||
cpu_limit: z.string().optional(),
|
||||
|
||||
jar_type: z.nativeEnum(MinecraftServerJarType).optional(),
|
||||
minecraft_version: z.string().optional(),
|
||||
|
||||
jvm_opts: z.string().optional(),
|
||||
use_aikar_flags: z.boolean().optional(),
|
||||
use_meowice_flags: z.boolean().optional(),
|
||||
|
||||
difficulty: z.nativeEnum(ServerDifficulty).optional(),
|
||||
game_mode: z.nativeEnum(GameMode).optional(),
|
||||
max_players: z.number().int().min(1).max(1000).optional(),
|
||||
pvp: z.boolean().optional(),
|
||||
online_mode: z.boolean().optional(),
|
||||
motd: z.string().optional(),
|
||||
level_seed: z.string().optional(),
|
||||
level_type: z.string().optional(),
|
||||
});
|
||||
|
||||
export const updateServerSchema = z.object({
|
||||
description: z.string().nullable().optional(),
|
||||
listen_port: z.number().int().min(1).max(65535).optional(),
|
||||
service_type: z.nativeEnum(ServiceType).optional(),
|
||||
node_port: z
|
||||
.union([
|
||||
z
|
||||
.number()
|
||||
.int()
|
||||
.min(30000, "Node port must be at least 30000")
|
||||
.max(32767, "Node port must be at most 32767"),
|
||||
z.null(),
|
||||
])
|
||||
.optional(),
|
||||
env_variables: z
|
||||
.array(
|
||||
z.object({
|
||||
key: z.string().min(1),
|
||||
value: z.string(),
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
memory: z.number().int().min(256).optional(),
|
||||
memory_request: z.number().int().min(256).optional(),
|
||||
cpu_request: z.string().optional(),
|
||||
cpu_limit: z.string().optional(),
|
||||
|
||||
jar_type: z.nativeEnum(MinecraftServerJarType).optional(),
|
||||
minecraft_version: z.string().optional(),
|
||||
|
||||
jvm_opts: z.string().optional(),
|
||||
use_aikar_flags: z.boolean().optional(),
|
||||
use_meowice_flags: z.boolean().optional(),
|
||||
|
||||
difficulty: z.nativeEnum(ServerDifficulty).optional(),
|
||||
game_mode: z.nativeEnum(GameMode).optional(),
|
||||
max_players: z.number().int().min(1).max(1000).optional(),
|
||||
pvp: z.boolean().optional(),
|
||||
online_mode: z.boolean().optional(),
|
||||
motd: z.string().optional(),
|
||||
level_seed: z.string().optional(),
|
||||
level_type: z.string().optional(),
|
||||
});
|
||||
|
||||
export const createReverseProxySchema = z.object({
|
||||
id: z
|
||||
.string()
|
||||
.min(1, "Server ID is required")
|
||||
.regex(/^[a-zA-Z0-9-_]+$/, "ID must be alphanumeric with - or _"),
|
||||
description: z.string().nullable().optional(),
|
||||
external_address: z.string().min(1, "External address is required"),
|
||||
external_port: z.number().int().min(1).max(65535),
|
||||
listen_port: z.number().int().min(1).max(65535).optional(),
|
||||
type: z.nativeEnum(ReverseProxyServerType).optional(),
|
||||
service_type: z.nativeEnum(ServiceType).optional(),
|
||||
node_port: z.union([z.number().int().min(30000).max(32767), z.null()]).optional(),
|
||||
env_variables: z
|
||||
.array(
|
||||
z.object({
|
||||
key: z.string().min(1),
|
||||
value: z.string(),
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
memory: z.number().int().min(256).optional(),
|
||||
cpu_request: z.string().optional(),
|
||||
cpu_limit: z.string().optional(),
|
||||
});
|
||||
|
||||
export const updateReverseProxySchema = z.object({
|
||||
description: z.string().nullable().optional(),
|
||||
external_address: z.string().optional(),
|
||||
external_port: z.number().int().min(1).max(65535).optional(),
|
||||
listen_port: z.number().int().min(1).max(65535).optional(),
|
||||
type: z.nativeEnum(ReverseProxyServerType).optional(),
|
||||
service_type: z.nativeEnum(ServiceType).optional(),
|
||||
node_port: z.union([z.number().int().min(30000).max(32767), z.null()]).optional(),
|
||||
memory: z.number().int().min(256).optional(),
|
||||
cpu_request: z.string().optional(),
|
||||
cpu_limit: z.string().optional(),
|
||||
});
|
||||
|
||||
export const envVariableSchema = z.object({
|
||||
key: z.string().min(1, "Key is required"),
|
||||
value: z.string(),
|
||||
});
|
||||
|
||||
export type CreateServerInput = z.infer<typeof createServerSchema>;
|
||||
export type UpdateServerInput = z.infer<typeof updateServerSchema>;
|
||||
export type CreateReverseProxyInput = z.infer<typeof createReverseProxySchema>;
|
||||
export type UpdateReverseProxyInput = z.infer<typeof updateReverseProxySchema>;
|
||||
export type EnvVariableInput = z.infer<typeof envVariableSchema>;
|
||||
19
apps/backend/src/schemas/user.schema.ts
Normal file
19
apps/backend/src/schemas/user.schema.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const updateUserSchema = z.object({
|
||||
name: z.string().min(1).optional(),
|
||||
role: z.enum(["admin", "user"]).optional(),
|
||||
});
|
||||
|
||||
export const updateSuspensionSchema = z.object({
|
||||
isSuspended: z.boolean(),
|
||||
suspendedUntil: z.string().nullable().optional(),
|
||||
});
|
||||
|
||||
export const suspendUserSchema = z.object({
|
||||
suspendedUntil: z.string().nullable().optional(),
|
||||
});
|
||||
|
||||
export type UpdateUserInput = z.infer<typeof updateUserSchema>;
|
||||
export type UpdateSuspensionInput = z.infer<typeof updateSuspensionSchema>;
|
||||
export type SuspendUserInput = z.infer<typeof suspendUserSchema>;
|
||||
Reference in New Issue
Block a user