Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.4 KB
Raw Blame
import { NextResponse } from "next/server";
import initializeCloudSync from "@/shared/services/initializeCloudSync";
import { startModelSyncScheduler } from "@/shared/services/modelSyncScheduler";

let syncInitialized = false;
let modelSyncInitialized = false;

// POST /api/sync/initialize - Initialize cloud sync scheduler
export async function POST(request) {
  try {
    if (syncInitialized) {
      return NextResponse.json({
        message: "Cloud sync already initialized",
      });
    }

    await initializeCloudSync();
    syncInitialized = true;

    // (#488) Start model auto-sync scheduler (6h default, configurable via MODEL_SYNC_INTERVAL_HOURS)
    if (!modelSyncInitialized) {
      startModelSyncScheduler();
      modelSyncInitialized = true;
    }

    return NextResponse.json({
      success: true,
      message: "Cloud sync initialized successfully",
      modelSyncEnabled: true,
    });
  } catch (error) {
    console.log("Error initializing cloud sync:", error);
    return NextResponse.json(
      {
        error: "Failed to initialize cloud sync",
      },
      { status: 500 }
    );
  }
}

// GET /api/sync/status - Check sync initialization status
export async function GET(request) {
  return NextResponse.json({
    initialized: syncInitialized,
    modelSyncInitialized,
    message: syncInitialized ? "Cloud sync is running" : "Cloud sync not initialized",
  });
}