Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: oembed #3494

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Loading