feat: establish NekoNest Cloud control and relay
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { getCloudViewer } from "@/app/cloud-auth";
|
||||
import {
|
||||
cancelPairingRequest,
|
||||
getOrCreateAccount,
|
||||
} from "@/db/repository";
|
||||
import { apiError, readJsonMutation } from "../../../respond";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const viewer = await getCloudViewer();
|
||||
if (!viewer) {
|
||||
return Response.json(
|
||||
{ error: "authentication_required", message: "请先登录" },
|
||||
{ status: 401, headers: { "cache-control": "no-store" } },
|
||||
);
|
||||
}
|
||||
const payload = await readJsonMutation<{ pairingId?: string }>(request);
|
||||
const account = await getOrCreateAccount(viewer);
|
||||
const result = await cancelPairingRequest({
|
||||
accountId: account.id,
|
||||
pairingId: payload.pairingId ?? "",
|
||||
actorId: viewer.userId,
|
||||
});
|
||||
return Response.json(result, {
|
||||
status: 200,
|
||||
headers: { "cache-control": "no-store" },
|
||||
});
|
||||
} catch (error) {
|
||||
const response = apiError(error);
|
||||
response.headers.set("cache-control", "no-store");
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { getCloudViewer } from "@/app/cloud-auth";
|
||||
import {
|
||||
createPairingRequest,
|
||||
getOrCreateAccount,
|
||||
getOwnedPairingProgress,
|
||||
} from "@/db/repository";
|
||||
import { apiError, readJsonMutation } from "../../respond";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const viewer = await getCloudViewer();
|
||||
if (!viewer) {
|
||||
return Response.json(
|
||||
{ error: "authentication_required", message: "请先登录" },
|
||||
{ status: 401, headers: { "cache-control": "no-store" } },
|
||||
);
|
||||
}
|
||||
const pairingId = new URL(request.url).searchParams.get("pairing_id") ?? "";
|
||||
const account = await getOrCreateAccount(viewer);
|
||||
const pairing = await getOwnedPairingProgress({
|
||||
accountId: account.id,
|
||||
pairingId,
|
||||
});
|
||||
return Response.json(
|
||||
{ pairing },
|
||||
{ status: 200, headers: { "cache-control": "no-store" } },
|
||||
);
|
||||
} catch (error) {
|
||||
const response = apiError(error);
|
||||
response.headers.set("cache-control", "no-store");
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const viewer = await getCloudViewer();
|
||||
if (!viewer) {
|
||||
return Response.json(
|
||||
{ error: "authentication_required", message: "请先登录" },
|
||||
{ status: 401 },
|
||||
);
|
||||
}
|
||||
const payload = await readJsonMutation<{
|
||||
requestedName?: string;
|
||||
os?: "windows" | "linux";
|
||||
}>(request);
|
||||
const account = await getOrCreateAccount(viewer);
|
||||
const pairing = await createPairingRequest({
|
||||
accountId: account.id,
|
||||
requestedName: payload.requestedName ?? "",
|
||||
os: payload.os ?? "windows",
|
||||
actorId: viewer.userId,
|
||||
});
|
||||
return Response.json(
|
||||
{ pairing },
|
||||
{ status: 201, headers: { "cache-control": "no-store" } },
|
||||
);
|
||||
} catch (error) {
|
||||
const response = apiError(error);
|
||||
response.headers.set("cache-control", "no-store");
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user