From fd40b1e394976f49d8ead1d29931fe6abfe8d34e Mon Sep 17 00:00:00 2001 From: dmitriylaukhin Date: Mon, 6 Jul 2026 13:13:19 +0500 Subject: [PATCH] Recompute Zotero script reactively on key regenerate --- src/app/(student)/tools/clean-pdf/ZoteroSection.tsx | 4 +++- src/app/(student)/tools/clean-pdf/page.tsx | 4 +--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/(student)/tools/clean-pdf/ZoteroSection.tsx b/src/app/(student)/tools/clean-pdf/ZoteroSection.tsx index 20b4b14..74d9e31 100644 --- a/src/app/(student)/tools/clean-pdf/ZoteroSection.tsx +++ b/src/app/(student)/tools/clean-pdf/ZoteroSection.tsx @@ -2,14 +2,16 @@ import { useState, useTransition } from "react"; import { CodeOutput } from "@/components/tools/CodeOutput"; import { regeneratePdfApiKey } from "@/lib/actions/pdf-key-actions"; +import { buildZoteroScript } from "@/lib/clean-pdf/zotero-script"; -export function ZoteroSection({ apiKey, script, baseUrl }: { apiKey: string; script: string; baseUrl: string }) { +export function ZoteroSection({ apiKey, baseUrl }: { apiKey: string; baseUrl: string }) { const [key, setKey] = useState(apiKey); const [revealed, setRevealed] = useState(false); const [pending, startTransition] = useTransition(); const shownKey = revealed ? key : key.slice(0, 8) + "…" + key.slice(-4); const curlExample = `curl -H "Authorization: Bearer ${key}" \\\n "${baseUrl}/api/pdf?url=https://example.com/article&format=A4&theme=light" \\\n -o article.pdf`; + const script = buildZoteroScript({ apiKey: key, baseUrl }); function regenerate() { if (!confirm("Старый ключ перестанет работать (в том числе в Zotero). Продолжить?")) return; diff --git a/src/app/(student)/tools/clean-pdf/page.tsx b/src/app/(student)/tools/clean-pdf/page.tsx index 2d767e9..0c53054 100644 --- a/src/app/(student)/tools/clean-pdf/page.tsx +++ b/src/app/(student)/tools/clean-pdf/page.tsx @@ -2,7 +2,6 @@ import { headers } from "next/headers"; import { auth } from "@/lib/auth"; import { getMonthlyLimit, getMonthlyUsage, hasPaidAccess } from "@/lib/clean-pdf/access"; import { getOrCreatePdfKey } from "@/lib/clean-pdf/keys"; -import { buildZoteroScript } from "@/lib/clean-pdf/zotero-script"; import { CleanPdfForm } from "./CleanPdfForm"; import { ZoteroSection } from "./ZoteroSection"; @@ -29,7 +28,6 @@ export default async function CleanPdfToolPage() { const [key, used] = await Promise.all([getOrCreatePdfKey(userId), getMonthlyUsage(userId)]); const limit = getMonthlyLimit(); const baseUrl = process.env.NEXT_PUBLIC_APP_URL ?? "https://school.second-brain.ru"; - const zoteroScript = buildZoteroScript({ apiKey: key, baseUrl }); return (
@@ -43,7 +41,7 @@ export default async function CleanPdfToolPage() {
- +
);