Bump version, attempt to refetch PDFs if download signed URL has expired
This commit is contained in:
@ -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
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 ?? ""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user