Update lock files and cleanup
This commit is contained in:
@@ -3,6 +3,16 @@ import { enqueueJob } from '../jobs/queue.js';
|
||||
import { registerClient } from '../ws/broadcast.js';
|
||||
import { findModel, DEFAULT_MODEL_ID } from '../models.js';
|
||||
|
||||
/**
|
||||
* Strip image data from a job object before sending it to clients.
|
||||
* Images are only needed server-side during processing.
|
||||
*/
|
||||
function sanitizeJob(job) {
|
||||
const json = job.toJSON();
|
||||
delete json.imageDataUrl;
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('fastify').FastifyInstance} fastify
|
||||
*/
|
||||
@@ -16,7 +26,7 @@ export async function jobRoutes(fastify) {
|
||||
Job.findAll({ order: [['createdAt', 'DESC']], limit: 100 })
|
||||
.then((jobs) => {
|
||||
if (socket.readyState === 1) {
|
||||
socket.send(JSON.stringify({ type: 'init', jobs: jobs.map((j) => j.toJSON()) }));
|
||||
socket.send(JSON.stringify({ type: 'init', jobs: jobs.map(sanitizeJob) }));
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
@@ -56,7 +66,7 @@ export async function jobRoutes(fastify) {
|
||||
});
|
||||
|
||||
enqueueJob(job.id);
|
||||
return reply.status(201).send(job.toJSON());
|
||||
return reply.status(201).send(sanitizeJob(job));
|
||||
});
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
@@ -64,7 +74,7 @@ export async function jobRoutes(fastify) {
|
||||
// ------------------------------------------------------------------
|
||||
fastify.get('/api/jobs', async (_req, reply) => {
|
||||
const jobs = await Job.findAll({ order: [['createdAt', 'DESC']], limit: 100 });
|
||||
return reply.send(jobs.map((j) => j.toJSON()));
|
||||
return reply.send(jobs.map(sanitizeJob));
|
||||
});
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
@@ -73,6 +83,6 @@ export async function jobRoutes(fastify) {
|
||||
fastify.get('/api/jobs/:id', async (req, reply) => {
|
||||
const job = await Job.findByPk(req.params.id);
|
||||
if (!job) return reply.status(404).send({ error: 'Not found' });
|
||||
return reply.send(job.toJSON());
|
||||
return reply.send(sanitizeJob(job));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user