export async function onRequest(context) { // URL থেকে ফাইলের ID নেওয়া const fileId = context.params.id; const requestUrl = new URL(context.request.url); // 🔥 তোমার বর্তমান Worker এর URL এখানে দাও const WORKER_API_URL = "https://seed.toxhost.workers.dev"; // 🔥 pdlink resolver worker (server-name based /api/{servername}/{id}) const PD_WORKER_URL = "https://pd.toxhost.workers.dev"; // ========================================== // 🛠️ Small helpers // ========================================== function isValid(val) { return val && val !== "Failed" && val !== "Disabled" && val !== "null" && val !== "Processing" && (typeof val !== "string" || val.trim() !== "") && (typeof val !== "string" || !val.startsWith("Failed")); } function escapeHtml(str) { if (str === null || str === undefined) return ""; return String(str) .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } // 📏 Bytes -> KB/MB/GB/TB auto formatter function formatBytes(bytes, decimals = 2) { bytes = parseInt(bytes); if (!bytes || isNaN(bytes) || bytes <= 0) return "Unknown"; const k = 1024; const dm = decimals < 0 ? 0 : decimals; const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`; } if (!fileId || fileId.trim() === "") { return new Response("

404 - File Not Found

Missing file ID.

", { status: 404, headers: { "Content-Type": "text/html" } }); } try { // ========================================== // ১. সার্ভার সাইড থেকে Worker-এ POST রিকোয়েস্ট করা // ========================================== const apiResponse = await fetch(`${WORKER_API_URL}/?id=${encodeURIComponent(fileId)}&action=download`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: fileId, action: 'download' }) }); let resJson; try { resJson = await apiResponse.json(); } catch (e) { return new Response("

502 - Error Fetching Data

", { status: 502, headers: { "Content-Type": "text/html" } }); } // ========================================== // ২. ডাটা না পেলে বা success false হলে 404 // ========================================== if (!resJson || !resJson.success || !resJson.data) { return new Response( "

404 - File Not Found

The file you are looking for does not exist or has been removed.

", { status: 404, headers: { "Content-Type": "text/html" } } ); } const fileData = resJson.data; // 🔄 /d/ এর জায়গায় /file/ const shareLink = `${requestUrl.origin}/file/${encodeURIComponent(fileId)}`; // ========================================== // 🎛️ ON/OFF SWITCHES — এখান থেকে যেকোনো সার্ভার true/false করে // enable/disable করা যাবে। false করলে বাটন একদম দেখাবে না। // ========================================== const SERVER_TOGGLES = { hubcloud: true, fsl: true, server10gbps: true, gofile: true, pixeldrain: true, vikingfile: true, buzzheavier: true, telegram: true, voe: true, streamhg: true, abyss: true }; // ========================================== // ৩. GCloud/HubCloud বাটন ও লিংক // ========================================== let gcloudUrl = null; if (isValid(fileData.gcloud_url) && /^https?:\/\//i.test(String(fileData.gcloud_url).trim())) { gcloudUrl = fileData.gcloud_url; } let gcloudHTML = ""; if (gcloudUrl && SERVER_TOGGLES.hubcloud) { gcloudHTML = ` Download [HubCloud]\n`; } let topCopyLink = gcloudUrl ? gcloudUrl : shareLink; // ========================================== // 🔴 FSL & 10Gbps Servers // ========================================== let fsl10GbpsHTML = ""; if (SERVER_TOGGLES.fsl) { fsl10GbpsHTML += ` Download [FSL Server]\n`; } if (SERVER_TOGGLES.server10gbps) { fsl10GbpsHTML += ` Download [Server : 10Gbps]\n`; fsl10GbpsHTML += `
Resume Not Supported in 10Gbps So Use only if you have stable internet (:
\n`; } // ========================================== // ৪. pdlink সার্ভারগুলো // ========================================== const PDLINK_SERVERS = [ { key: 'gofile', name: 'Gofile' }, { key: 'pixeldrain', name: 'PixelServer : 2' }, { key: 'vikingfile', name: 'Vikingfile' }, { key: 'buzzheavier', name: 'Buzz Server' } ]; let pdlinkHTML = ""; PDLINK_SERVERS.forEach(srv => { if (!SERVER_TOGGLES[srv.key]) return; // 🎛️ toggle off -> skip entirely const val = fileData[srv.key] || fileData[`${srv.key}_id`]; if (isValid(val)) { let colorClass = "bg-blue"; // Default if (srv.key === 'pixeldrain') colorClass = "bg-purple"; if (srv.key === 'buzzheavier') colorClass = "bg-darkgrey"; pdlinkHTML += ` Download [${srv.name}]\n`; } }); // ========================================== // ৫. বাকি সব সার্ভার // ========================================== function makeUrl(key, defaultDomain, path) { let domain = defaultDomain; if (fileData.custom_domains && fileData.custom_domains[key] && typeof fileData.custom_domains[key] === 'string' && fileData.custom_domains[key].trim() !== "") { let custom = fileData.custom_domains[key].trim(); custom = custom.replace(/^https?:\/\//, '').replace(/\/$/, ''); domain = `https://${custom}`; } return domain + path; } const DIRECT_SERVERS = []; const telegramId = fileData.telegram_id; if (SERVER_TOGGLES.telegram && isValid(telegramId)) DIRECT_SERVERS.push({ name: "From Telegram", url: makeUrl("telegram", "https://t.me", `/${telegramId}`) }); const voe = fileData.voe; if (SERVER_TOGGLES.voe && isValid(voe)) DIRECT_SERVERS.push({ name: "Voe", url: makeUrl("voe", "https://voe.sx", `/${voe}`) }); const streamhgId = fileData.streamhg_id; if (SERVER_TOGGLES.streamhg && isValid(streamhgId)) DIRECT_SERVERS.push({ name: "StreamHG", url: makeUrl("streamhg", "https://audinifer.com", `/f/${streamhgId}`) }); const abyssId = fileData.abyss_id || fileData.abyss; if (SERVER_TOGGLES.abyss && isValid(abyssId)) DIRECT_SERVERS.push({ name: "Abyss", url: makeUrl("abyss", "https://download.openx.xyz", `/?v=${abyssId}`) }); let directServersHTML = ""; DIRECT_SERVERS.forEach(srv => { let colorClass = "bg-blue"; let iconClass = "fas fa-file-download"; const n = srv.name.toLowerCase(); if (n.includes("ruby") || n.includes("voe")) colorClass = "bg-red"; else if (n.includes("filepress") || n.includes("abyss")) colorClass = "bg-purple"; else if (n.includes("telegram")) { colorClass = "bg-tg"; iconClass = "fab fa-telegram-plane"; } else if (n.includes("mixdrop") || n.includes("streamtape") || n.includes("dropload")) colorClass = "bg-grey"; directServersHTML += ` Download ${escapeHtml(srv.name)}\n`; }); // 🟢 Final Output for Download Servers let generatedHeaderHTML = `

Download Link Generated

If All Servers 📶 are not working ❌ Then Please
Change Your Browser DNS To Cloudflare 🚀 or Use VPN
How ? Click Here 👉 to Watch Tutorial 👀
`; // 🔄 Mobile-friendly note card: percentage-based width + box-sizing fix let bottomNoteHTML = `
Note : Please Use Download Manager like IDM Or IDA - To accelerate Your Download Speeds
`; let allServersHTML = generatedHeaderHTML + fsl10GbpsHTML + gcloudHTML + pdlinkHTML + directServersHTML + bottomNoteHTML; // ========================================== // ৬. Meta তথ্য // ========================================== let sizeDisplay = formatBytes(fileData.size); let dateDisplay = fileData.created_at ? String(fileData.created_at) : new Date().toLocaleString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit' }); let formatDisplay = fileData.format ? fileData.format : "video/x-matroska"; const safeTitle = escapeHtml(fileData.title || 'Unknown File'); // 🔵 Shared By badge — under Share Date, blue link const sharedByHTML = `
  • Shared By Animedrive.in
  • `; // ========================================== // ৭. HTML টেমপ্লেট জেনারেট (SSR) // ========================================== const html = ` ${safeTitle}

    TOXcloud | Create An Account |Login

    ${safeTitle}
    • File Size${escapeHtml(sizeDisplay)}
    • File Type${escapeHtml(formatDisplay)}
    • Share Date${escapeHtml(dateDisplay)}
    • ${sharedByHTML}

    Please Wait While Links are Generating...

    Generate Direct Download Link








    `; // ========================================== // ৮. Response পাঠানো // ========================================== return new Response(html, { status: 200, headers: { "Content-Type": "text/html;charset=UTF-8", "Cache-Control": "public, max-age=60" } }); } catch (error) { return new Response(`

    Internal Error

    ${escapeHtml(error.message)}

    `, { status: 500, headers: { "Content-Type": "text/html" } }); } }