import { NextResponse } from "next/server"; import { deleteApiKey, isCloudEnabled } from "@/lib/localDb"; import { getConsistentMachineId } from "@/shared/utils/machineId"; import { syncToCloud } from "@/app/api/sync/cloud/route"; // DELETE /api/keys/[id] - Delete API key export async function DELETE(request, { params }) { try { const { id } = await params; const deleted = await deleteApiKey(id); if (!deleted) { return NextResponse.json({ error: "Key not found" }, { status: 404 }); } // Auto sync to Cloud if enabled await syncKeysToCloudIfEnabled(); return NextResponse.json({ message: "Key deleted successfully" }); } catch (error) { console.log("Error deleting key:", error); return NextResponse.json({ error: "Failed to delete key" }, { status: 500 }); } } /** * Sync API keys to Cloud if enabled */ async function syncKeysToCloudIfEnabled() { try { const cloudEnabled = await isCloudEnabled(); if (!cloudEnabled) return; const machineId = await getConsistentMachineId(); await syncToCloud(machineId); } catch (error) { console.log("Error syncing keys to cloud:", error); } }