From d4e487e181e090991782384eee544d1dbd37c5fa Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Tue, 23 Jan 2024 21:50:10 +0800 Subject: [PATCH 1/2] set the state to failed if content is not fetched --- packages/api/src/jobs/save_page.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/api/src/jobs/save_page.ts b/packages/api/src/jobs/save_page.ts index 07cbde2f3..191597873 100644 --- a/packages/api/src/jobs/save_page.ts +++ b/packages/api/src/jobs/save_page.ts @@ -279,7 +279,6 @@ export const savePageJob = async (data: Data, attemptsMade: number) => { const { userId, articleSavingRequestId, - state, labels, source, folder, @@ -289,14 +288,17 @@ export const savePageJob = async (data: Data, attemptsMade: number) => { taskId, url, } = data - let isImported, isSaved + let isImported, + isSaved, + state = data.state try { console.log(`savePageJob: ${userId} ${url}`) // get the fetch result from cache - const { title, content, contentType, readabilityResult } = - await getCachedFetchResult(url) + const fetchedResult = await getCachedFetchResult(url) + const { title, contentType, readabilityResult } = fetchedResult + let content = fetchedResult.content // for pdf content, we need to upload the pdf if (contentType === 'application/pdf') { @@ -329,9 +331,10 @@ export const savePageJob = async (data: Data, attemptsMade: number) => { } if (!content) { - throw new Error( - 'Invalid SavePage job, fetch result missing required data' - ) + console.log('content is not fetched', url) + // set the state to failed if we don't have content + content = 'Failed to fetch content' + state = ArticleSavingRequestStatus.Failed } const user = await userRepository.findById(userId) From c1d5ec722f68b0acfcd236934859841625c55e7b Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Tue, 23 Jan 2024 22:06:27 +0800 Subject: [PATCH 2/2] do not encode url when getting file data --- packages/api/src/jobs/save_page.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/api/src/jobs/save_page.ts b/packages/api/src/jobs/save_page.ts index 191597873..14500d959 100644 --- a/packages/api/src/jobs/save_page.ts +++ b/packages/api/src/jobs/save_page.ts @@ -114,7 +114,7 @@ const getUploadIdAndSignedUrl = async ( }`, variables: { input: { - url, + url: encodeURI(url), contentType: 'application/pdf', clientRequestId: articleSavingRequestId, }, @@ -304,11 +304,7 @@ export const savePageJob = async (data: Data, attemptsMade: number) => { if (contentType === 'application/pdf') { const encodedUrl = encodeURI(url) - const uploadFileId = await uploadPdf( - encodedUrl, - userId, - articleSavingRequestId - ) + const uploadFileId = await uploadPdf(url, userId, articleSavingRequestId) const uploadedPdf = await sendCreateArticleMutation(userId, { url: encodedUrl, articleSavingRequestId,