mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
iOS: fix for PDF downloads, always use the download signed URL, not the original URL
This commit is contained in:
parent
4e2e23c570
commit
d7bd5c54a3
10 changed files with 17 additions and 8 deletions
|
|
@ -96,7 +96,7 @@ final class PDFViewerViewModel: ObservableObject {
|
|||
}
|
||||
}
|
||||
|
||||
return try await dataService.loadPDFData(slug: pdfItem.slug, pageURLString: pdfItem.originalArticleURL)
|
||||
return try await dataService.loadPDFData(slug: pdfItem.slug, downloadURL: pdfItem.downloadURL)
|
||||
} catch {
|
||||
print("error downloading PDF", error)
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ import Views
|
|||
private func trackReadEvent() {
|
||||
guard let itemID = item?.unwrappedID ?? pdfItem?.itemID else { return }
|
||||
guard let slug = item?.unwrappedSlug ?? pdfItem?.slug else { return }
|
||||
guard let originalArticleURL = item?.unwrappedPageURLString ?? pdfItem?.originalArticleURL else { return }
|
||||
guard let originalArticleURL = item?.unwrappedPageURLString ?? pdfItem?.downloadURL else { return }
|
||||
|
||||
EventTracker.track(
|
||||
.linkRead(
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21513" systemVersion="21G531" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22225" systemVersion="22G74" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
|
||||
<entity name="Highlight" representedClassName="Highlight" syncable="YES" codeGenerationType="class">
|
||||
<attribute name="annotation" optional="YES" attributeType="String"/>
|
||||
<attribute name="color" optional="YES" attributeType="String"/>
|
||||
|
|
@ -32,6 +32,7 @@
|
|||
<attribute name="createdAt" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="createdId" optional="YES" attributeType="String"/>
|
||||
<attribute name="descriptionText" optional="YES" attributeType="String"/>
|
||||
<attribute name="downloadURL" optional="YES" attributeType="String"/>
|
||||
<attribute name="htmlContent" optional="YES" attributeType="String"/>
|
||||
<attribute name="id" attributeType="String"/>
|
||||
<attribute name="imageURLString" optional="YES" attributeType="String"/>
|
||||
|
|
|
|||
|
|
@ -56,12 +56,14 @@ public struct JSONArticle: Decodable {
|
|||
public let isArchived: Bool
|
||||
public let language: String?
|
||||
public let wordsCount: Int?
|
||||
public let downloadURL: String
|
||||
}
|
||||
|
||||
public extension LinkedItem {
|
||||
var unwrappedID: String { id ?? "" }
|
||||
var unwrappedSlug: String { slug ?? "" }
|
||||
var unwrappedTitle: String { title ?? "" }
|
||||
var unwrappedDownloadURLString: String { downloadURL ?? "" }
|
||||
var unwrappedPageURLString: String { pageURLString ?? "" }
|
||||
var unwrappedSavedAt: Date { savedAt ?? Date() }
|
||||
var unwrappedCreatedAt: Date { createdAt ?? Date() }
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public struct PDFItem {
|
|||
public let readingProgressAnchor: Int
|
||||
public let isArchived: Bool
|
||||
public let isRead: Bool
|
||||
public let originalArticleURL: String
|
||||
public let downloadURL: String
|
||||
public let highlights: [Highlight]
|
||||
|
||||
public static func make(item: LinkedItem) -> PDFItem? {
|
||||
|
|
@ -32,7 +32,7 @@ public struct PDFItem {
|
|||
readingProgressAnchor: Int(item.readingProgressAnchor),
|
||||
isArchived: item.isArchived,
|
||||
isRead: item.isRead,
|
||||
originalArticleURL: item.unwrappedPageURLString,
|
||||
downloadURL: item.unwrappedPageURLString,
|
||||
highlights: item.highlights.asArray(of: Highlight.self)
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ extension DataService {
|
|||
}
|
||||
|
||||
if articleProps.item.isPDF, needsPDFDownload {
|
||||
_ = try await loadPDFData(slug: articleProps.item.slug, pageURLString: articleProps.item.pageURLString)
|
||||
_ = try await loadPDFData(slug: articleProps.item.slug, downloadURL: articleProps.item.downloadURL)
|
||||
}
|
||||
|
||||
try await backgroundContext.perform { [weak self] in
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import Models
|
|||
import Utils
|
||||
|
||||
public extension DataService {
|
||||
func loadPDFData(slug: String, pageURLString: String) async throws -> URL? {
|
||||
guard let url = URL(string: pageURLString) else {
|
||||
func loadPDFData(slug: String, downloadURL: String) async throws -> URL? {
|
||||
guard let url = URL(string: downloadURL) else {
|
||||
throw BasicError.message(messageText: "No PDF URL found")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ extension DataService {
|
|||
originalHtml: nil,
|
||||
language: try $0.language(),
|
||||
wordsCount: try $0.wordsCount(),
|
||||
downloadURL: try $0.url(),
|
||||
recommendations: try $0.recommendations(selection: recommendationSelection.list.nullable) ?? [],
|
||||
labels: try $0.labels(selection: feedItemLabelSelection.list.nullable) ?? []
|
||||
),
|
||||
|
|
|
|||
|
|
@ -277,6 +277,7 @@ private let libraryArticleSelection = Selection.Article {
|
|||
originalHtml: nil,
|
||||
language: try $0.language(),
|
||||
wordsCount: try $0.wordsCount(),
|
||||
downloadURL: try $0.url(),
|
||||
recommendations: try $0.recommendations(selection: recommendationSelection.list.nullable) ?? [],
|
||||
labels: try $0.labels(selection: feedItemLabelSelection.list.nullable) ?? []
|
||||
)
|
||||
|
|
@ -316,6 +317,7 @@ private let searchItemSelection = Selection.SearchItem {
|
|||
originalHtml: nil,
|
||||
language: try $0.language(),
|
||||
wordsCount: try $0.wordsCount(),
|
||||
downloadURL: try $0.url(),
|
||||
recommendations: try $0.recommendations(selection: recommendationSelection.list.nullable) ?? [],
|
||||
labels: try $0.labels(selection: feedItemLabelSelection.list.nullable) ?? []
|
||||
)
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ struct InternalLinkedItem {
|
|||
let originalHtml: String?
|
||||
let language: String?
|
||||
let wordsCount: Int?
|
||||
let downloadURL: String
|
||||
let recommendations: [InternalRecommendation]
|
||||
var labels: [InternalLinkedItemLabel]
|
||||
|
||||
|
|
@ -65,6 +66,7 @@ struct InternalLinkedItem {
|
|||
linkedItem.originalHtml = originalHtml
|
||||
linkedItem.language = language
|
||||
linkedItem.wordsCount = Int64(wordsCount ?? 0)
|
||||
linkedItem.downloadURL = downloadURL
|
||||
|
||||
// Remove existing labels in case a label had been deleted
|
||||
if let existingLabels = linkedItem.labels {
|
||||
|
|
@ -146,6 +148,7 @@ extension JSONArticle {
|
|||
originalHtml: nil,
|
||||
language: language,
|
||||
wordsCount: wordsCount,
|
||||
downloadURL: downloadURL,
|
||||
recommendations: [],
|
||||
labels: []
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue