diff --git a/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift b/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift index 4514916d9..505fbd1a6 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift @@ -153,8 +153,8 @@ public final class DataService: ObservableObject { linkedItem.originalHtml = html linkedItem.title = title ?? self.titleFromPdfFile(pageScrape.url) case .none: - print("SAVING NONE TYPE") - throw BasicError.message(messageText: "Attempting to save none type") + print("SAVING URL", linkedItem.unwrappedPageURLString) + linkedItem.contentReader = "WEB" } do { diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SavePage.swift b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SavePage.swift index ee2c54733..7229db5c3 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SavePage.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SavePage.swift @@ -3,23 +3,23 @@ import Models import SwiftGraphQL public extension DataService { - func savePage(pageScrapePayload: PageScrapePayload, html: String, title: String?, requestId: String) async throws { + func savePage(item: LinkedItem) async throws { enum MutationResult { case saved(requestId: String, url: String) case error(errorCode: Enums.SaveErrorCode) } let input = InputObjects.SavePageInput( - url: pageScrapePayload.url, + url: item.unwrappedPageURLString, source: "ios-page", - clientRequestId: requestId, - title: OptionalArgument(title), - originalContent: html + clientRequestId: item.unwrappedID, + title: OptionalArgument(item.title), + originalContent: item.originalHtml! ) let selection = Selection { try $0.on( - saveSuccess: .init { .saved(requestId: requestId, url: (try? $0.url()) ?? "") }, + saveSuccess: .init { .saved(requestId: item.unwrappedID, url: (try? $0.url()) ?? "") }, saveError: .init { .error(errorCode: (try? $0.errorCodes().first) ?? .unknown) } @@ -43,7 +43,6 @@ public extension DataService { ) return } - switch payload.data { case .saved: continuation.resume() diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SaveUrl.swift b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SaveUrl.swift index 6f29d8e04..2cacf3d5c 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SaveUrl.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SaveUrl.swift @@ -3,18 +3,20 @@ import Models import SwiftGraphQL public extension DataService { - func saveURL(pageScrapePayload: PageScrapePayload, requestId: String) async throws { + func saveURL(item: LinkedItem) async throws { enum MutationResult { case saved(requestId: String, url: String) case error(errorCode: Enums.SaveErrorCode) } let input = InputObjects.SaveUrlInput( - url: pageScrapePayload.url, + url: item.unwrappedPageURLString, source: "ios-url", - clientRequestId: requestId + clientRequestId: item.unwrappedID ) + print("UPLOADING ITEM:", item.unwrappedID, item) + let requestId = item.unwrappedID let selection = Selection { try $0.on( saveSuccess: .init { .saved(requestId: requestId, url: (try? $0.url()) ?? "") }, diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Networking/Networker.swift b/apple/OmnivoreKit/Sources/Services/DataService/Networking/Networker.swift index a94e514e6..d9a5d9c20 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Networking/Networker.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Networking/Networker.swift @@ -29,7 +29,6 @@ public final class Networker: NSObject, URLSessionTaskDelegate { public func urlSession(_: URLSession, task: URLSessionTask, didCompleteWithError: Error?) { if let httpResponse = task.response as? HTTPURLResponse { print("httpRespinse status code", httpResponse.statusCode) - print("current Request", task.currentRequest?.url) } print("finished upload of file:", task.taskIdentifier, task.currentRequest, task.response, "with error", didCompleteWithError) } diff --git a/apple/OmnivoreKit/Sources/Services/DataService/OfflineSync.swift b/apple/OmnivoreKit/Sources/Services/DataService/OfflineSync.swift index d55eb6c9f..798369406 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/OfflineSync.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/OfflineSync.swift @@ -40,13 +40,29 @@ extension DataService { case "PDF": // SaveFile uploadFilePublisher(item: item) - .receive(on: DispatchQueue.main) - .eraseToAnyPublisher() + .sink(receiveCompletion: { [weak self] _ in + print("received PDF saved completion") + }, receiveValue: { [weak self] _ in + print("recived save PDF value", item) + }) + .store(in: &subscriptions) case "WEB": if item.originalHtml != nil { - // SavePage + savePagePublisher(item: item) + .sink(receiveCompletion: { [weak self] _ in + print("received page saved completion") + }, receiveValue: { [weak self] _ in + print("recived save page value", item) + }) + .store(in: &subscriptions) } else { - // SaveURL + saveUrlPublisher(item: item) + .sink(receiveCompletion: { [weak self] _ in + print("received url saved completion") + }, receiveValue: { [weak self] _ in +// print("recived save url value", item) + }) + .store(in: &subscriptions) } case .none: print("NONE HANDLER") @@ -61,7 +77,7 @@ extension DataService { switch syncStatus { case .needsCreation: - print("SYNCING LINKED ITEM", unsyncedLinkedItems) + syncLocalCreatedLinkedItem(item: item) case .isNSync, .isSyncing: break case .needsDeletion: diff --git a/packages/api/src/resolvers/upload_files/index.ts b/packages/api/src/resolvers/upload_files/index.ts index 0fb38ea06..5e49aa0ac 100644 --- a/packages/api/src/resolvers/upload_files/index.ts +++ b/packages/api/src/resolvers/upload_files/index.ts @@ -112,7 +112,7 @@ export const uploadFileRequestResolver: ResolverFn< savedAt: new Date(), readingProgressPercent: 0, readingProgressAnchorIndex: 0, - state: ArticleSavingRequestStatus.Processing, + state: ArticleSavingRequestStatus.Succeeded, }, ctx )