export default { async fetch(request) { const url = new URL(request.url); const shortUrl = url.searchParams.get("url"); if (!shortUrl) { return new Response("缺少 url 参数", { status: 400 }); } try { const resp = await fetch(shortUrl, { redirect: "manual" }); const location = resp.headers.get("Location") || ""; let realUrl = null; if (location.includes("viglink.com")) { // 直接从原始 location 字符串里截取 u= 的值,不用 URL 解析(避免自动 decode) const match = location.match(/[?&]u=([^&]+)/); if (match) { realUrl = match[1]; // 保持原始编码,不 decode } } else if (location.includes("account.microsoft.com")) { realUrl = location; } if (!realUrl) { return new Response("无法解析链接:" + location, { status: 500 }); } const alookUrl = "alook://" + realUrl.replace("https://", "").replace("https%3A%2F%2F", ""); return new Response( `
`, { headers: { "Content-Type": "text/html;charset=utf-8" } } ); } catch (e) { return new Response("错误:" + e.message, { status: 500 }); } } };