Recompute Zotero script reactively on key regenerate

This commit is contained in:
2026-07-06 13:13:19 +05:00
parent 0cbea10e1a
commit fd40b1e394
2 changed files with 4 additions and 4 deletions
@@ -2,14 +2,16 @@
import { useState, useTransition } from "react"; import { useState, useTransition } from "react";
import { CodeOutput } from "@/components/tools/CodeOutput"; import { CodeOutput } from "@/components/tools/CodeOutput";
import { regeneratePdfApiKey } from "@/lib/actions/pdf-key-actions"; 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 [key, setKey] = useState(apiKey);
const [revealed, setRevealed] = useState(false); const [revealed, setRevealed] = useState(false);
const [pending, startTransition] = useTransition(); const [pending, startTransition] = useTransition();
const shownKey = revealed ? key : key.slice(0, 8) + "…" + key.slice(-4); 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 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() { function regenerate() {
if (!confirm("Старый ключ перестанет работать (в том числе в Zotero). Продолжить?")) return; if (!confirm("Старый ключ перестанет работать (в том числе в Zotero). Продолжить?")) return;
+1 -3
View File
@@ -2,7 +2,6 @@ import { headers } from "next/headers";
import { auth } from "@/lib/auth"; import { auth } from "@/lib/auth";
import { getMonthlyLimit, getMonthlyUsage, hasPaidAccess } from "@/lib/clean-pdf/access"; import { getMonthlyLimit, getMonthlyUsage, hasPaidAccess } from "@/lib/clean-pdf/access";
import { getOrCreatePdfKey } from "@/lib/clean-pdf/keys"; import { getOrCreatePdfKey } from "@/lib/clean-pdf/keys";
import { buildZoteroScript } from "@/lib/clean-pdf/zotero-script";
import { CleanPdfForm } from "./CleanPdfForm"; import { CleanPdfForm } from "./CleanPdfForm";
import { ZoteroSection } from "./ZoteroSection"; import { ZoteroSection } from "./ZoteroSection";
@@ -29,7 +28,6 @@ export default async function CleanPdfToolPage() {
const [key, used] = await Promise.all([getOrCreatePdfKey(userId), getMonthlyUsage(userId)]); const [key, used] = await Promise.all([getOrCreatePdfKey(userId), getMonthlyUsage(userId)]);
const limit = getMonthlyLimit(); const limit = getMonthlyLimit();
const baseUrl = process.env.NEXT_PUBLIC_APP_URL ?? "https://school.second-brain.ru"; const baseUrl = process.env.NEXT_PUBLIC_APP_URL ?? "https://school.second-brain.ru";
const zoteroScript = buildZoteroScript({ apiKey: key, baseUrl });
return ( return (
<main className="mx-auto w-full max-w-5xl px-6 py-8"> <main className="mx-auto w-full max-w-5xl px-6 py-8">
@@ -43,7 +41,7 @@ export default async function CleanPdfToolPage() {
</div> </div>
<div className="mt-6 card-aubade p-4"> <div className="mt-6 card-aubade p-4">
<ZoteroSection apiKey={key} script={zoteroScript} baseUrl={baseUrl} /> <ZoteroSection apiKey={key} baseUrl={baseUrl} />
</div> </div>
</main> </main>
); );