From 9b5b5d9caa9e5073b976830c27c783c1988e82cb Mon Sep 17 00:00:00 2001 From: imjihun Date: Wed, 2 Mar 2022 13:51:45 +0900 Subject: [PATCH 1/4] Update the user-agent for preview purposes. - Update to receive social tag of firebase dynamic link --- src/utils.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index d3df83c..46442f7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -83,8 +83,9 @@ export const getPreviewData = async (text: string, requestTimeout = 5000) => { const request = fetch(url, { headers: { - 'User-Agent': - 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36', + /* very slow */ + // 'User-Agent': 'googlebot', + 'User-Agent': 'facebookexternalhit/1.1', }, signal: abortController.signal, }) @@ -112,7 +113,7 @@ export const getPreviewData = async (text: string, requestTimeout = 5000) => { // Some pages return undefined if (!html) return previewData - const head = html.substring(0, html.indexOf('')) // Get page title const title = REGEX_TITLE.exec(head) From f68abd93335c0f4d7e88be4fc1d8608cddbef610 Mon Sep 17 00:00:00 2001 From: Saehanseul Date: Tue, 5 Apr 2022 18:07:17 +0900 Subject: [PATCH 2/4] Bug: fix module html split range check text --- src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index 46442f7..75f6c5a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -113,7 +113,7 @@ export const getPreviewData = async (text: string, requestTimeout = 5000) => { // Some pages return undefined if (!html) return previewData - const head = html.substring(0, html.indexOf('body>')) + const head = html.substring(0, html.indexOf('')) // Get page title const title = REGEX_TITLE.exec(head) From 9737ed3a36d37c1b0c7434c380f3a40c4e22469b Mon Sep 17 00:00:00 2001 From: imjihun Date: Thu, 28 Apr 2022 15:41:25 +0900 Subject: [PATCH 3/4] =?UTF-8?q?Feat:=20title=20=EB=B3=B4=EB=8B=A4=20og:tit?= =?UTF-8?q?le=20=ED=83=9C=EA=B7=B8=EA=B0=80=20=EC=9A=B0=EC=84=A0=20?= =?UTF-8?q?=EB=B0=98=EC=98=81=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 75f6c5a..b9bc3a7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -153,12 +153,12 @@ export const getPreviewData = async (text: string, requestTimeout = 5000) => { title: ogTitle ? getHtmlEntitiesDecodedText(ogTitle) : acc.title, } }, - { title: previewData.title } + {} ) previewData.description = metaPreviewData.description previewData.image = await getPreviewDataImage(metaPreviewData.imageUrl) - previewData.title = metaPreviewData.title + previewData.title = metaPreviewData.title || previewData.title if (!previewData.image) { let imageMatches: RegExpMatchArray | null @@ -202,7 +202,7 @@ export const getPreviewDataImage = async (url?: string) => { const image: PreviewDataImage = { height, url, width } return image } - } catch {} + } catch { } } export const oneOf = @@ -210,9 +210,9 @@ export const oneOf = truthy: T | undefined, falsy: U ) => - (...args: Parameters): ReturnType | U => { - return truthy ? truthy(...args) : falsy - } + (...args: Parameters): ReturnType | U => { + return truthy ? truthy(...args) : falsy + } export const REGEX_EMAIL = /([a-zA-Z0-9+._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/g export const REGEX_IMAGE_CONTENT_TYPE = /image\/*/g From 7d7ebef067589485024f653ee7b0b701980c53b0 Mon Sep 17 00:00:00 2001 From: imjihun Date: Mon, 9 Jan 2023 16:40:51 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Bug:=20tsc=20bug=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - npm i 중 yarn compile 할 때 버그 발생 --- src/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index b9bc3a7..087e455 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -122,7 +122,7 @@ export const getPreviewData = async (text: string, requestTimeout = 5000) => { let matches: RegExpMatchArray | null const meta: RegExpMatchArray[] = [] while ((matches = REGEX_META.exec(head)) !== null) { - meta.push([...matches]) + meta.push([...matches] as RegExpMatchArray) } const metaPreviewData = meta.reduce<{ @@ -164,7 +164,7 @@ export const getPreviewData = async (text: string, requestTimeout = 5000) => { let imageMatches: RegExpMatchArray | null const tags: RegExpMatchArray[] = [] while ((imageMatches = REGEX_IMAGE_TAG.exec(html)) !== null) { - tags.push([...imageMatches]) + tags.push([...imageMatches] as RegExpMatchArray) } let images: PreviewDataImage[] = []