FastComments.com
Here you can edit and run the code snippet from our documentation.
Example Code Snippet "डिलीवरी सत्यापित करना"
import { createHmac, timingSafeEqual } from "node:crypto"; async function receive(c) { // जो सटीक बाइट्स आए हैं। c.req.json() का उपयोग करके दोबारा सीरियलाइज़ न करें। const rawBody = await c.req.raw.text(); const timestamp = c.req.raw.headers.get("X-FastComments-Timestamp"); const signature = c.req.raw.headers.get("X-FastComments-Signature"); if (!timestamp || !signature) return new Response("Missing headers", { status: 400 }); // पुरानी डिलीवरी अस्वीकार करें ताकि कैप्चर किया गया रिक्वेस्ट बाद में रिप्ले न हो सके। if (Math.abs(Math.floor(Date.now() / 1000) - Number(timestamp)) > 300) { return new Response("Timestamp outside window", { status: 400 }); } const expected = "sha256=" + createHmac("sha256", Deno.env.get("FASTCOMMENTS_API_SECRET")) .update(`${timestamp}.${rawBody}`) .digest("hex"); const a = new TextEncoder().encode(signature); const b = new TextEncoder().encode(expected); if (a.length !== b.length || !timingSafeEqual(a, b)) { return new Response("Signature mismatch", { status: 401 }); } // ...JSON.parse(rawBody) को हैंडल करें return Response.json({ received: true }); } app.put("/", receive); app.delete("/", receive);
Result