Guess I'll have to maintain a list after all :)
This commit is contained in:
parent
3b674f5e28
commit
bf70ad32a1
1 changed files with 16 additions and 3 deletions
19
uiharu.ts
19
uiharu.ts
|
@ -139,6 +139,15 @@ const readableStreamToString = async (stream?: ReadableStream): string => {
|
|||
return result;
|
||||
};
|
||||
|
||||
const isDomainSuffix = (known: string, user: string) => {
|
||||
if(!known.startsWith('.'))
|
||||
known = '.' + known;
|
||||
if(!user.startsWith('.'))
|
||||
user = '.' + user;
|
||||
|
||||
return user.endsWith(known);
|
||||
};
|
||||
|
||||
const isAllowedOEmbedDomain = (domain: string): Boolean => {
|
||||
if(!domain.startsWith('.'))
|
||||
domain = '.' + domain;
|
||||
|
@ -373,9 +382,13 @@ const parseLinkHeader = (header: string) => {
|
|||
const extractOEmbedData = async (response: Response, html, url: string, urlInfo: URL) => {
|
||||
let oEmbedUrl: string = '';
|
||||
|
||||
// idk how long i'll bother with this for
|
||||
if(urlInfo.host === 'x.com' || urlInfo.host === 'twitter.com')
|
||||
// TODO: maintain a fucking list because its too difficult for services to just provide <link rel=alternate> tags
|
||||
if(isDomainSuffix('x.com', urlInfo.host) || isDomainSuffix('twitter.com', urlInfo.host))
|
||||
oEmbedUrl = `https://publish.twitter.com/oembed?dnt=true&omit_script=true&url=${encodeURIComponent(url)}`;
|
||||
else if(isDomainSuffix('soundcloud.com', urlInfo.host))
|
||||
oEmbedUrl = `https://soundcloud.com/oembed?format=json&url=${encodeURIComponent(url)}`;
|
||||
else if(isDomainSuffix('tiktok.com', urlInfo.host))
|
||||
oEmbedUrl = `https://www.tiktok.com/oembed?url=${encodeURIComponent(url)}`;
|
||||
else if(html !== undefined)
|
||||
oEmbedUrl = html('link[rel="alternate"][type="application/json+oembed"]').first()?.attr('href')?.trim() ?? '';
|
||||
|
||||
|
@ -717,7 +730,7 @@ const requestHandler = async (req: Request): Response => {
|
|||
const urlHash = encodeBase64Url(
|
||||
await crypto.subtle.digest('SHA-256', new TextEncoder().encode(urlParamRaw))
|
||||
);
|
||||
const cacheKey = `uiharu:metadata:fv${formatVersion}:${urlHash}`;
|
||||
const cacheKey = `uiharu:${appVersion}:md:fv${formatVersion}:${urlHash}`;
|
||||
const cacheInfo = await cache.get(cacheKey);
|
||||
if(cacheInfo !== undefined)
|
||||
return new Response(
|
||||
|
|
Loading…
Reference in a new issue