Recompute Zotero script reactively on key regenerate
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 (
|
||||
<main className="mx-auto w-full max-w-5xl px-6 py-8">
|
||||
@@ -43,7 +41,7 @@ export default async function CleanPdfToolPage() {
|
||||
</div>
|
||||
|
||||
<div className="mt-6 card-aubade p-4">
|
||||
<ZoteroSection apiKey={key} script={zoteroScript} baseUrl={baseUrl} />
|
||||
<ZoteroSection apiKey={key} baseUrl={baseUrl} />
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user