This commit is contained in:
Ritobroto Kalita 2025-03-26 09:42:21 +00:00 committed by GitHub
commit f8e970dec7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -52,6 +52,12 @@ const RE_REDDIT =
const RE_REDDIT_EMBED =
/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i;
const RE_TUTAR_WITH_USER_ID =
/^https:\/\/web\.tutar\.app\?api-key=([a-zA-Z0-9_-]+)&user-id=([a-zA-Z0-9_-]+)$/;
const RE_TUTAR_WITHOUT_USER_ID =
/^https:\/\/web\.tutar\.app\?api-key=([a-zA-Z0-9_-]+)$/;
const ALLOWED_DOMAINS = new Set([
"youtube.com",
"youtu.be",
@ -67,6 +73,7 @@ const ALLOWED_DOMAINS = new Set([
"val.town",
"giphy.com",
"reddit.com",
"web.tutar.app",
]);
const ALLOW_SAME_ORIGIN = new Set([
@ -80,6 +87,7 @@ const ALLOW_SAME_ORIGIN = new Set([
"*.simplepdf.eu",
"stackblitz.com",
"reddit.com",
"web.tutar.app",
]);
export const createSrcDoc = (body: string) => {
@ -268,6 +276,52 @@ export const getEmbedLink = (
return ret;
}
const tutarLinkWithUserId = link.match(RE_TUTAR_WITH_USER_ID);
if(tutarLinkWithUserId) {
const [, apiKey, userId] = link.match(RE_TUTAR_WITH_USER_ID)!;
const safeURL = sanitizeHTMLAttribute(
`https://web.tutar.app?api-key=${apiKey}&user-id=${userId}`,
);
const ret: IframeDataWithSandbox = {
type: "document",
srcdoc: () =>
createSrcDoc(`
<iframe
src="${safeURL}"
id="3d-viewer"
allow="camera"
allowFullScreen ></iframe>
`),
intrinsicSize: { w: 550, h: 550 },
sandbox: { allowSameOrigin },
};
embeddedLinkCache.set(link, ret);
return ret;
}
const tutarLinkWithoutUserId = link.match(RE_TUTAR_WITHOUT_USER_ID);
if(tutarLinkWithoutUserId) {
const [, apiKey] = link.match(RE_TUTAR_WITHOUT_USER_ID)!;
const safeURL = sanitizeHTMLAttribute(
`https://web.tutar.app?api-key=${apiKey}`,
);
const ret: IframeDataWithSandbox = {
type: "document",
srcdoc: () =>
createSrcDoc(`
<iframe
src="${safeURL}"
id="3d-viewer"
allow="camera"
allowFullScreen ></iframe>
`),
intrinsicSize: { w: 550, h: 550 },
sandbox: { allowSameOrigin },
};
embeddedLinkCache.set(link, ret);
return ret;
}
embeddedLinkCache.set(link, {
link,
intrinsicSize: aspectRatio,