// ========================================== // Cloudflare Worker: Daily Report System // ========================================== const ADMIN_PASSWORD = "123456"; // رمز عبور خود را اینجا تغییر دهید export default { async fetch(request, env, ctx) { const url = new URL(request.url); const action = url.searchParams.get('action'); // 1. Authentication Check const cookie = request.headers.get("Cookie") || ""; const isAuthenticated = cookie.includes(`auth=${ADMIN_PASSWORD}`); // Handle Login Logic if (url.pathname === "/login" && request.method === "POST") { const formData = await request.formData(); const password = formData.get("password"); if (password === ADMIN_PASSWORD) { return new Response("Redirecting...", { status: 302, headers: { "Set-Cookie": `auth=${ADMIN_PASSWORD}; Path=/; HttpOnly; Max-Age=2592000`, "Location": "/" }, }); } return new Response("رمز عبور اشتباه است", { status: 403 }); } if (!isAuthenticated) { return new Response(loginPageHtml(), { headers: { "Content-Type": "text/html" } }); } // 2. API Routes (Replacing PHP Logic) if (request.method === "POST" && action) { if (action === 'save_report') { const data = await request.json(); let reports = JSON.parse(await env.REPORTS_KV.get("reports") || "[]"); const existingIndex = reports.findIndex(r => r.id === data.id); if (existingIndex !== -1) { reports[existingIndex] = data; } else { reports.unshift(data); } reports.sort((a, b) => new Date(b.date) - new Date(a.date)); await env.REPORTS_KV.put("reports", JSON.stringify(reports)); return new Response(JSON.stringify({ status: 'success' }), { headers: { 'Content-Type': 'application/json' } }); } if (action === 'delete_report') { const data = await request.json(); let reports = JSON.parse(await env.REPORTS_KV.get("reports") || "[]"); reports = reports.filter(r => r.id !== data.id); await env.REPORTS_KV.put("reports", JSON.stringify(reports)); return new Response(JSON.stringify({ status: 'success' }), { headers: { 'Content-Type': 'application/json' } }); } if (action === 'save_settings') { const data = await request.json(); await env.REPORTS_KV.put("settings", JSON.stringify(data)); return new Response(JSON.stringify({ status: 'success' }), { headers: { 'Content-Type': 'application/json' } }); } } // 3. Load Initial Data & Serve Frontend if (url.pathname === "/data") { const reports = await env.REPORTS_KV.get("reports") || "[]"; const settings = await env.REPORTS_KV.get("settings") || '{"dailyGoalHours": 8, "taskCategories": []}'; return new Response(JSON.stringify({ reports: JSON.parse(reports), settings: JSON.parse(settings) }), { headers: { "Content-Type": "application/json" } }); } return new Response(mainPageHtml(), { headers: { "Content-Type": "text/html" } }); } }; // --- HTML Templates --- function loginPageHtml() { return `
`; } function mainPageHtml() { // اینجا تمام کد HTML/CSS/JS شما که در فایل اصلی بود قرار میگیرد. // فقط بخش اسکریپت در انتها باید تغییر کند تا دادهها را به جای PHP از API داخلی Worker بگیرد. return `سیستم حرفهای ثبت و مدیریت گزارشهای کاری
دانلود فایل اکسل از گزارشها.
کپی آخرین گزارش با فرمت تلگرام.