Update alook-redirect

This commit is contained in:
XXhaos
2026-04-11 00:32:29 +08:00
committed by GitHub
parent 25a4bf853f
commit 41bbf70abd

View File

@@ -6,33 +6,10 @@ export default {
return new Response("缺少 url 参数", { status: 400 }); return new Response("缺少 url 参数", { status: 400 });
} }
try { const alookUrl = "alook://" + shortUrl.replace("https://", "");
const resp = await fetch(shortUrl, { redirect: "manual" }); return new Response(
const location = resp.headers.get("Location") || ""; `<html><body><script>window.location.href=${JSON.stringify(alookUrl)};</script></body></html>`,
{ headers: { "Content-Type": "text/html;charset=utf-8" } }
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(
`<html><body><script>window.location.href=${JSON.stringify(alookUrl)};</script></body></html>`,
{ headers: { "Content-Type": "text/html;charset=utf-8" } }
);
} catch (e) {
return new Response("错误:" + e.message, { status: 500 });
}
} }
}; };