Skip to content

Commit

Permalink
Clear parser & Fix Archive
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuz0u committed May 5, 2021
1 parent 63f43fa commit 145858a
Show file tree
Hide file tree
Showing 7 changed files with 365 additions and 296 deletions.
496 changes: 284 additions & 212 deletions EhPanda/App/Tools/Parser.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion EhPanda/DataFlow/AppAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ enum AppAction {
case fetchAssociatedItemsDone(result: Result<(Depth, AssociatedKeyword, PageNumber, [Manga]), AppError>)
case fetchMoreAssociatedItems(depth: Int, keyword: AssociatedKeyword)
case fetchMoreAssociatedItemsDone(result: Result<(Depth, AssociatedKeyword, PageNumber, [Manga]), AppError>)
case fetchAlterImages(gid: String, doc: HTMLDocument)
case fetchAlterImages(gid: String)
case fetchAlterImagesDone(result: Result<(Identity, [MangaAlterData]), AppError>)
case updateMangaComments(gid: String)
case updateMangaCommentsDone(result: Result<(Identity, [MangaComment]), AppError>)
Expand Down
6 changes: 3 additions & 3 deletions EhPanda/DataFlow/AppCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ struct FetchMangaDetailCommand: AppCommand {
} receiveValue: { detail in
store.dispatch(.fetchMangaDetailDone(result: .success((gid, detail.0, detail.1))))
if detail.0.previews.isEmpty == true {
store.dispatch(.fetchAlterImages(gid: gid, doc: detail.2))
store.dispatch(.fetchAlterImages(gid: gid))
}
}
.seal(in: token)
Expand Down Expand Up @@ -411,11 +411,11 @@ struct FetchMoreAssociatedItemsCommand: AppCommand {

struct FetchAlterImagesCommand: AppCommand {
let gid: String
let doc: HTMLDocument
let alterImagesURL: String

func execute(in store: Store) {
let token = SubscriptionToken()
AlterImagesRequest(doc: doc)
AlterImagesRequest(alterImagesURL: alterImagesURL)
.publisher
.receive(on: DispatchQueue.main)
.sink { completion in
Expand Down
9 changes: 5 additions & 4 deletions EhPanda/DataFlow/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,7 @@ final class Store: ObservableObject {
if appState.detailInfo.mangaArchiveFundsLoading { break }
appState.detailInfo.mangaArchiveFundsLoading = true

let detailURL = (appState.cachedList.items?[gid]?.detailURL ?? "")
.replacingOccurrences(of: Defaults.URL.exhentai, with: Defaults.URL.ehentai)
let detailURL = appState.cachedList.items?[gid]?.detailURL ?? ""
appCommand = FetchMangaArchiveFundsCommand(detailURL: detailURL)
case .fetchMangaArchiveFundsDone(let result):
appState.detailInfo.mangaArchiveFundsLoading = false
Expand Down Expand Up @@ -602,11 +601,13 @@ final class Store: ObservableObject {
print(error)
}

case .fetchAlterImages(let gid, let doc):
case .fetchAlterImages(let gid):
if appState.detailInfo.alterImagesLoading { break }
appState.detailInfo.alterImagesLoading = true

appCommand = FetchAlterImagesCommand(gid: gid, doc: doc)
let alterImagesURL = appState.cachedList.items?[gid]?.detail?.alterImagesURL ?? ""
appCommand = FetchAlterImagesCommand(gid: gid, alterImagesURL: alterImagesURL)

case .fetchAlterImagesDone(let result):
appState.detailInfo.alterImagesLoading = false

Expand Down
23 changes: 7 additions & 16 deletions EhPanda/Models/Manga.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct Manga: Identifiable, Codable, Equatable {
category: .nonH,
uploader: nil,
publishedTime: "",
publishedDate: Date(),
coverURL: "",
detailURL: ""
)
Expand All @@ -40,6 +41,7 @@ struct Manga: Identifiable, Codable, Equatable {
var language: Language?
let uploader: String?
let publishedTime: String
let publishedDate: Date
let coverURL: String
let detailURL: String
var lastOpenTime: Date?
Expand All @@ -48,6 +50,7 @@ struct Manga: Identifiable, Codable, Equatable {
struct MangaDetail: Codable {
static let empty = MangaDetail(
isFavored: false,
alterImagesURL: nil,
alterImages: [],
torrents: [],
comments: [],
Expand All @@ -60,6 +63,7 @@ struct MangaDetail: Codable {
language: .English,
uploader: "",
publishedTime: "",
publishedDate: Date(),
coverURL: "",
likeCount: "",
pageCount: "",
Expand All @@ -75,6 +79,7 @@ struct MangaDetail: Codable {
var isFavored: Bool
var archiveURL: String?
var archive: MangaArchive?
let alterImagesURL: String?
var alterImages: [MangaAlterData]
var torrents: [MangaTorrent]
var comments: [MangaComment]
Expand All @@ -90,6 +95,7 @@ struct MangaDetail: Codable {
let language: Language
let uploader: String
let publishedTime: String
let publishedDate: Date
let coverURL: String
var likeCount: String
var pageCount: String
Expand Down Expand Up @@ -129,6 +135,7 @@ struct MangaComment: Identifiable, Codable {
let author: String
let contents: [CommentContent]
let commentID: String
let commentTime: String
let commentDate: Date
}

Expand Down Expand Up @@ -188,11 +195,6 @@ extension Manga {
var color: Color {
category.color
}
var publishedDate: Date {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm"
return formatter.date(from: publishedTime) ?? Date()
}
}

extension MangaDetail {
Expand All @@ -201,17 +203,6 @@ extension MangaDetail {
}
}

extension MangaComment {
var commentTime: String {
let formatter = DateFormatter()
formatter.locale = Locale.current
formatter.timeZone = TimeZone.current
formatter.dateFormat = "yyyy-MM-dd HH:mm"

return formatter.string(from: commentDate)
}
}

extension Category {
var color: Color {
Color(galleryType.rawValue + "/" + rawValue)
Expand Down
Loading

0 comments on commit 145858a

Please sign in to comment.