// User-Agent pool to mimic browser requests const userAgents = [ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Safari/605.1.15', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0' ]; // IMPORTANT: Configure your proxy subdomains here. // These should be other Cloudflare Workers running the proxy logic. const subDomains = [ 'https://pdb01.yourdomain.com', // Replace with your own proxy worker URL 'https://pdb02.yourdomain.com' // Replace with your own proxy worker URL ]; // --- Main Fetch Handler --- export default { async fetch(request, env, ctx) { const url = new URL(request.url); const path = url.pathname; // Route requests if (path.startsWith('/api/generate/')) { // API: Generate download links const fileId = path.replace('/api/generate/', ''); return handleGenerateAPI(fileId); } else { // Serve the basic HTML page for all other requests return new Response(getHtml(), { headers: { 'Content-Type': 'text/html; charset=utf-8' } }); } }, }; // --- API Logic --- async function handleGenerateAPI(fileId) { if (!fileId || !/^[a-zA-Z0-9]+$/.test(fileId)) { return new Response(JSON.stringify({ success: false, error: 'Invalid Pixeldrain URL format.' }), { headers: { 'Content-Type': 'application/json' }, status: 400 }); } try { const fileInfo = await getPixeldrainFileInfo(fileId); if (!fileInfo.success) { return new Response(JSON.stringify(fileInfo), { headers: { 'Content-Type': 'application/json' }, status: 404 }); } // Generate multiple proxied download links const downloadUrls = subDomains.map(domain => `${domain}/download/${fileId}`); // Note: Assumes proxy workers handle the /download/ path return new Response(JSON.stringify({ success: true, fileName: fileInfo.fileName, downloadUrls: downloadUrls }), { headers: { 'Content-Type': 'application/json' } }); } catch (error) { return new Response(JSON.stringify({ success: false, error: 'Server error. Please try again later.' }), { headers: { 'Content-Type': 'application/json' }, status: 500 }); } } // --- Helper Functions --- async function getPixeldrainFileInfo(fileId) { const randomUserAgent = userAgents[Math.floor(Math.random() * userAgents.length)]; const infoUrl = `https://pixeldrain.com/api/file/${fileId}/info`; try { const response = await fetch(infoUrl, { headers: { 'User-Agent': randomUserAgent, 'Accept': 'application/json' } }); if (!response.ok) { return { success: false, error: 'Invalid URL or file not found/expired.' }; } const data = await response.json(); if (!data.success) { return { success: false, error: data.message || 'Could not retrieve file info.' }; } return { success: true, fileName: data.name || `file_${fileId}` }; } catch (error) { return { success: false, error: 'Failed to connect to Pixeldrain API.' }; } } // --- Minimalist Frontend HTML --- function getHtml() { return `
Paste a Pixeldrain URL to generate a direct download link.