♻️ refactor: remove stale code and comments

This commit is contained in:
2026-08-13 02:19:25 +07:00
parent 913c18b6b7
commit b58488c1b9
15 changed files with 10 additions and 48 deletions
@@ -7,14 +7,12 @@ import { ReverseProxyService } from "./services/reverse-proxy.service";
import { ServerService } from "./services/server.service";
import { UserService } from "./services/user.service";
// Infrastructure layer
const userRepo = new PrismaUserRepository();
const serverRepo = new PrismaServerRepository();
const reverseProxyRepo = new PrismaReverseProxyRepository();
const webSocketService = new WebSocketService();
const k8sService = new K8sService();
// Application layer
export const userService = new UserService(userRepo);
export const serverService = new ServerService(serverRepo, k8sService);
export const reverseProxyService = new ReverseProxyService(reverseProxyRepo);
@@ -2,7 +2,6 @@ import type * as k8s from "@kubernetes/client-node";
import type { CustomResourceSummary } from "@minikura/api";
export interface IK8sService {
// Initialization
isInitialized(): boolean;
getConnectionInfo(): {
initialized: boolean;
@@ -11,7 +10,6 @@ export interface IK8sService {
namespace: string;
};
// Pods
getPods(): Promise<any[]>;
getPodsByLabel(labelSelector: string): Promise<any[]>;
getPodInfo(podName: string): Promise<any>;
@@ -26,20 +24,16 @@ export interface IK8sService {
): Promise<string>;
getPodMetrics(namespace?: string): Promise<any>;
// Workloads
getDeployments(): Promise<any[]>;
getStatefulSets(): Promise<any[]>;
// Network
getServices(): Promise<any[]>;
getIngresses(): Promise<any[]>;
getServiceInfo(serviceName: string): Promise<any>;
getServerConnectionInfo(serviceName: string): Promise<any>;
// Configuration
getConfigMaps(): Promise<any[]>;
// Custom Resources
getCustomResources(
group: string,
version: string,
@@ -48,11 +42,9 @@ export interface IK8sService {
getMinecraftServers(): Promise<CustomResourceSummary[]>;
getReverseProxyServers(): Promise<CustomResourceSummary[]>;
// Cluster
getNodes(): Promise<any[]>;
getNodeMetrics(): Promise<any>;
// Low-level access
getKubeConfig(): k8s.KubeConfig;
getCoreApi(): k8s.CoreV1Api;
getNamespace(): string;
+4 -4
View File
@@ -8,13 +8,13 @@ export const DEFAULT_PORTS = {
} as const;
export const DEFAULT_MEMORY = {
SERVER: 2048, // MB
REVERSE_PROXY: 512, // MB
SERVER: 2048,
REVERSE_PROXY: 512,
} as const;
export const DEFAULT_MEMORY_REQUEST = {
SERVER: 1024, // MB
REVERSE_PROXY: 512, // MB
SERVER: 1024,
REVERSE_PROXY: 512,
} as const;
export const DEFAULT_CPU = {
+2 -4
View File
@@ -2,8 +2,8 @@ import { dotenvLoad } from "dotenv-mono";
dotenvLoad();
import { Elysia } from "elysia";
import { node } from "@elysiajs/node";
import { Elysia } from "elysia";
import { logger } from "./infrastructure/logger";
import { auth } from "./middleware/auth";
import { authPlugin } from "./middleware/auth-plugin";
@@ -15,7 +15,6 @@ import { serverRoutes } from "./routes/servers";
import { terminalRoutes } from "./routes/terminal";
import { userRoutes } from "./routes/users";
// Register event handlers
import "./infrastructure/event-handlers";
const app = new Elysia({ adapter: node() })
@@ -33,8 +32,7 @@ const app = new Elysia({ adapter: node() })
.use(authPlugin)
.group("/api", (app) =>
app.use(userRoutes).use(serverRoutes).use(reverseProxyRoutes).use(k8sRoutes).use(terminalRoutes)
)
.get("/health", () => ({ status: "ok" }));
);
export type App = typeof app;
@@ -95,7 +95,6 @@ export class PrismaReverseProxyRepository implements ReverseProxyRepository {
throw new NotFoundError("ReverseProxyServer", id);
}
// Update proxy fields
const updated = await prisma.reverseProxyServer.update({
where: { id },
data: {
@@ -107,12 +107,10 @@ export class PrismaServerRepository implements ServerRepository {
throw new NotFoundError("Server", id);
}
// Handle env variables separately
if (input.env_variables !== undefined) {
await this.replaceEnvVariables(id, input.env_variables);
}
// Update server fields
const updated = await prisma.server.update({
where: { id },
data: {
-1
View File
@@ -46,7 +46,6 @@ export const k8sRoutes = new Elysia({ prefix: "/k8s" })
};
const logs = await k8sService.getPodLogs(params.podName, options);
// Return as plain text
const headers = (set.headers ?? {}) as Record<string, string>;
headers["content-type"] = "text/plain";
set.headers = headers;
-4
View File
@@ -6,9 +6,7 @@ import type { IK8sService } from "../application/interfaces/k8s.service.interfac
import { logger } from "../infrastructure/logger";
import { ClusterOperations } from "./kubernetes/operations/cluster.operations";
import { CustomResourceOperations } from "./kubernetes/operations/custom-resource.operations";
import { NetworkOperations } from "./kubernetes/operations/network.operations";
import { PodOperations } from "./kubernetes/operations/pod.operations";
import { WorkloadOperations } from "./kubernetes/operations/workload.operations";
import { K8sResources } from "./kubernetes/resources";
const CUSTOM_RESOURCE_VERSION = "v1alpha1";
@@ -56,8 +54,6 @@ export class K8sService implements IK8sService {
private initializeOperations(): void {
this.podOps = new PodOperations(this.coreApi, this.namespace);
this.workloadOps = new WorkloadOperations(this.appsApi, this.namespace);
this.networkOps = new NetworkOperations(this.coreApi, this.networkingApi, this.namespace);
this.clusterOps = new ClusterOperations(this.coreApi, this.customObjectsApi, this.namespace);
this.customResourceOps = new CustomResourceOperations(this.customObjectsApi, this.namespace);
}
-1
View File
@@ -33,7 +33,6 @@ export class WebSocketService implements IWebSocketService {
timestamp: new Date().toISOString(),
});
// Send to all connected clients, removing any that fail
let failedClients = 0;
this.clients.forEach((client) => {
try {
-5
View File
@@ -7,7 +7,6 @@ datasource db {
provider = "postgresql"
}
// Better Auth Models
model User {
id String @id
name String
@@ -68,7 +67,6 @@ model Verification {
@@map("verification")
}
// Application Models
enum ServerType {
STATEFUL
STATELESS
@@ -141,16 +139,13 @@ model Server {
env_variables CustomEnvironmentVariable[] @relation("ServerEnvVars")
api_key String @unique
// Minecraft specific configurations
jar_type MinecraftServerJarType @default(VANILLA)
minecraft_version String @default("LATEST") // e.g., "LATEST", "1.20.4", "SNAPSHOT"
// JVM Options
jvm_opts String? // Custom JVM options
use_aikar_flags Boolean @default(false)
use_meowice_flags Boolean @default(false)
// Server Properties (common ones)
difficulty ServerDifficulty @default(EASY)
game_mode GameMode @default(SURVIVAL)
max_players Int @default(20)
@@ -10,7 +10,6 @@ export const NAMESPACE = process.env.KUBERNETES_NAMESPACE || "minikura";
export const ENABLE_CRD_REFLECTION = process.env.ENABLE_CRD_REFLECTION === "true";
// Resource types
export const RESOURCE_TYPES = {
MINECRAFT_SERVER: {
kind: "MinecraftServer",
@@ -26,8 +25,7 @@ export const RESOURCE_TYPES = {
},
};
// Polling intervals (in milliseconds)
export const SYNC_INTERVAL = 30 * 1000; // 30 seconds
export const SYNC_INTERVAL = 30 * 1000;
export const IMAGES = {
MINECRAFT: "itzg/minecraft-server",
@@ -9,7 +9,6 @@ export const RESOURCE_DEFAULTS = {
},
} as const;
// 80% of container memory goes to JVM heap; 20% headroom
export const JAVA_MEMORY_FACTOR = 0.8;
export const DEFAULT_SERVER_MEMORY = "1G";
-3
View File
@@ -4,7 +4,6 @@ import type {
Server as PrismaServer,
} from "@minikura/db";
// Base interface
export interface CustomResource {
apiVersion: string;
kind: string;
@@ -45,8 +44,6 @@ export interface MinecraftServerCRD extends CustomResource {
status?: MinecraftServerStatus;
}
// Reverse Proxy Types
export type ReverseProxyConfig = Pick<
PrismaReverseProxyServer,
| "id"
-2
View File
@@ -7,8 +7,6 @@ export function getErrorMessage(error: unknown): string {
}
return String(error);
}
/** Returns age string like "3d", "12h", "5m" */
export function getAge(timestamp: Date | string | undefined): string {
if (!timestamp) return "unknown";
+3 -7
View File
@@ -1,16 +1,12 @@
import pino from "pino";
export function createLogger(component: string): pino.Logger;
export function createLogger(context: Record<string, string | number>): pino.Logger;
export function createLogger(
context: Record<string, string | number>,
): pino.Logger;
export function createLogger(
componentOrContext: string | Record<string, string | number>,
componentOrContext: string | Record<string, string | number>
): pino.Logger {
const isString = typeof componentOrContext === "string";
const baseContext = isString
? { component: componentOrContext }
: componentOrContext;
const baseContext = isString ? { component: componentOrContext } : componentOrContext;
return pino({
level: process.env.LOG_LEVEL || "info",