export default { async fetch(request, env, ctx) { var url = new URL(request.url); var path = url.pathname; if (request.method === 'OPTIONS') { return new Response(null, { headers: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type' } }); } if (path === '/api/deploy' && request.method === 'POST') { try { var body = await request.json(); var email = body.email, apiKey = body.apiKey, projectName = body.projectName; var workerJs = body.workerJs, rawUrl = body.rawUrl, backends = body.backends, useCustomScript = body.useCustomScript; if (!email || !apiKey) throw new Error('Email & API Key required'); if (!projectName) throw new Error('projectName required'); var result = { success: true, steps: [], url: null, message: '' }; result.steps.push('Getting account...'); var accRes = await fetch('https://api.cloudflare.com/client/v4/accounts', { headers: { 'X-Auth-Email': email, 'X-Auth-Key': apiKey } }); var accData = await accRes.json(); if (!accData.success || !accData.result.length) throw new Error('Invalid credentials'); var accountId = accData.result[0].id; result.steps.push('Account: ' + accData.result[0].name); var script = ''; if (useCustomScript && workerJs) { script = workerJs; result.steps.push('Using CUSTOM script'); } else if (rawUrl) { try { script = await (await fetch(rawUrl)).text(); } catch(e) {} } if (!script) { script = "export default {\n" + " async fetch(request, env, ctx) {\n" + " let url = new URL(request.url);\n" + " let domainBackend = ['payload.goku25.workers.dev'];\n" + " if(env.HOST) domainBackend = await ADD(env.HOST);\n" + " let pathUji = env.PATH || '/';\n" + " if (pathUji.charAt(0) !== '/') pathUji = '/' + pathUji;\n" + " let kodeRespon = env.CODE || '200';\n" + " async function getValidResponse(request, hosts) {\n" + " let shuffledHosts = hosts.sort(() => Math.random() - 0.5);\n" + " for (const host of shuffledHosts) {\n" + " let testUrl = new URL(url.href); testUrl.hostname = host;\n" + " testUrl.pathname = pathUji.split('?')[0]; testUrl.search = pathUji.split('?')[1] || '';\n" + " try {\n" + " const response = await fetch(testUrl.href, { method: 'HEAD', redirect: 'manual' });\n" + " if (response.status.toString() === kodeRespon || response.status === 302) {\n" + " let finalUrl = new URL(url.href); finalUrl.hostname = host;\n" + " return await fetch(new Request(finalUrl.href, { method: request.method, headers: new Headers(request.headers), body: request.body, redirect: 'follow' }));\n" + " }\n" + " } catch (error) {}\n" + " }\n" + " return new Response('Down', { status: 503 });\n" + " }\n" + " return await getValidResponse(request, domainBackend);\n" + " }\n" + "};\n" + "async function ADD(envadd) {\n" + " var addtext = envadd.replace(/[\\t |\"'\\`\\r\\n]+/g, ',').replace(/,+/g, ',');\n" + " if (addtext.charAt(0) == ',') addtext = addtext.slice(1);\n" + " if (addtext.charAt(addtext.length - 1) == ',') addtext = addtext.slice(0, -1);\n" + " return addtext.split(',');\n" + "}"; if (backends && backends.length > 0) { var arr = backends.map(function(b) { return "'" + b.trim() + "'"; }).join(', '); script = script.replace(/let domainBackend = \['payload.goku25.workers.dev'\];/, 'let domainBackend = [' + arr + '];'); } } result.steps.push('Checking project...'); var checkRes = await fetch('https://api.cloudflare.com/client/v4/accounts/' + accountId + '/pages/projects/' + projectName, { headers: { 'X-Auth-Email': email, 'X-Auth-Key': apiKey } }); if (!(await checkRes.json()).success) { await fetch('https://api.cloudflare.com/client/v4/accounts/' + accountId + '/pages/projects', { method: 'POST', headers: { 'X-Auth-Email': email, 'X-Auth-Key': apiKey, 'Content-Type': 'application/json' }, body: JSON.stringify({ name: projectName, production_branch: 'main' }) }); } result.steps.push('Deploying...'); var boundary = '----Boundary' + Date.now().toString(36); var body2 = '--' + boundary + '\r\nContent-Disposition: form-data; name="manifest"\r\n\r\n{"name":"' + projectName + '"}\r\n'; body2 += '--' + boundary + '\r\nContent-Disposition: form-data; name="_worker.js"; filename="_worker.js"\r\nContent-Type: application/javascript\r\n\r\n' + script + '\r\n'; body2 += '--' + boundary + '--\r\n'; var deployRes = await fetch('https://api.cloudflare.com/client/v4/accounts/' + accountId + '/pages/projects/' + projectName + '/deployments', { method: 'POST', headers: { 'X-Auth-Email': email, 'X-Auth-Key': apiKey, 'Content-Type': 'multipart/form-data; boundary=' + boundary }, body: body2 }); var deployData = await deployRes.json(); if (deployData.success) { result.url = 'https://' + projectName + '.pages.dev'; result.message = 'Deployed!'; } else { result.success = false; result.message = JSON.stringify(deployData.errors); } return new Response(JSON.stringify(result), { status: 200, headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' } }); } catch (err) { return new Response(JSON.stringify({ success: false, message: err.message }), { status: 500, headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' } }); } } if (path === '/api/list-pages' && request.method === 'POST') { try { var body = await request.json(); var email = body.email, apiKey = body.apiKey; var accRes = await fetch('https://api.cloudflare.com/client/v4/accounts', { headers: { 'X-Auth-Email': email, 'X-Auth-Key': apiKey } }); var accData = await accRes.json(); var accountId = accData.result[0].id; var pagesRes = await fetch('https://api.cloudflare.com/client/v4/accounts/' + accountId + '/pages/projects', { headers: { 'X-Auth-Email': email, 'X-Auth-Key': apiKey } }); var pagesData = await pagesRes.json(); return new Response(JSON.stringify({ success: true, projects: pagesData.result || [] }), { status: 200, headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' } }); } catch (err) { return new Response(JSON.stringify({ success: false, message: err.message }), { status: 500 }); } } if (path === '/api/delete-pages' && request.method === 'POST') { try { var body = await request.json(); var email = body.email, apiKey = body.apiKey, projectName = body.projectName; var accRes = await fetch('https://api.cloudflare.com/client/v4/accounts', { headers: { 'X-Auth-Email': email, 'X-Auth-Key': apiKey } }); var accData = await accRes.json(); var accountId = accData.result[0].id; var delRes = await fetch('https://api.cloudflare.com/client/v4/accounts/' + accountId + '/pages/projects/' + projectName, { method: 'DELETE', headers: { 'X-Auth-Email': email, 'X-Auth-Key': apiKey } }); var delData = await delRes.json(); return new Response(JSON.stringify({ success: delData.success, message: delData.success ? 'Deleted' : JSON.stringify(delData.errors) }), { status: 200, headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' } }); } catch (err) { return new Response(JSON.stringify({ success: false, message: err.message }), { status: 500 }); } } return new Response(HTML, { headers: { 'Content-Type': 'text/html; charset=utf-8' } }); } }; var HTML = "\n\n\n\nCF PAGES DEPLOYER v3.5\n\n\n\n
\n

KOPI KAPAL CF PAGES DEPLOYER v3.5

\n
Hide Akun | Blur | Pages Manager | Delete Pages | Custom Script | LOG FIXED
\n
\n
\n

AKUN

\n
\n\n
0
\n
\n
\n
\n

TARGET

\n

PROJECT

\n\n

PAGES MANAGER

\n
Klik LOAD...
\n
0
\n
\n
\n

MODE

CUSTOM MANUAL

\n

BACKEND

0
\n

SCRIPT EDITOR

\n

LOG

\n
[--:--:--] System Ready v3.5
\n
\n
\n
\n

IMPORT BACKUP

\n
\n\n\n";