Add link previews for web+ap and web+feed

This commit is contained in:
SoniEx2 2024-01-18 19:53:32 -03:00
parent a8be84028c
commit 168dd2982e

View file

@ -506,7 +506,31 @@ function fetch(uri: string, headers: Record<string, string>) {
function normalizeURL(link: string, baseLink?: string, disallowHttp = false) {
try {
const url = new URL(link, baseLink);
let url = new URL(link, baseLink);
// Use the FediLinks protocol to fetch some web+ links
if (/^web\+(ap|feed):$/.test(url.protocol)) {
// ew, why is this not RFC 3986
// no worries, we can copy over from https://github.com/fedi-to/fc-dll/blob/default/src/lib.rs#L109
const targetParam = url.toString();
const asIfHttps = targetParam.replace(/^web\+[a-z]+/, "https");
if (
!asIfHttps.startsWith("https://") ||
asIfHttps.startsWith("https:///") ||
asIfHttps.startsWith("https://\\")
) {
return undefined;
}
url = new URL(asIfHttps);
url.pathname = "/.well-known/protocol-handler";
url.username = "";
url.password = "";
url.hash = "";
url.search = "";
url.searchParams.append("target", targetParam);
}
// Only fetch http and https links
if (url.protocol !== "http:" && url.protocol !== "https:") {