Skip to content

Commit

Permalink
fix: oembed (#3494)
Browse files Browse the repository at this point in the history
* fix: oembed

* fix: oembed
  • Loading branch information
bigint committed Aug 10, 2023
1 parent 0a56ad0 commit 0b9f785
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
14 changes: 4 additions & 10 deletions packages/workers/oembed/src/helper/getMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { encode } from '@cfworker/base64url';
import { parseHTML } from 'linkedom';

import type { Env } from '../types';
import getProxyUrl from './getProxyUrl';
import generateIframe from './meta/generateIframe';
import getDescription from './meta/getDescription';
import getEmbedUrl from './meta/getEmbedUrl';
Expand Down Expand Up @@ -32,15 +32,9 @@ const getMetadata = async (url: string, env: Env): Promise<any> => {
}));

const { document } = parseHTML(html);
const isLarge = getIsLarge(document);
const image = getImage(document);
const isProduction = env.WORKER_ENV === 'production';
const workerUrl = isProduction
? 'https://oembed.lenster.xyz'
: 'http://localhost:8087';
const proxiedUrl = `${workerUrl}/image?hash=${encode(
image || ''
)}&transform=${isLarge ? 'large' : 'square'}`;
const isLarge = getIsLarge(document) as boolean;
const image = getImage(document) as string;
const proxiedUrl = getProxyUrl(image, isLarge, env);
const metadata: Metadata = {
url,
title: getTitle(document),
Expand Down
26 changes: 26 additions & 0 deletions packages/workers/oembed/src/helper/getProxyUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { encode } from '@cfworker/base64url';

import type { Env } from '../types';

const directUrls = [
'zora.co/api/thumbnail' // Zora
];

const getProxyUrl = (url: string, isLarge: boolean, env: Env) => {
const isDirect = directUrls.some((directUrl) => url.includes(directUrl));

if (isDirect) {
return url;
}

const isProduction = env.WORKER_ENV === 'production';
const workerUrl = isProduction
? 'https://oembed.lenster.xyz'
: 'http://localhost:8087';

return `${workerUrl}/image?hash=${encode(url)}&transform=${
isLarge ? 'large' : 'square'
}`;
};

export default getProxyUrl;

1 comment on commit 0b9f785

@vercel
Copy link

@vercel vercel bot commented on 0b9f785 Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

prerender – ./apps/prerender

prerender-lenster.vercel.app
prerender-git-main-lenster.vercel.app
prerender.lenster.xyz

Please sign in to comment.