diff --git a/src/app/(student)/tools/clean-pdf/ZoteroSection.tsx b/src/app/(student)/tools/clean-pdf/ZoteroSection.tsx index 74d9e31..b1ee081 100644 --- a/src/app/(student)/tools/clean-pdf/ZoteroSection.tsx +++ b/src/app/(student)/tools/clean-pdf/ZoteroSection.tsx @@ -8,6 +8,7 @@ export function ZoteroSection({ apiKey, baseUrl }: { apiKey: string; baseUrl: st const [key, setKey] = useState(apiKey); const [revealed, setRevealed] = useState(false); const [pending, startTransition] = useTransition(); + const [error, setError] = useState(null); 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`; @@ -15,9 +16,19 @@ export function ZoteroSection({ apiKey, baseUrl }: { apiKey: string; baseUrl: st function regenerate() { if (!confirm("Старый ключ перестанет работать (в том числе в Zotero). Продолжить?")) return; + setError(null); startTransition(async () => { - const res = await regeneratePdfApiKey(); - if (res.ok && res.key) { setKey(res.key); setRevealed(true); } + try { + const res = await regeneratePdfApiKey(); + if (res.ok && res.key) { + setKey(res.key); + setRevealed(true); + } else { + setError("Не удалось перевыпустить ключ, попробуйте ещё раз"); + } + } catch { + setError("Не удалось перевыпустить ключ, попробуйте ещё раз"); + } }); } @@ -40,6 +51,7 @@ export function ZoteroSection({ apiKey, baseUrl }: { apiKey: string; baseUrl: st

Ключ персональный — не публикуйте его. Если ключ утёк, перевыпустите: старый сразу отключится.

+ {error &&

{error}

}