Skip to content

Commit

Permalink
fix: skipCache for portals for now (#4688)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint authored Feb 26, 2024
2 parents 915f7cf + 10695d8 commit f47644b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/api/src/lib/oembed/getMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import getPortal from './meta/getPortal';
import getSite from './meta/getSite';
import getTitle from './meta/getTitle';

const getMetadata = async (url: string): Promise<any> => {
const getMetadata = async (url: string): Promise<OG> => {
const { html } = await fetch(url, {
headers: { 'User-Agent': 'HeyBot/0.1 (like TwitterBot)' }
}).then(async (res) => ({
Expand Down
6 changes: 5 additions & 1 deletion apps/api/src/routes/oembed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ export const get: Handler = async (req, res) => {
}

try {
const oembed = await getMetadata(url as string);
const skipCache = oembed.portal !== null;

logger.info(`Oembed generated for ${url}`);

return res
.status(200)
.setHeader('Cache-Control', CACHE_AGE_30_DAYS)
.setHeader('Cache-Control', skipCache ? 'no-cache' : CACHE_AGE_30_DAYS)
.json({
oembed: await getMetadata(url as string),
success: true
Expand Down

0 comments on commit f47644b

Please sign in to comment.