/** * GET /api/settings/print-agents/jobs/mine?since= (session) * Jobs created by the current user that changed after `since` (+ all still-open ones). * Polled by plugins/05.print-jobs.client.ts as the cross-PM2-worker fallback for the SSE toasts. */ import { requireAdminSession } from '../../../../utils/printAgentAuth' import { listJobs } from '../../../../utils/printSpoolDb' export default defineEventHandler(async (event) => { const session = await requireAdminSession(event) if (!session.userId) return { status: 200, jobs: [], serverTime: new Date().toISOString() } const since = String(getQuery(event).since || '').trim() const changed = listJobs({ userId: session.userId, sinceIso: since || undefined, limit: 300 }) const open = listJobs({ userId: session.userId, status: ['queued', 'sent'], limit: 300 }) const seen = new Set() const jobs = [...changed, ...open].filter(j => (seen.has(j.id) ? false : (seen.add(j.id), true))).map(j => ({ id: j.id, batchId: j.batch_id, queue: j.queue, status: j.status, source: j.source, error: j.error, createdAt: j.created_at, updatedAt: j.updated_at })) // SQLite CURRENT_TIMESTAMP is UTC 'YYYY-MM-DD HH:MM:SS' — hand the client a cursor in that format const serverTime = new Date().toISOString().replace('T', ' ').slice(0, 19) return { status: 200, jobs, serverTime } })