windows-iso-downloader/.claude/worktrees/modest-hamilton-53380c/cloudflare-worker/worker.js
Shekhar Vaidya 1c54c36d03 feat: expiry countdown, refresh links, CLI tabs, recently viewed, file size support
- Backend: ?force=true on /proxy bypasses cache for fresh link fetch
- Frontend: parse `se` param for live expiry countdown on download links
- Frontend: show Refresh button when link expires in <6h, force-fetches fresh URL
- Frontend: CliCommand component replaces Aria2Tip — wget/curl/aria2 tabs, persists selection in localStorage
- Frontend: RecentlyViewed component — localStorage, shows active countdown or expired state
- Frontend: FileSize shown alongside arch if returned by Microsoft CDN

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-22 21:06:17 +05:30

44 lines
1.3 KiB
JavaScript

const ALLOWED_HOSTS = [
"www.microsoft.com",
"vlscppe.microsoft.com",
"ov-df.microsoft.com",
];
export default {
async fetch(request) {
const url = new URL(request.url);
// Target host comes from the ?host= param; path+search are forwarded as-is
const targetHost = url.searchParams.get("host");
if (!targetHost || !ALLOWED_HOSTS.includes(targetHost)) {
return new Response(JSON.stringify({ error: "Invalid or missing host parameter" }), {
status: 400,
headers: { "Content-Type": "application/json" },
});
}
url.searchParams.delete("host");
url.hostname = targetHost;
url.protocol = "https:";
url.port = "";
const upstreamRequest = new Request(url.toString(), {
method: request.method,
headers: {
"User-Agent": request.headers.get("User-Agent") || "Mozilla/5.0",
"Referer": request.headers.get("Referer") || "",
"Accept": request.headers.get("Accept") || "application/json",
},
});
const upstream = await fetch(upstreamRequest);
return new Response(upstream.body, {
status: upstream.status,
headers: {
"Content-Type": upstream.headers.get("Content-Type") || "application/json",
"Access-Control-Allow-Origin": "*",
},
});
},
};