File size: 549 Bytes
011f1af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { captionImage } from './captioner.js';

let busy = false;
self.onmessage = async ({ data }) => {
  if (busy || data.type !== 'caption') return;
  busy = true;
  const { id, image, options } = data;
  try {
    const result = await captionImage(image, options, progress => self.postMessage({ type: 'progress', id, progress }));
    self.postMessage({ type: 'result', id, result });
  } catch (error) {
    self.postMessage({ type: 'error', id, message: String(error?.message ?? error).slice(0, 500) });
  } finally {
    busy = false;
  }
};