deckhearth/lib/scan-capture-upload.js
varutasu 071a3dca21
refactor(scanner): extract disambiguation dialog and upload helpers. (#67)
Brief 1 of god-component-split: move ScanDisambiguationDialog and
scan-capture-upload lib out of CameraScanner (~90 lines) without
behavior changes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-02 11:01:32 -05:00

29 lines
874 B
JavaScript

/** Cooldown timestamp for rate-limit backoff (ms from now). */
export function rateLimitCooldownUntil(ms) {
return Date.now() + ms;
}
/** Upload a base64 scan capture to Blob storage; returns public URL or null on 429. */
export async function uploadScanCapture(imageData) {
const response = await fetch('/api/scan/upload-image', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${localStorage.getItem('auth_token')}`,
},
body: JSON.stringify({ imageData }),
});
if (response.status === 429) {
console.warn('Scan image upload rate-limited');
return null;
}
if (!response.ok) {
const errBody = await response.json().catch(() => ({}));
throw new Error(errBody.error || 'Failed to upload scan image');
}
const result = await response.json();
return result.url || null;
}