diff --git a/uiharu.ts b/uiharu.ts index 1c5c636..2e0f90c 100644 --- a/uiharu.ts +++ b/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 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(