From 7c4c2de7a08bedacd2e53864957a5cbca8863b77 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 1 Nov 2020 14:15:44 -0600 Subject: [PATCH] Make folder restores work for Reader API --- .../ReaderAPI/ReaderAPIAccountDelegate.swift | 21 ++++++++++++------- .../Account/ReaderAPI/ReaderAPICaller.swift | 18 ++++++++++------ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index 9beadb958..1602469a0 100644 --- a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -299,13 +299,18 @@ final class ReaderAPIAccountDelegate: AccountDelegate { } group.notify(queue: DispatchQueue.main) { - self.caller.deleteTag(folder: folder) { result in - switch result { - case .success: - account.removeFolder(folder) - completion(.success(())) - case .failure(let error): - completion(.failure(error)) + if self.variant == .theOldReader { + account.removeFolder(folder) + completion(.success(())) + } else { + self.caller.deleteTag(folder: folder) { result in + switch result { + case .success: + account.removeFolder(folder) + completion(.success(())) + case .failure(let error): + completion(.failure(error)) + } } } } @@ -858,7 +863,7 @@ private extension ReaderAPIAccountDelegate { switch result { case .success: if let name = name { - account.renameWebFeed(feed, to: name) { result in + self.renameWebFeed(for: account, with: feed, to: name) { result in switch result { case .success: self.initialFeedDownload(account: account, feed: feed, completion: completion) diff --git a/Account/Sources/Account/ReaderAPI/ReaderAPICaller.swift b/Account/Sources/Account/ReaderAPI/ReaderAPICaller.swift index b83b58f64..48784e9f8 100644 --- a/Account/Sources/Account/ReaderAPI/ReaderAPICaller.swift +++ b/Account/Sources/Account/ReaderAPI/ReaderAPICaller.swift @@ -83,6 +83,7 @@ final class ReaderAPICaller: NSObject { var urlHostAllowed = CharacterSet.urlHostAllowed urlHostAllowed.remove("+") + urlHostAllowed.remove("&") uriComponentAllowed = urlHostAllowed super.init() } @@ -387,10 +388,10 @@ final class ReaderAPICaller: NSObject { request.httpMethod = "POST" var postString = "T=\(token)&ac=subscribe&s=\(streamId)" - if let folder = folder { - postString += "&a=user/-/label/\(folder.nameForDisplay)" + if let folderName = self.encodeForURLPath(folder?.nameForDisplay) { + postString += "&a=user/-/label/\(folderName)" } - if let name = name { + if let name = self.encodeForURLPath(name) { postString += "&t=\(name)" } @@ -508,8 +509,12 @@ final class ReaderAPICaller: NSObject { request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") request.httpMethod = "POST" - let tagName = "user/-/label/\(tagName)" - let postData = "T=\(token)&s=\(subscriptionID)&ac=edit&a=\(tagName)".data(using: String.Encoding.utf8) + guard let tagName = self.encodeForURLPath(tagName) else { + completion(.failure(ReaderAPIAccountDelegateError.invalidParameter)) + return + } + + let postData = "T=\(token)&s=\(subscriptionID)&ac=edit&a=user/-/label/\(tagName)".data(using: String.Encoding.utf8) self.transport.send(request: request, method: HTTPMethod.post, payload: postData!, completion: { (result) in switch result { @@ -750,7 +755,8 @@ final class ReaderAPICaller: NSObject { private extension ReaderAPICaller { - func encodeForURLPath(_ pathComponent: String) -> String? { + func encodeForURLPath(_ pathComponent: String?) -> String? { + guard let pathComponent = pathComponent else { return nil } return pathComponent.addingPercentEncoding(withAllowedCharacters: uriComponentAllowed) }