● Zion Boggan
repos/Zion Pm/app/api/channels/route.ts
zionboggan.com ↗
18 lines · typescript
History for this file →
1
import { NextRequest, NextResponse } from 'next/server';
2
import { listChannels, createChannel, getChannelByName } from '@/lib/db';
3
 
4
export const runtime = 'nodejs';
5
export const dynamic = 'force-dynamic';
6
 
7
export async function GET() {
8
  return NextResponse.json({ channels: listChannels() });
9
}
10
 
11
export async function POST(req: NextRequest) {
12
  const { name, defaultModel } = await req.json();
13
  if (!name || !defaultModel) return NextResponse.json({ error: 'name and defaultModel required' }, { status: 400 });
14
  const clean = String(name).trim().replace(/^#/, '').replace(/\s+/g, '-').toLowerCase();
15
  if (getChannelByName(clean)) return NextResponse.json({ error: 'channel exists' }, { status: 409 });
16
  if (!['glm', 'claude', 'codex', 'ollama'].includes(defaultModel)) return NextResponse.json({ error: 'bad model' }, { status: 400 });
17
  return NextResponse.json({ channel: createChannel(clean, defaultModel) });
18
}