Update lock files and cleanup
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user