From 8f8c472474238ad0f20137c6d4063cb1f8f94b3e Mon Sep 17 00:00:00 2001 From: William Oldham Date: Sun, 17 Dec 2023 20:15:39 +0000 Subject: [PATCH] Rename id to eventId and reformat --- src/index.ts | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/index.ts b/src/index.ts index 97e86a0..64b6092 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,7 +9,7 @@ import { import { ZodError, z } from 'zod'; const app = new Hono(); -let id = 0; +let eventId = 0; const fetcher = makeStandardFetcher(fetch); @@ -26,11 +26,11 @@ async function outputEvent( return await stream.writeSSE({ event, data: JSON.stringify(data), - id: String(id++), + id: String(eventId++), }); } -const tmdbIdSchema = z.string().regex(/^\d+$/) +const tmdbIdSchema = z.string().regex(/^\d+$/); const mediaSchema = z .discriminatedUnion('type', [ @@ -71,39 +71,39 @@ const mediaSchema = z }); async function validateTurnstile(context: Context) { - const turnstileSecret = context.env?.TURNSTILE_SECRET as string | undefined + const turnstileSecret = context.env?.TURNSTILE_SECRET as string | undefined; - const token = context.req.header("cf-turnstile-token") || "" + const token = context.req.header('cf-turnstile-token') || ''; // TODO: Make this cross platform - const ip = context.req.header('CF-Connecting-IP') || ""; + const ip = context.req.header('CF-Connecting-IP') || ''; const formData = new FormData(); - formData.append('secret', turnstileSecret || ""); - formData.append('response', token); - formData.append('remoteip', ip); + formData.append('secret', turnstileSecret || ''); + formData.append('response', token); + formData.append('remoteip', ip); const url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify'; - const result = await fetch(url, { - body: formData, - method: 'POST', - }); + const result = await fetch(url, { + body: formData, + method: 'POST', + }); - const outcome = await result.json(); - return outcome.success -} + const outcome = await result.json(); + return outcome.success; +} app.get('/scrape', async (context) => { const queryParams = context.req.query(); - const turnstileEnabled = Boolean(context.env?.TURNSTILE_ENABLED) + const turnstileEnabled = Boolean(context.env?.TURNSTILE_ENABLED); if (turnstileEnabled) { - const success = await validateTurnstile(context) + const success = await validateTurnstile(context); if (!success) { - context.status(401) - return context.text("Turnstile invalid") + context.status(401); + return context.text('Turnstile invalid'); } } @@ -142,7 +142,7 @@ app.get('/scrape', async (context) => { return await outputEvent(stream, 'completed', output); } - stream.writeSSE({ event: 'noOutput', data: '', id: String(id++) }); + stream.writeSSE({ event: 'noOutput', data: '', id: String(eventId++) }); }); });