Skip to content

Commit

Permalink
fix: Speed up link preview generation (WEBAPP-6415) (#3139)
Browse files Browse the repository at this point in the history
  • Loading branch information
ffflorian authored Oct 22, 2019
1 parent 1a30f3b commit 9850908
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions electron/src/lib/openGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,7 @@ const fetchOpenGraphData = async (url: string): Promise<OpenGraphResult> => {
};

const body = await axiosWithContentLimit(axiosConfig, CONTENT_SIZE_LIMIT);
// For the regex, see https://regex101.com/r/U62pCH/1
const matches = body.match(/.*property=(["'])og:.+?\1.*/gim) || [''];

if (!matches) {
throw new Error('No open graph tags found in website.');
}

const openGraphTags = matches.join(' ');

return openGraphParse(openGraphTags);
return openGraphParse(body);
};

const updateMetaDataWithImage = (meta: OpenGraphResult, imageData?: string): OpenGraphResult => {
Expand All @@ -200,7 +191,7 @@ export const getOpenGraphData = async (url: string, callback: GetDataCallback):
const [imageUrl] = arrayify(meta.image.url);

const uri = await fetchImageAsBase64(imageUrl);
meta = await updateMetaDataWithImage(meta, uri);
meta = updateMetaDataWithImage(meta, uri);
} else {
throw new Error('OpenGraph metadata contains no image.');
}
Expand Down

0 comments on commit 9850908

Please sign in to comment.