Skip to content

Commit

Permalink
PATCH: Add SpeakEasy HTTP header when loading Link Preview from SAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
nmagedman committed Jun 4, 2024
1 parent 1ea6c2b commit e5b4252
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions apps/meteor/app/oembed/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,23 @@ const getUrlContent = async (urlObj: URL, redirectCount = 5): Promise<OEmbedUrlC
const sizeLimit = 250000;

log.debug(`Fetching ${url} following redirects ${redirectCount} times`);

const hittingSAPI =
(process.env.SPEAKEASY_HTTP_HEADER_KEY && process.env.SPEAKEASY_HTTP_HEADER_VALUE) &&

Check failure on line 104 in apps/meteor/app/oembed/server/server.ts

View workflow job for this annotation

GitHub Actions / 🔎 Code Check / Code Lint

Replace `(process.env.SPEAKEASY_HTTP_HEADER_KEY·&&·process.env.SPEAKEASY_HTTP_HEADER_VALUE)` with `process.env.SPEAKEASY_HTTP_HEADER_KEY·&&⏎↹↹process.env.SPEAKEASY_HTTP_HEADER_VALUE`
(urlObj.hostname === 'seekingalpha.com' || urlObj.hostname.endsWith('.seekingalpha.com'));

const response = await fetch(
url,
{
compress: true,
follow: redirectCount,
headers: {
'User-Agent': `${settings.get('API_Embed_UserAgent')} Rocket.Chat/${Info.version}`,
'Accept-Language': settings.get('Language') || 'en',
},
headers: Object.assign(
{
'User-Agent': `${settings.get('API_Embed_UserAgent')} Rocket.Chat/${Info.version}`,
'Accept-Language': settings.get('Language') || 'en',
},
hittingSAPI ? { [process.env.SPEAKEASY_HTTP_HEADER_KEY]: process.env.SPEAKEASY_HTTP_HEADER_VALUE } : {},
),
size: sizeLimit, // max size of the response body, this was not working as expected so I'm also manually verifying that on the iterator
},
settings.get('Allow_Invalid_SelfSigned_Certs'),
Expand Down

0 comments on commit e5b4252

Please sign in to comment.