mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 20:32:20 +03:00
Require dashboard session cookies on protected management APIs and reject bearer API keys with explicit 403 responses to prevent privilege escalation across provider, settings, and model alias routes. Add a dedicated payload rules management surface with dashboard UI, OpenAPI documentation, route normalization, and tests for hot-reloaded runtime updates. Consolidate provider catalog metadata for dashboard pages, add Perplexity web-cookie provider support, retire the legacy provider creation page, and improve upstream proxy handling. Harden startup and runtime behavior by moving cloud sync bootstrap to server instrumentation, skipping background services during build/test, making models.dev sync abortable, pruning isolated build artifacts, and improving DB backup and recovery safeguards.
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import initializeCloudSync from "@/shared/services/initializeCloudSync";
|
|
import { startBudgetResetJob } from "@/lib/jobs/budgetResetJob";
|
|
import { startModelSyncScheduler } from "@/shared/services/modelSyncScheduler";
|
|
|
|
// Initialize runtime background sync services once per server process.
|
|
let initialized = false;
|
|
|
|
function isAutomatedTestProcess(
|
|
env: NodeJS.ProcessEnv = process.env,
|
|
argv: string[] = process.argv
|
|
): boolean {
|
|
return (
|
|
env.NODE_ENV === "test" || env.VITEST !== undefined || argv.some((arg) => arg.includes("test"))
|
|
);
|
|
}
|
|
|
|
export function shouldSkipCloudSyncInitialization(
|
|
env: NodeJS.ProcessEnv = process.env,
|
|
argv: string[] = process.argv
|
|
): boolean {
|
|
if (env.NEXT_PHASE === "phase-production-build") {
|
|
return true;
|
|
}
|
|
|
|
const raw = env.OMNIROUTE_DISABLE_BACKGROUND_SERVICES;
|
|
if (raw && new Set(["1", "true", "yes", "on"]).has(raw.trim().toLowerCase())) {
|
|
return true;
|
|
}
|
|
|
|
return isAutomatedTestProcess(env, argv) && env.OMNIROUTE_ENABLE_RUNTIME_BACKGROUND_TASKS !== "1";
|
|
}
|
|
|
|
export async function ensureCloudSyncInitialized() {
|
|
if (shouldSkipCloudSyncInitialization()) {
|
|
return false;
|
|
}
|
|
if (!initialized) {
|
|
try {
|
|
const { initTokenHealthCheck } = await import("@/lib/tokenHealthCheck");
|
|
initTokenHealthCheck();
|
|
await initializeCloudSync();
|
|
startModelSyncScheduler();
|
|
startBudgetResetJob();
|
|
initialized = true;
|
|
} catch (error) {
|
|
console.error("[ServerInit] Error initializing background sync services:", error);
|
|
}
|
|
}
|
|
return initialized;
|
|
}
|
|
|
|
export default ensureCloudSyncInitialized;
|