export default { async fetch(request, env) { const url = new URL(request.url); const key = url.pathname.slice(1); // Lấy tên file từ URL // --- PHẦN BẢO MẬT: Chống Hotlinking --- const referer = request.headers.get("Referer"); if (referer && !referer.includes("zenapi.club")) { return new Response("Access Denied", { status: 403 }); } // Lấy file từ R2 const object = await env.MY_BUCKET.get(key); // --- PHẦN XỬ LÝ 404: Giao diện tùy chỉnh --- if (object === null) { return new Response(`
Hệ thống ZenAPI không tìm thấy nội dung bạn yêu cầu.
Quay lại trang chủ body> `, { status: 404, headers: { "Content-Type": "text/html" } }); } // Trả về file bình thường nếu tìm thấy const headers = new Headers(); object.writeHttpMetadata(headers); headers.set("etag", object.httpEtag); return new Response(object.body, { headers, }); }, };