Bump version, attempt to refetch PDFs if download signed URL has expired

This commit is contained in:
Jackson Harper
2023-10-24 12:11:28 +08:00
parent d7bd5c54a3
commit 9a1ccd46bc
4 changed files with 45 additions and 4 deletions

View File

@ -96,7 +96,18 @@ final class PDFViewerViewModel: ObservableObject {
}
}
return try await dataService.loadPDFData(slug: pdfItem.slug, downloadURL: pdfItem.downloadURL)
if let result = try? await dataService.loadPDFData(slug: pdfItem.slug, downloadURL: pdfItem.downloadURL) {
return result
}
// Downloading failed, try to get the article again, and then download
if let content = try? await dataService.loadArticleContentWithRetries(itemID: pdfItem.itemID, username: "me") {
// refetched the content, now try one more time then throw
if let result = try await dataService.loadPDFData(slug: pdfItem.slug, downloadURL: content.downloadURL) {
return result
}
}
return nil
} catch {
print("error downloading PDF", error)
return nil

View File

@ -16,19 +16,22 @@ public struct ArticleContent {
public let highlightsJSONString: String
public let contentStatus: ArticleContentStatus
public let objectID: NSManagedObjectID?
public let downloadURL: String
public init(
title: String,
htmlContent: String,
highlightsJSONString: String,
contentStatus: ArticleContentStatus,
objectID: NSManagedObjectID?
objectID: NSManagedObjectID?,
downloadURL: String
) {
self.title = title
self.htmlContent = htmlContent
self.highlightsJSONString = highlightsJSONString
self.contentStatus = contentStatus
self.objectID = objectID
self.downloadURL = downloadURL
}
}

View File

@ -63,7 +63,8 @@ extension DataService {
htmlContent: fetchResult.htmlContent,
highlightsJSONString: fetchResult.highlights.asJSONString,
contentStatus: fetchResult.item.isPDF ? .succeeded : fetchResult.item.state,
objectID: objectID
objectID: objectID,
downloadURL: fetchResult.item.downloadURL
)
}
@ -91,7 +92,8 @@ extension DataService {
.filter { $0.serverSyncStatus != ServerSyncStatus.needsDeletion.rawValue }
.map { InternalHighlight.make(from: $0) }.asJSONString,
contentStatus: .succeeded,
objectID: linkedItem.objectID
objectID: linkedItem.objectID,
downloadURL: linkedItem.downloadURL ?? ""
)
}
}