export default {
async fetch(request, env, ctx) {
const cache = caches.default;
const cacheKey = new Request("https://lavasemkhangi.ir/torob-feed.xml");
const cached = await cache.match(cacheKey);
if (cached) return cached;
const API_URL = "https://lavasemkhangi.ir/api/products"; // باید با endpoint واقعی جایگزین شود
const TOKEN = env.TOROB_API_TOKEN; // در secrets تنظیم شود
const res = await fetch(API_URL, {
headers: {
"Authorization": `Bearer ${TOKEN}`,
"Accept": "application/json"
}
});
if (!res.ok) {
return new Response(`API error: ${res.status}`, { status: 500 });
}
const data = await res.json();
const items = data محصولات || data.items || [];
let xml = `\n
🎁 کد تخفیف ویژه اولین خرید: naniwa | ارسال سریع به سراسر کشور 🚀.