From 87488e220ac8f09401939b113ffa38097166f1e9 Mon Sep 17 00:00:00 2001 From: Chihchy Date: Thu, 2 Nov 2023 19:21:05 +0800 Subject: [PATCH] Fix MPV parsing --- EhPanda/Network/Request.swift | 17 +++++++++++++---- EhPanda/View/Reading/ReadingReducer.swift | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/EhPanda/Network/Request.swift b/EhPanda/Network/Request.swift index 768031bb..d739ee09 100644 --- a/EhPanda/Network/Request.swift +++ b/EhPanda/Network/Request.swift @@ -612,9 +612,9 @@ struct GalleryMPVImageURLRequest: Request { let index: Int let mpvKey: String let mpvImageKey: String - let skipServerIdentifier: Int? + let skipServerIdentifier: String? - var publisher: AnyPublisher<(URL, URL?, Int), AppError> { + var publisher: AnyPublisher<(URL, URL?, String), AppError> { var params: [String: Any] = [ "method": "imagedispatch", "gid": gid, @@ -637,10 +637,19 @@ struct GalleryMPVImageURLRequest: Request { guard let dict = try JSONSerialization .jsonObject(with: data) as? [String: Any], let imageURLString = dict["i"] as? String, - let imageURL = URL(string: imageURLString), - let skipServerIdentifier = dict["s"] as? Int + let imageURL = URL(string: imageURLString) else { throw AppError.parseFailed } + var skipServerIdentifier: String? + + if let integerIdentifier = dict["s"] as? Int { + skipServerIdentifier = integerIdentifier.description + } else if let stringIdentifier = dict["s"] as? String { + skipServerIdentifier = stringIdentifier + } + + guard let skipServerIdentifier else { throw AppError.parseFailed } + if let originalImageURLStringSlice = dict["lf"] as? String { let originalImageURL = Defaults.URL.host.appendingPathComponent(originalImageURLStringSlice) return (imageURL, originalImageURL, skipServerIdentifier) diff --git a/EhPanda/View/Reading/ReadingReducer.swift b/EhPanda/View/Reading/ReadingReducer.swift index 15bf9682..96b5560b 100644 --- a/EhPanda/View/Reading/ReadingReducer.swift +++ b/EhPanda/View/Reading/ReadingReducer.swift @@ -69,7 +69,7 @@ struct ReadingReducer: ReducerProtocol { var mpvKey: String? var mpvImageKeys = [Int: String]() - var mpvSkipServerIdentifiers = [Int: Int]() + var mpvSkipServerIdentifiers = [Int: String]() @BindingState var showsPanel = false @BindingState var showsSliderPreview = false @@ -172,7 +172,7 @@ struct ReadingReducer: ReducerProtocol { case fetchMPVKeys(Int, URL) case fetchMPVKeysDone(Int, Result<(String, [Int: String]), AppError>) case fetchMPVImageURL(Int, Bool) - case fetchMPVImageURLDone(Int, Result<(URL, URL?, Int), AppError>) + case fetchMPVImageURLDone(Int, Result<(URL, URL?, String), AppError>) } @Dependency(\.appDelegateClient) private var appDelegateClient