Spaces:
Configuration error
Configuration error
Download worker/src/security.ts from UUUZCX/video-optimizer-bot: direct link, hf CLI and curl.
- Browser
- Download file 796 Bytes
-
https://huggingface.co/spaces/UUUZCX/video-optimizer-bot/resolve/main/worker/src/security.ts
- Command line
-
hf download hf://spaces/UUUZCX/video-optimizer-bot/worker/src/security.ts
-
curl -L -o security.ts https://huggingface.co/spaces/UUUZCX/video-optimizer-bot/resolve/main/worker/src/security.ts
796 Bytes
| export interface Env { | |
| WORKER_FORWARD_URL: string; | |
| WORKER_SHARED_SECRET: string; | |
| TELEGRAM_WEBHOOK_SECRET: string; | |
| } | |
| export async function timingSafeEqualText(left: string, right: string): Promise<boolean> { | |
| const encoder = new TextEncoder(); | |
| const a = encoder.encode(left || ""); | |
| const b = encoder.encode(right || ""); | |
| if (a.length !== b.length) return false; | |
| let diff = 0; | |
| for (let index = 0; index < a.length; index += 1) { | |
| diff |= a[index] ^ b[index]; | |
| } | |
| return diff === 0; | |
| } | |
| export async function validateTelegramSecret(request: Request, env: Env): Promise<boolean> { | |
| if (!env.TELEGRAM_WEBHOOK_SECRET) return true; | |
| const header = request.headers.get("x-telegram-bot-api-secret-token") || ""; | |
| return timingSafeEqualText(header, env.TELEGRAM_WEBHOOK_SECRET); | |
| } | |