fix: add admin endpoint to make existing agents public
This commit is contained in:
parent
4b392a2eed
commit
2fe2fcef5c
2 changed files with 76 additions and 0 deletions
42
apps/web/src/app/api/admin/make-agents-public/route.ts
Normal file
42
apps/web/src/app/api/admin/make-agents-public/route.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
import { prisma } from '@tpmjs/db';
|
||||||
|
import { type NextRequest, NextResponse } from 'next/server';
|
||||||
|
|
||||||
|
export const runtime = 'nodejs';
|
||||||
|
export const dynamic = 'force-dynamic';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/admin/make-agents-public
|
||||||
|
* One-off endpoint to update all existing agents to be public.
|
||||||
|
* Protected by CRON_SECRET.
|
||||||
|
*/
|
||||||
|
export async function POST(request: NextRequest): Promise<NextResponse> {
|
||||||
|
// Verify authorization
|
||||||
|
const authHeader = request.headers.get('authorization');
|
||||||
|
const cronSecret = process.env.CRON_SECRET;
|
||||||
|
|
||||||
|
if (!cronSecret || authHeader !== `Bearer ${cronSecret}`) {
|
||||||
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Update all agents to be public
|
||||||
|
const result = await prisma.agent.updateMany({
|
||||||
|
where: { isPublic: false },
|
||||||
|
data: { isPublic: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get all agents for verification
|
||||||
|
const agents = await prisma.agent.findMany({
|
||||||
|
select: { id: true, name: true, isPublic: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
updated: result.count,
|
||||||
|
agents: agents.map((a) => ({ name: a.name, isPublic: a.isPublic })),
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to update agents:', error);
|
||||||
|
return NextResponse.json({ success: false, error: 'Failed to update agents' }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
34
packages/db/prisma/make-agents-public.ts
Normal file
34
packages/db/prisma/make-agents-public.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/**
|
||||||
|
* One-off script to update all existing agents to be public.
|
||||||
|
* Run with: pnpm --filter=@tpmjs/db exec tsx prisma/make-agents-public.ts
|
||||||
|
*/
|
||||||
|
import { PrismaClient } from '@prisma/client';
|
||||||
|
|
||||||
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
console.log('Updating all agents to be public...');
|
||||||
|
|
||||||
|
const result = await prisma.agent.updateMany({
|
||||||
|
where: { isPublic: false },
|
||||||
|
data: { isPublic: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`Updated ${result.count} agents to isPublic=true`);
|
||||||
|
|
||||||
|
// Show all agents now
|
||||||
|
const agents = await prisma.agent.findMany({
|
||||||
|
select: { id: true, name: true, isPublic: true },
|
||||||
|
});
|
||||||
|
console.log('\nAll agents:');
|
||||||
|
for (const agent of agents) {
|
||||||
|
console.log(` - ${agent.name} (isPublic: ${agent.isPublic})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
.catch((e) => {
|
||||||
|
console.error('Error:', e);
|
||||||
|
process.exit(1);
|
||||||
|
})
|
||||||
|
.finally(() => prisma.$disconnect());
|
||||||
Loading…
Add table
Add a link
Reference in a new issue