ebe0c77f7e
CI / build (push) Has been cancelled
Reopen advanced edits from their saved recipe, seed or take over the quick editor from them, refresh thumbnails after a save, and add an edited-only download. Also fixes the Lumenroom library collapsing to slivers on large shoots and documents deploying both containers on a new host. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { NextRequest } from "next/server";
|
|
import { authenticateBridge } from "@/db/bridge";
|
|
import {
|
|
BRIDGE_SESSION_TTL_SECONDS,
|
|
bridgeReturnUrl,
|
|
signBridgeToken,
|
|
} from "@/lib/bridge";
|
|
import { errorResponse, jsonResponse } from "@/lib/http";
|
|
|
|
/**
|
|
* POST /api/bridge/sessions/:sessionId/exchange
|
|
*
|
|
* The login token is deliberately short-lived because it travels in a URL.
|
|
* The editor exchanges it once for a service token it keeps server-side; that
|
|
* token authorizes the photo proxy and the save-back calls.
|
|
*/
|
|
export const POST = async (
|
|
req: NextRequest,
|
|
{ params }: { params: Promise<{ sessionId: string }> },
|
|
) => {
|
|
const { sessionId } = await params;
|
|
const auth = await authenticateBridge(req, sessionId, "login");
|
|
if (!auth) return errorResponse(401, "invalid or expired bridge token");
|
|
|
|
const token = signBridgeToken({
|
|
sid: auth.session.id,
|
|
eid: auth.session.eventId,
|
|
uid: auth.user.id,
|
|
email: auth.user.email,
|
|
name: auth.user.name,
|
|
kind: "service",
|
|
exp: Math.floor(Date.now() / 1000) + BRIDGE_SESSION_TTL_SECONDS,
|
|
});
|
|
|
|
return jsonResponse({
|
|
token,
|
|
sessionId: auth.session.id,
|
|
eventId: auth.session.eventId,
|
|
expiresAt: auth.session.expiresAt,
|
|
// Carried from the browser-facing request that opened the editor so the
|
|
// editor can link back to the address the user actually reached.
|
|
returnUrl:
|
|
auth.payload.ret ?? bridgeReturnUrl(auth.session.eventId) ?? null,
|
|
});
|
|
};
|