mirror of
https://github.com/thelounge/thelounge
synced 2024-11-22 03:53:08 +00:00
Add link previews for web+ap and web+feed
This commit is contained in:
parent
a8be84028c
commit
168dd2982e
1 changed files with 25 additions and 1 deletions
|
@ -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:") {
|
||||
|
|
Loading…
Reference in a new issue