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`; for (const p of items) { const name = p.name || ""; const url = p.url || ""; const price = String(p.price || "").replace(/[^\d]/g, ""); const image = p.image || ""; const sku = p.sku || ""; const desc = p.description || ""; if (!name || !url || !price) continue; xml += ` ${url} ${price} ${image} ${p.available ? "instock" : "outofstock"} ${sku} `; } xml += `\n`; const response = new Response(xml, { headers: { "Content-Type": "application/xml; charset=UTF-8", "Cache-Control": "public, max-age=600" } }); ctx.waitUntil(cache.put(cacheKey, response.clone())); return response; } };
جستجو در محصولات
کالایی در این صفحه موجود نیست
    پروفایلسبد خریددسته‌بندیخانه