feat(zero): admin panel section + site /zero page + autogen card
Admin (/admin/zero):
- new AdminZero with list, status filters, generate button (bucket + allow_dup)
- per-note actions: approve, edit inline, regenerate (bucket pick), skip,
'publish now' (approve + scheduled_at=now → runner picks up within 1m)
- config panel: toggle on/off, generate/approve/publish hour MSK, site URL base
- new pin 'Зеро' (☕) in AdminNav
Site (zeropost.ru):
- ZeroBlock — feed of last 3-6 Zero notes, rendered on home next to Серии
- /zero — full Zero notes list page with character bio block (avatar + bullets)
Autogen integration:
- ZeroAutogenCard on /admin/autogen — amber card with on/off, hour pickers,
'generate now' and last-3 preview, link to full section
Plumbing:
- lib/engine.js: listZeroNotes(), getZeroCharacter()
- app/admin/api/zero/[...path]/route.js: catch-all proxy with cookie auth
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { requireAdminAuth } from '@/lib/adminAuth';
|
||||
import AutogenPanel from '@/components/admin/AutogenPanel';
|
||||
import ZeroAutogenCard from '@/components/admin/ZeroAutogenCard';
|
||||
import Link from 'next/link';
|
||||
import { Coffee, ArrowRight } from 'lucide-react';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
export const metadata = { title: 'Автогенерация' };
|
||||
@@ -18,11 +21,33 @@ async function engineCall(path) {
|
||||
|
||||
export default async function AutogenPage() {
|
||||
await requireAdminAuth();
|
||||
const [status, queue, topics] = await Promise.all([
|
||||
const [status, queue, topics, zeroConfig, zeroNotes] = await Promise.all([
|
||||
engineCall('/api/autogen/status'),
|
||||
engineCall('/api/autogen/queue'),
|
||||
engineCall('/api/autogen/topics'),
|
||||
engineCall('/api/admin/zero/config'),
|
||||
engineCall('/api/admin/zero/notes?limit=5'),
|
||||
]);
|
||||
|
||||
return <AutogenPanel status={status || []} queue={queue || []} topics={topics || {}} />;
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<AutogenPanel status={status || []} queue={queue || []} topics={topics || {}} />
|
||||
|
||||
{/* Блок Зеро — отдельная карточка рядом с категориями статей */}
|
||||
<div className="border-t border-neutral-200 dark:border-neutral-800 pt-8">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div>
|
||||
<h2 className="text-lg font-bold text-neutral-900 dark:text-neutral-100 flex items-center gap-2">
|
||||
<Coffee className="w-5 h-5 text-amber-500" /> Заметки от Зеро
|
||||
</h2>
|
||||
<p className="text-xs text-neutral-500 mt-0.5">AI-персонаж в @zeropostru — отдельный пайплайн</p>
|
||||
</div>
|
||||
<Link href="/admin/zero" className="text-sm text-emerald-600 hover:underline inline-flex items-center gap-1">
|
||||
Полный раздел <ArrowRight className="w-3 h-3" />
|
||||
</Link>
|
||||
</div>
|
||||
<ZeroAutogenCard initialConfig={zeroConfig?.config || null} recentNotes={zeroNotes?.items || []} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { requireAdminAuth } from '@/lib/adminAuth';
|
||||
import AdminZero from '@/components/admin/AdminZero';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
export const metadata = { title: 'Заметки от Зеро' };
|
||||
|
||||
export default async function AdminZeroPage() {
|
||||
await requireAdminAuth();
|
||||
return <AdminZero />;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Catch-all proxy для /admin/api/zero/* → engine /api/admin/zero/*
|
||||
* Auth: session cookie через checkAdminAuth().
|
||||
*/
|
||||
import { NextResponse } from 'next/server';
|
||||
import { checkAdminAuth } from '@/lib/adminAuth';
|
||||
|
||||
const E = process.env.ENGINE_URL || 'http://127.0.0.1:3030';
|
||||
const S = process.env.ENGINE_SECRET || 'zeropost_internal_2026';
|
||||
|
||||
async function proxy(req, { params }) {
|
||||
if (!(await checkAdminAuth())) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
const resolved = await params;
|
||||
const tail = (resolved?.path || []).join('/');
|
||||
const qs = req.url.split('?')[1];
|
||||
const url = `${E}/api/admin/zero${tail ? '/' + tail : ''}${qs ? '?' + qs : ''}`;
|
||||
|
||||
const headers = {
|
||||
'x-internal-secret': S,
|
||||
'x-user-id': '1', // engine requireAdmin требует is_admin=true; на проде у нас один админ
|
||||
};
|
||||
|
||||
let body;
|
||||
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
||||
headers['Content-Type'] = 'application/json';
|
||||
const raw = await req.text();
|
||||
body = raw || undefined;
|
||||
}
|
||||
|
||||
const res = await fetch(url, { method: req.method, headers, body, cache: 'no-store' });
|
||||
const data = await res.json().catch(() => ({ error: 'invalid engine response' }));
|
||||
return NextResponse.json(data, { status: res.status });
|
||||
}
|
||||
|
||||
export const GET = proxy;
|
||||
export const POST = proxy;
|
||||
export const PATCH = proxy;
|
||||
export const PUT = proxy;
|
||||
export const DELETE = proxy;
|
||||
+14
-3
@@ -6,12 +6,13 @@ import HeroImage from '@/components/HeroImage';
|
||||
import Stats from '@/components/Stats';
|
||||
import NowBlock from '@/components/NowBlock';
|
||||
import NotesBlock from '@/components/NotesBlock';
|
||||
import ZeroBlock from '@/components/ZeroBlock';
|
||||
import SeriesGrid from '@/components/SeriesGrid';
|
||||
import CategoryRow from '@/components/CategoryRow';
|
||||
import PopularBlock from '@/components/PopularBlock';
|
||||
import RecentBlock from '@/components/RecentBlock';
|
||||
import Reveal from '@/components/Reveal';
|
||||
import { getHomeData, listTags, getStats, getLive, listNotes, listSeries, listCategories } from '@/lib/engine';
|
||||
import { getHomeData, listTags, getStats, getLive, listNotes, listSeries, listCategories, listZeroNotes } from '@/lib/engine';
|
||||
import { Sparkles, ArrowRight } from 'lucide-react';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
@@ -20,10 +21,10 @@ const CATEGORY_ORDER = ['ai-tools', 'ai-dev', 'automation', 'cybersec'];
|
||||
|
||||
export default async function HomePage() {
|
||||
let home = { hero: null, byCategory: {}, popular: [], recent: [] };
|
||||
let tags = [], stats = null, live = null, notes = [], series = [], categories = [];
|
||||
let tags = [], stats = null, live = null, notes = [], series = [], categories = [], zeroNotes = [];
|
||||
|
||||
try {
|
||||
[home, tags, stats, live, notes, series, categories] = await Promise.all([
|
||||
[home, tags, stats, live, notes, series, categories, zeroNotes] = await Promise.all([
|
||||
getHomeData(),
|
||||
listTags(),
|
||||
getStats(),
|
||||
@@ -31,6 +32,7 @@ export default async function HomePage() {
|
||||
listNotes({ limit: 6 }),
|
||||
listSeries(),
|
||||
listCategories(),
|
||||
listZeroNotes({ limit: 6 }),
|
||||
]);
|
||||
} catch (err) {
|
||||
console.error('Home load failed:', err.message);
|
||||
@@ -131,6 +133,15 @@ export default async function HomePage() {
|
||||
</Reveal>
|
||||
)}
|
||||
|
||||
{/* ЗЕРО — короткие заметки AI-персонажа */}
|
||||
{zeroNotes.length > 0 && (
|
||||
<Reveal>
|
||||
<div className="reveal">
|
||||
<ZeroBlock notes={zeroNotes} compact />
|
||||
</div>
|
||||
</Reveal>
|
||||
)}
|
||||
|
||||
{/* КАТЕГОРИЙНЫЕ РЯДЫ */}
|
||||
{CATEGORY_ORDER.map(cat => (
|
||||
<Reveal key={cat}>
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
import Header from '@/components/Header';
|
||||
import Footer from '@/components/Footer';
|
||||
import ZeroBlock from '@/components/ZeroBlock';
|
||||
import { listZeroNotes, getZeroCharacter } from '@/lib/engine';
|
||||
import { Coffee } from 'lucide-react';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
export const metadata = {
|
||||
title: 'Заметки от Зеро',
|
||||
description: 'Короткие посты от AI-персонажа Зеро — мысли программиста о работе, инструментах и забавных багах',
|
||||
};
|
||||
|
||||
export default async function ZeroPage() {
|
||||
const [notes, character] = await Promise.all([
|
||||
listZeroNotes({ limit: 100 }),
|
||||
getZeroCharacter(),
|
||||
]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header />
|
||||
<main className="pt-10 pb-16">
|
||||
<div className="container-wide mb-10">
|
||||
<div
|
||||
className="inline-flex items-center gap-2 text-xs accent px-3 py-1.5 rounded-full mb-4"
|
||||
style={{ background: 'rgb(var(--accent) / 0.1)', border: '1px solid rgb(var(--accent) / 0.2)' }}
|
||||
>
|
||||
<Coffee className="w-3.5 h-3.5" /> AI-персонаж
|
||||
</div>
|
||||
<h1 className="text-3xl sm:text-5xl font-bold ink mb-3 leading-tight">
|
||||
Заметки от Зеро
|
||||
</h1>
|
||||
<p className="mute text-base sm:text-lg max-w-2xl mb-8">
|
||||
Короткие посты от первого лица в Telegram-канале{' '}
|
||||
<a href="https://t.me/zeropostru" target="_blank" rel="noreferrer" className="accent hover:underline">@zeropostru</a>.
|
||||
Программист с многолетним опытом, любит копаться под капотом, постоянно носится с кофе.
|
||||
</p>
|
||||
|
||||
{character?.character?.bio && (
|
||||
<div className="rounded-xl border border-amber-200 dark:border-amber-900 bg-amber-50/50 dark:bg-amber-950/20 p-5 sm:p-6 max-w-3xl">
|
||||
<div className="flex items-start gap-4">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
src="/uploads/zero-coffee.webp"
|
||||
alt="Зеро"
|
||||
className="w-16 h-16 rounded-full object-cover bg-amber-100 dark:bg-amber-950/40 ring-2 ring-amber-300 dark:ring-amber-800 shrink-0"
|
||||
/>
|
||||
<div className="min-w-0">
|
||||
<div className="text-sm font-semibold ink mb-2">Кто такой Зеро</div>
|
||||
<ul className="space-y-1 text-sm mute">
|
||||
{character.character.bio.map((line, i) => (
|
||||
<li key={i}>— {line}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{notes.length > 0 ? (
|
||||
<ZeroBlock notes={notes} />
|
||||
) : (
|
||||
<div className="container-wide">
|
||||
<div className="rounded-xl border border-neutral-200 dark:border-neutral-800 p-10 text-center">
|
||||
<Coffee className="w-8 h-8 text-amber-500 mx-auto mb-3" />
|
||||
<p className="mute text-sm">Зеро ещё не написал ни одной заметки. Скоро появится.</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</main>
|
||||
<Footer />
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user