Update lock files and cleanup

This commit is contained in:
khalid@traclabs.com
2026-05-14 09:00:04 -05:00
parent 62e5e309ad
commit 4564fb1b56
8 changed files with 1310 additions and 708 deletions

View File

@@ -74,9 +74,17 @@ function broadcastQueueStats() {
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
/** Strip image data before sending job info to clients. */
function sanitizeJob(job) {
const json = job.toJSON();
delete json.imageDataUrl;
return json;
}
async function setStatus(job, status, extra = {}) {
await job.update({ status, ...extra });
broadcast({ type: 'job_update', job: job.toJSON() });
broadcast({ type: 'job_update', job: sanitizeJob(job) });
}
/** Padding factor applied to each side of the detected bounding box. */
@@ -211,6 +219,14 @@ async function cropImage(imageDataUrl, bbox, padding = BBOX_PADDING) {
};
}
/**
* Scrub image data from the job row so we don't persist user photos.
* Called in both the success and error paths.
*/
async function clearImageData(job) {
await job.update({ imageDataUrl: null });
}
// ---------------------------------------------------------------------------
// Main runner — two-pass: detect bbox → crop → analyse cropped image
// ---------------------------------------------------------------------------
@@ -245,7 +261,7 @@ async function runJob(jobId) {
bboxWidth: bboxResult.bbox.width,
bboxHeight: bboxResult.bbox.height,
});
broadcast({ type: 'job_update', job: job.toJSON() });
broadcast({ type: 'job_update', job: sanitizeJob(job) });
// ---- Crop the image around the detected subject ----
const isFullImage =
@@ -263,10 +279,6 @@ async function runJob(jobId) {
);
imageForAnalysis = croppedDataUrl;
// Optionally store the cropped image for UI preview
await job.update({ croppedImageDataUrl: croppedDataUrl });
broadcast({ type: 'job_update', job: job.toJSON() });
if (cropPixels) {
console.log(
`Cropped to ${cropPixels.width}×${cropPixels.height} ` +
@@ -291,12 +303,18 @@ async function runJob(jobId) {
maxTokens: 1024,
});
// Scrub image before marking done — don't persist photos
await clearImageData(job);
await setStatus(job, 'done', {
result: text,
inputTokens: usage?.promptTokens ?? null,
outputTokens: usage?.completionTokens ?? null,
});
} catch (err) {
// Scrub image even on failure
await clearImageData(job).catch(() => {});
const detail = err?.message
? `${err.name ?? 'Error'}: ${err.message}${err.cause ? `\nCause: ${JSON.stringify(err.cause, null, 2)}` : ''}`
: String(err);