From bbbae29280930e9efb8ad8e5fa753e897eff2e85 Mon Sep 17 00:00:00 2001 From: nstarikov Date: Mon, 24 Aug 2026 10:31:05 +0300 Subject: [PATCH] feat: add API for external draft creation --- admin/src/App.tsx | 58 +++++++++++++++++++++++++++ app/auth.py | 2 +- app/routes.py | 92 +++++++++++++++++++++++++++++++++++++++++- docs/draft-api.md | 100 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 250 insertions(+), 2 deletions(-) create mode 100644 docs/draft-api.md diff --git a/admin/src/App.tsx b/admin/src/App.tsx index a346ad6..b6e4ee8 100644 --- a/admin/src/App.tsx +++ b/admin/src/App.tsx @@ -40,6 +40,8 @@ type AppSettings = { imageApiUrl: string imageModel: string imageApiTokenConfigured: boolean + draftApiKeyConfigured: boolean + draftApiKeyPrefix: string } type ImageGenerationTarget = "cover" | "middle" | "final" @@ -779,8 +781,11 @@ function SettingsPanel({ onBack, onSaved }: { onBack: () => void; onSaved: (sett imageApiUrl: "https://polza.ai/api", imageModel: "google/gemini-3.1-flash-image", imageApiTokenConfigured: false, + draftApiKeyConfigured: false, + draftApiKeyPrefix: "", }) const [imageApiToken, setImageApiToken] = useState("") + const [draftApiKey, setDraftApiKey] = useState("") const [loading, setLoading] = useState(true) const [saving, setSaving] = useState(false) const [dirty, setDirty] = useState(false) @@ -845,6 +850,8 @@ function SettingsPanel({ onBack, onSaved }: { onBack: () => void; onSaved: (sett imageApiUrl: settings.imageApiUrl.trim(), imageModel: settings.imageModel.trim(), imageApiTokenConfigured: settings.imageApiTokenConfigured, + draftApiKeyConfigured: settings.draftApiKeyConfigured, + draftApiKeyPrefix: settings.draftApiKeyPrefix, } const payload: Record = { ...next } if (imageApiToken.trim()) payload.imageApiToken = imageApiToken.trim() @@ -887,6 +894,20 @@ function SettingsPanel({ onBack, onSaved }: { onBack: () => void; onSaved: (sett } } + async function generateDraftApiKey() { + setSaving(true) + try { + const generated = await api<{ apiKey: string; prefix: string }>("/api/settings/draft-api-key", { method: "POST" }) + setDraftApiKey(generated.apiKey) + setSettings((current) => ({ ...current, draftApiKeyConfigured: true, draftApiKeyPrefix: generated.prefix })) + setMessage("API-ключ создан. Скопируйте его сейчас: повторно показать ключ нельзя.") + } catch (error) { + setMessage(`Не удалось создать API-ключ: ${error instanceof Error ? error.message : String(error)}`) + } finally { + setSaving(false) + } + } + async function registerPasskey() { setPasskeyBusy(true) try { @@ -994,6 +1015,41 @@ function SettingsPanel({ onBack, onSaved }: { onBack: () => void; onSaved: (sett ) : null} + {!loading ? ( + + + API для создания черновиков + Внешний ИИ сможет создавать новые черновики через POST-запрос. При перевыпуске старый ключ сразу перестаёт работать. + + +
+ Статус + + {settings.draftApiKeyConfigured ? `Ключ задан (${settings.draftApiKeyPrefix}...)` : "Ключ ещё не создан"} + +
+ {draftApiKey ? ( +
+

Скопируйте ключ сейчас. В целях безопасности он больше не будет показан в настройках.

+
+ + +
+
+ ) : null} +
+ + Передавайте ключ только в заголовке Authorization: Bearer. +
+
+
+ ) : null}