diff --git a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift index d6217081c..fa89eeb4e 100644 --- a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift +++ b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift @@ -142,6 +142,7 @@ import Utils // NOTE: the issue here is the PDF is downloaded, but saved to a URL we don't know about // because it is changed. let pdfURL = await viewModel.downloadPDF(dataService: dataService) + print("PDF URL", pdfURL) if let pdfURL = pdfURL { let document = HighlightedDocument(url: pdfURL, viewModel: viewModel) pdfStateObject.document = document diff --git a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewerViewModel.swift b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewerViewModel.swift index 5b25456cb..2f78cef45 100644 --- a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewerViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewerViewModel.swift @@ -3,6 +3,7 @@ import CoreData import Foundation import Models import Services +import Utils public final class PDFViewerViewModel: ObservableObject { @Published public var errorMessage: String? @@ -93,6 +94,12 @@ public final class PDFViewerViewModel: ObservableObject { if itemDownloaded { return pdfItem.localPdfURL } + if let tempURL = pdfItem.tempPDFURL { + if let localURL = try? PDFUtils.copyToLocal(url: tempURL) { + return tempURL + // return URL(string: localURL) + } + } if let localURL = try await dataService.fetchPDFData(slug: pdfItem.slug, pageURLString: pdfItem.originalArticleURL) { return localURL } diff --git a/apple/OmnivoreKit/Sources/Models/CoreData/CoreDataModel.xcdatamodeld/CoreDataModel.xcdatamodel/contents b/apple/OmnivoreKit/Sources/Models/CoreData/CoreDataModel.xcdatamodeld/CoreDataModel.xcdatamodel/contents index fec76121b..9c4257c46 100644 --- a/apple/OmnivoreKit/Sources/Models/CoreData/CoreDataModel.xcdatamodeld/CoreDataModel.xcdatamodel/contents +++ b/apple/OmnivoreKit/Sources/Models/CoreData/CoreDataModel.xcdatamodeld/CoreDataModel.xcdatamodel/contents @@ -44,6 +44,7 @@ + @@ -91,7 +92,7 @@ - + diff --git a/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift b/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift index 4147401d9..d74f21aeb 100644 --- a/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift +++ b/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift @@ -47,7 +47,7 @@ public extension LinkedItem { var isReadyToRead: Bool { if isPDF { // If its a PDF we verify the local file is available - return PDFUtils.exists(filename: localPDF) + return PDFUtils.exists(filename: localPDF) || PDFUtils.tempExists(tempPDFURL: tempPDFURL) } // Check the state and whether we have HTML return state == "SUCCEEDED" diff --git a/apple/OmnivoreKit/Sources/Models/DataModels/PDFItem.swift b/apple/OmnivoreKit/Sources/Models/DataModels/PDFItem.swift index 475f8dfb9..43c2eb672 100644 --- a/apple/OmnivoreKit/Sources/Models/DataModels/PDFItem.swift +++ b/apple/OmnivoreKit/Sources/Models/DataModels/PDFItem.swift @@ -7,6 +7,7 @@ public struct PDFItem { public let itemID: String public let pdfURL: URL? public let localPDF: String? + public let tempPDFURL: URL? public let title: String public let slug: String public let readingProgress: Double @@ -24,6 +25,7 @@ public struct PDFItem { itemID: item.unwrappedID, pdfURL: URL(string: item.unwrappedPageURLString), localPDF: item.localPDF, + tempPDFURL: item.tempPDFURL, title: item.unwrappedID, slug: item.unwrappedSlug, readingProgress: item.readingProgress, diff --git a/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift b/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift index eb464759c..f14ac5b6a 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift @@ -148,9 +148,8 @@ public final class DataService: ObservableObject { switch pageScrape.contentType { case let .pdf(localUrl): linkedItem.contentReader = "PDF" + linkedItem.tempPDFURL = localUrl linkedItem.title = PDFUtils.titleFromPdfFile(pageScrape.url) - print("PERSISTING PDF", localUrl) - linkedItem.localPDF = try PDFUtils.copyToLocal(url: localUrl) case let .html(html: html, title: title, iconURL: iconURL): linkedItem.contentReader = "WEB" linkedItem.originalHtml = html diff --git a/apple/OmnivoreKit/Sources/Utils/PDFUtils.swift b/apple/OmnivoreKit/Sources/Utils/PDFUtils.swift index 0d4a4c19c..d7c89cd68 100644 --- a/apple/OmnivoreKit/Sources/Utils/PDFUtils.swift +++ b/apple/OmnivoreKit/Sources/Utils/PDFUtils.swift @@ -45,6 +45,13 @@ public enum PDFUtils { return false } + public static func tempExists(tempPDFURL: URL?) -> Bool { + if let tempPDFURL = tempPDFURL { + return FileManager.default.fileExists(atPath: tempPDFURL.path) + } + return false + } + public static func titleFromPdfFile(_ urlStr: String) -> String { let url = URL(string: urlStr) if let url = url {