fix: resolve architecture disconnects and codebase weaknesses
- fix(backend): replace raw .parse() with proper loadConfig() + ConfigError - fix(gateway): connect voice recording uploader to EventBroadcaster - fix(gateway): remove dead globalThis.moderationBroadcaster path in AI analyzer - fix(gateway): eliminate audioStream race condition by attaching handlers before pipe - fix(gateway): enable inlineVolume by default for setMusicVolume to work - fix(gateway): reuse persistent redisPub for command replies (no new connection per cmd) - fix(frontend): add missing voice_active_user/voice_pcm_data to WsEventMap - fix(frontend): correct onAttachmentUploaded handler signature to accept data - chore: move @types/pg from dependencies to devDependencies - chore: translate remaining Indonesian comments to English - chore: remove stale P3 TODO comment
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import "dotenv/config";
|
||||
import { ConfigError } from "@bete/shared/errors";
|
||||
import { z } from "zod";
|
||||
|
||||
const configSchema = z
|
||||
@@ -86,7 +87,31 @@ const configSchema = z
|
||||
.url()
|
||||
.default("https://upload.asepharyana.my.id/api/upload"),
|
||||
})
|
||||
.parse(process.env);
|
||||
.superRefine((value, ctx) => {
|
||||
if (!value.DATABASE_URL && !value.DATABASE_HOST) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
path: ["DATABASE_URL"],
|
||||
message: "Either DATABASE_URL or DATABASE_HOST must be provided",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const config = configSchema;
|
||||
export function loadConfig(
|
||||
env: NodeJS.ProcessEnv = process.env,
|
||||
): z.infer<typeof configSchema> {
|
||||
try {
|
||||
return configSchema.parse(env);
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
const messages = error.issues
|
||||
.map((e) => `${e.path.join(".")}: ${e.message}`)
|
||||
.join("\n");
|
||||
throw new ConfigError(`Configuration validation failed:\n${messages}`);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export const config = loadConfig();
|
||||
export type Config = typeof config;
|
||||
|
||||
Reference in New Issue
Block a user