mirror of
https://github.com/codeaashu/claude-code.git
synced 2026-04-08 22:28:48 +03:00
claude-code
This commit is contained in:
42
web/app/api/share/[shareId]/route.ts
Normal file
42
web/app/api/share/[shareId]/route.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getShare, revokeShare, verifySharePassword } from "@/lib/share-store";
|
||||
|
||||
interface RouteContext {
|
||||
params: { shareId: string };
|
||||
}
|
||||
|
||||
export async function GET(req: NextRequest, { params }: RouteContext) {
|
||||
const { shareId } = params;
|
||||
const share = getShare(shareId);
|
||||
|
||||
if (!share) {
|
||||
return NextResponse.json({ error: "Share not found or expired" }, { status: 404 });
|
||||
}
|
||||
|
||||
if (share.visibility === "password") {
|
||||
const pw = req.headers.get("x-share-password") ?? req.nextUrl.searchParams.get("password");
|
||||
if (!pw || !verifySharePassword(shareId, pw)) {
|
||||
return NextResponse.json({ error: "Password required", requiresPassword: true }, { status: 401 });
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
id: share.id,
|
||||
title: share.conversation.title,
|
||||
messages: share.conversation.messages,
|
||||
model: share.conversation.model,
|
||||
createdAt: share.conversation.createdAt,
|
||||
shareCreatedAt: share.createdAt,
|
||||
});
|
||||
}
|
||||
|
||||
export async function DELETE(_req: NextRequest, { params }: RouteContext) {
|
||||
const { shareId } = params;
|
||||
const deleted = revokeShare(shareId);
|
||||
|
||||
if (!deleted) {
|
||||
return NextResponse.json({ error: "Share not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
}
|
||||
50
web/app/api/share/route.ts
Normal file
50
web/app/api/share/route.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { nanoid } from "nanoid";
|
||||
import type { Conversation } from "@/lib/types";
|
||||
import type { ShareVisibility, ShareExpiry } from "@/lib/share-store";
|
||||
import { createShare } from "@/lib/share-store";
|
||||
|
||||
interface CreateShareRequest {
|
||||
conversation: Conversation;
|
||||
visibility: ShareVisibility;
|
||||
password?: string;
|
||||
expiry: ShareExpiry;
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
let body: CreateShareRequest;
|
||||
try {
|
||||
body = await req.json();
|
||||
} catch {
|
||||
return NextResponse.json({ error: "Invalid JSON body" }, { status: 400 });
|
||||
}
|
||||
|
||||
const { conversation, visibility, password, expiry } = body;
|
||||
if (!conversation || !visibility || !expiry) {
|
||||
return NextResponse.json({ error: "Missing required fields" }, { status: 400 });
|
||||
}
|
||||
|
||||
if (visibility === "password" && !password) {
|
||||
return NextResponse.json(
|
||||
{ error: "Password required for password-protected shares" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const shareId = nanoid(12);
|
||||
const share = createShare(shareId, { conversation, visibility, password, expiry });
|
||||
|
||||
const origin = req.headers.get("origin") ?? "";
|
||||
const url = `${origin}/share/${shareId}`;
|
||||
|
||||
return NextResponse.json({
|
||||
id: share.id,
|
||||
conversationId: share.conversationId,
|
||||
visibility: share.visibility,
|
||||
hasPassword: !!share.passwordHash,
|
||||
expiry: share.expiry,
|
||||
expiresAt: share.expiresAt,
|
||||
createdAt: share.createdAt,
|
||||
url,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user