mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
33 lines
824 B
TypeScript
33 lines
824 B
TypeScript
/// <reference lib="webworker" />
|
|
|
|
import { safeFetch } from '@soapbox/safe-fetch';
|
|
import { logi } from '@soapbox/logi';
|
|
import * as Comlink from 'comlink';
|
|
|
|
import '@/workers/handlers/abortsignal.ts';
|
|
import '@/sentry.ts';
|
|
|
|
export const FetchWorker = {
|
|
async fetch(
|
|
url: string,
|
|
init: Omit<RequestInit, 'signal'>,
|
|
signal: AbortSignal | null | undefined,
|
|
): Promise<[BodyInit, ResponseInit]> {
|
|
logi({ level: 'debug', ns: 'ditto.fetch', method: init.method ?? 'GET', url });
|
|
|
|
const response = await safeFetch(url, { ...init, signal });
|
|
|
|
return [
|
|
await response.arrayBuffer(),
|
|
{
|
|
status: response.status,
|
|
statusText: response.statusText,
|
|
headers: [...response.headers.entries()],
|
|
},
|
|
];
|
|
},
|
|
};
|
|
|
|
Comlink.expose(FetchWorker);
|
|
|
|
self.postMessage('ready');
|