Merge pull request #3422 from omnivore-app/fix/no-content

set the state to failed if content is not fetched
This commit is contained in:
Hongbo Wu 2024-01-23 22:18:35 +08:00 committed by GitHub
commit 9f1a17853a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -114,7 +114,7 @@ const getUploadIdAndSignedUrl = async (
}`,
variables: {
input: {
url,
url: encodeURI(url),
contentType: 'application/pdf',
clientRequestId: articleSavingRequestId,
},
@ -279,7 +279,6 @@ export const savePageJob = async (data: Data, attemptsMade: number) => {
const {
userId,
articleSavingRequestId,
state,
labels,
source,
folder,
@ -289,24 +288,23 @@ 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') {
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,
@ -329,9 +327,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)