fix: images, couverture, slash, agents, wizard, Stripe et admin
- Collage/accès images: ownership path userId + meta legacy, 403 non caché - Couverture note: explicite (choix/aucune), plus d’auto depuis le corps - Éditeur: suppression image TipTap, sync immédiate, toolbar réordonnée - Slash: listes par titre (plus d’index), keywords nettoyés - Agents: nextRun à la réactivation, cron sans stampede null - Wizard: titres courts + mode Expert plus robuste - Stripe checkout hosted fiable; admin métriques live; dark mode IA/settings - Indexation notes courtes + test unit aligné
This commit is contained in:
@@ -27,10 +27,12 @@ export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const now = new Date()
|
||||
|
||||
// Due = nextRun in the past; also backfill agents whose nextRun was never set
|
||||
// (legacy / toggle bug) — but only schedule them, don't stampede-execute all nulls
|
||||
const dueAgents = await prisma.agent.findMany({
|
||||
where: {
|
||||
isEnabled: true,
|
||||
frequency: { not: 'manual' },
|
||||
frequency: { notIn: ['manual', 'one-shot'] },
|
||||
nextRun: { lte: now },
|
||||
},
|
||||
select: {
|
||||
@@ -40,13 +42,44 @@ export async function POST(request: NextRequest) {
|
||||
scheduledTime: true,
|
||||
scheduledDay: true,
|
||||
timezone: true,
|
||||
nextRun: true,
|
||||
},
|
||||
orderBy: { nextRun: 'asc' },
|
||||
})
|
||||
|
||||
if (dueAgents.length === 0) {
|
||||
return NextResponse.json({ success: true, executed: 0 })
|
||||
// One-time repair: set nextRun for enabled scheduled agents stuck with null
|
||||
const unscheduled = await prisma.agent.findMany({
|
||||
where: {
|
||||
isEnabled: true,
|
||||
frequency: { notIn: ['manual', 'one-shot'] },
|
||||
nextRun: null,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
frequency: true,
|
||||
scheduledTime: true,
|
||||
scheduledDay: true,
|
||||
timezone: true,
|
||||
},
|
||||
take: 50,
|
||||
})
|
||||
for (const a of unscheduled) {
|
||||
const nextRun = calculateNextRun({
|
||||
frequency: a.frequency,
|
||||
scheduledTime: a.scheduledTime,
|
||||
scheduledDay: a.scheduledDay,
|
||||
timezone: a.timezone,
|
||||
})
|
||||
await prisma.agent.update({ where: { id: a.id }, data: { nextRun } })
|
||||
}
|
||||
|
||||
if (dueAgents.length === 0) {
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
executed: 0,
|
||||
repairedSchedules: unscheduled.length,
|
||||
})
|
||||
}
|
||||
|
||||
const results: { id: string; success: boolean; error?: string }[] = []
|
||||
|
||||
@@ -56,7 +89,6 @@ export async function POST(request: NextRequest) {
|
||||
const { executeAgent } = await import('@/lib/ai/services/agent-executor.service')
|
||||
const result = await executeAgent(agent.id, agent.userId)
|
||||
|
||||
// Calculate and set next run
|
||||
const nextRun = calculateNextRun({
|
||||
frequency: agent.frequency,
|
||||
scheduledTime: agent.scheduledTime,
|
||||
@@ -64,7 +96,6 @@ export async function POST(request: NextRequest) {
|
||||
timezone: agent.timezone,
|
||||
})
|
||||
|
||||
|
||||
await prisma.agent.update({
|
||||
where: { id: agent.id },
|
||||
data: { nextRun },
|
||||
@@ -75,7 +106,6 @@ export async function POST(request: NextRequest) {
|
||||
const msg = error instanceof Error ? error.message : 'Unknown error'
|
||||
console.error(`[CronAgents] Agent ${agent.id} failed:`, msg)
|
||||
|
||||
// Still schedule next run even on failure
|
||||
const nextRun = calculateNextRun({
|
||||
frequency: agent.frequency,
|
||||
scheduledTime: agent.scheduledTime,
|
||||
|
||||
Reference in New Issue
Block a user