Initial working state: CL3.5 complete (Plesk sync + suspend/unsuspend)
This commit is contained in:
52
app/api/plesk/instances/[id]/sync/route.ts
Normal file
52
app/api/plesk/instances/[id]/sync/route.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { assertAgencyAdmin, getRouteAgencyContextOrThrow } from "@/lib/agency";
|
||||
import { assertRateLimit } from "@/lib/api/rate-limit";
|
||||
import { assertSameOrigin } from "@/lib/api/security";
|
||||
import { syncPleskInstance } from "@/lib/plesk/sync";
|
||||
import { createSupabaseRouteClient } from "@/lib/supabase/route";
|
||||
|
||||
export async function POST(
|
||||
req: Request,
|
||||
{ params }: { params: { id: string } },
|
||||
) {
|
||||
try {
|
||||
assertSameOrigin(req);
|
||||
|
||||
const context = await getRouteAgencyContextOrThrow();
|
||||
assertAgencyAdmin(context);
|
||||
assertRateLimit(`plesk-sync:${context.userId}`, 8, 60_000);
|
||||
|
||||
const supabase = createSupabaseRouteClient() as any;
|
||||
|
||||
const { data: instance, error: instanceError } = await supabase
|
||||
.from("plesk_instances")
|
||||
.select(
|
||||
"id, agency_id, base_url, auth_type, encrypted_secret, last_connected_at",
|
||||
)
|
||||
.eq("id", params.id)
|
||||
.eq("agency_id", context.agencyId)
|
||||
.single();
|
||||
|
||||
if (instanceError || !instance) throw new Error("Plesk instance not found");
|
||||
|
||||
const result = await syncPleskInstance(
|
||||
supabase,
|
||||
instance,
|
||||
context.userId,
|
||||
"sync",
|
||||
);
|
||||
|
||||
return NextResponse.json({
|
||||
subscriptionsUpserted: result.subscriptionsUpserted,
|
||||
domainsUpserted: result.domainsUpserted,
|
||||
skipped: result.skipped,
|
||||
reason: result.reason,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: error instanceof Error ? error.message : "Sync failed" },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user