| import { NextResponse } from "next/server"; |
| import initializeCloudSync from "@/shared/services/initializeCloudSync"; |
| import { startModelSyncScheduler } from "@/shared/services/modelSyncScheduler"; |
|
|
| let syncInitialized = false; |
| let modelSyncInitialized = false; |
|
|
| |
| export async function POST(request) { |
| try { |
| if (syncInitialized) { |
| return NextResponse.json({ |
| message: "Cloud sync already initialized", |
| }); |
| } |
|
|
| await initializeCloudSync(); |
| syncInitialized = true; |
|
|
| |
| if (!modelSyncInitialized) { |
| const origin = request.headers.get("origin") || "http://localhost:20128"; |
| startModelSyncScheduler(origin); |
| 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 } |
| ); |
| } |
| } |
|
|
| |
| export async function GET(request) { |
| return NextResponse.json({ |
| initialized: syncInitialized, |
| modelSyncInitialized, |
| message: syncInitialized ? "Cloud sync is running" : "Cloud sync not initialized", |
| }); |
| } |
|
|