Move fetcher + providers inside request and localise eventId to write method

This commit is contained in:
William Oldham
2023-12-17 22:05:42 +00:00
parent a7b6d61ad3
commit dd37fecf57

View File

@@ -11,15 +11,8 @@ import { mediaSchema } from '@/schema';
import { validateTurnstile } from '@/turnstile'; import { validateTurnstile } from '@/turnstile';
const app = new Hono(); const app = new Hono();
let eventId = 0; let eventId = 0;
const fetcher = makeStandardFetcher(fetch);
const providers = makeProviders({
fetcher,
target: targets.NATIVE,
});
async function writeSSEEvent( async function writeSSEEvent(
stream: Parameters<Parameters<typeof streamSSE>['1']>['0'], stream: Parameters<Parameters<typeof streamSSE>['1']>['0'],
event: string, event: string,
@@ -62,6 +55,13 @@ app.get('/scrape', async (context) => {
return context.text('An error has occurred!'); return context.text('An error has occurred!');
} }
const fetcher = makeStandardFetcher(fetch);
const providers = makeProviders({
fetcher,
target: targets.NATIVE,
});
return streamSSE(context, async (stream) => { return streamSSE(context, async (stream) => {
const output = await providers.runAll({ const output = await providers.runAll({
media, media,