Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuz0u committed Jul 19, 2021
2 parents 12f15e1 + 5d0b343 commit 1c91494
Show file tree
Hide file tree
Showing 17 changed files with 360 additions and 225 deletions.
8 changes: 2 additions & 6 deletions EhPanda.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
AB358315269D821D009466A5 /* DFExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB358314269D821D009466A5 /* DFExtensions.swift */; };
AB358317269D826B009466A5 /* DFStreamHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB358316269D826B009466A5 /* DFStreamHandler.swift */; };
AB358319269D9996009466A5 /* DomainResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB358318269D9996009466A5 /* DomainResolver.swift */; };
AB35831B269DADE7009466A5 /* DFManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB35831A269DADE7009466A5 /* DFManager.swift */; };
AB38A0CB25CA993D00764D64 /* ColorCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB38A0CA25CA993D00764D64 /* ColorCodable.swift */; };
AB47FD9F25BC81A40007765D /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = AB47FD9925BC81A40007765D /* [email protected] */; };
AB47FDA025BC81A40007765D /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = AB47FD9A25BC81A40007765D /* [email protected] */; };
Expand Down Expand Up @@ -101,7 +100,6 @@
AB358314269D821D009466A5 /* DFExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFExtensions.swift; sourceTree = "<group>"; };
AB358316269D826B009466A5 /* DFStreamHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFStreamHandler.swift; sourceTree = "<group>"; };
AB358318269D9996009466A5 /* DomainResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainResolver.swift; sourceTree = "<group>"; };
AB35831A269DADE7009466A5 /* DFManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFManager.swift; sourceTree = "<group>"; };
AB38A0CA25CA993D00764D64 /* ColorCodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorCodable.swift; sourceTree = "<group>"; };
AB47FD9925BC81A40007765D /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
AB47FD9A25BC81A40007765D /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -299,7 +297,6 @@
children = (
ABCD2F09259763FC008E5A20 /* Request.swift */,
AB358318269D9996009466A5 /* DomainResolver.swift */,
AB35831A269DADE7009466A5 /* DFManager.swift */,
AB358312269D7E89009466A5 /* DFRequest.swift */,
AB358316269D826B009466A5 /* DFStreamHandler.swift */,
AB358314269D821D009466A5 /* DFExtensions.swift */,
Expand Down Expand Up @@ -574,7 +571,6 @@
ABF45ABA25F3312F00ECB568 /* AppCommand.swift in Sources */,
ABF45AE425F3313D00ECB568 /* TagCloudView.swift in Sources */,
ABCA93C22691929D00A98BC6 /* MangaDetailMO+CoreDataClass.swift in Sources */,
AB35831B269DADE7009466A5 /* DFManager.swift in Sources */,
ABF45AEE25F3313D00ECB568 /* ArchiveView.swift in Sources */,
ABF45AEC25F3313D00ECB568 /* ContentView.swift in Sources */,
ABEA1FE625A9B40B002966B9 /* Setting.swift in Sources */,
Expand Down Expand Up @@ -751,7 +747,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = EhPanda/EhPanda.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 60;
CURRENT_PROJECT_VERSION = 61;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 9SKQ7QTZ74;
ENABLE_PREVIEWS = YES;
Expand All @@ -778,7 +774,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = EhPanda/EhPanda.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 60;
CURRENT_PROJECT_VERSION = 61;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 9SKQ7QTZ74;
ENABLE_PREVIEWS = YES;
Expand Down
25 changes: 11 additions & 14 deletions EhPanda/App/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ extension Defaults.URL {
// Fetch
static func searchList(keyword: String, filter: Filter) -> String {
merge(urls: [
host,
listCompact,
fSearch + keyword.urlEncoded()
host, fSearch
+ keyword.urlEncoded()
]
+ applyFilters(filter: filter)
)
Expand All @@ -142,7 +141,6 @@ extension Defaults.URL {
merge(
urls: [
host,
listCompact,
fSearch + keyword.urlEncoded(),
page + pageNum,
from + lastID
Expand All @@ -151,25 +149,25 @@ extension Defaults.URL {
)
}
static func frontpageList() -> String {
merge(urls: [host, listCompact])
host
}
static func moreFrontpageList(pageNum: String, lastID: String) -> String {
merge(urls: [host, listCompact, page + pageNum, from + lastID])
merge(urls: [host, page + pageNum, from + lastID])
}
static func popularList() -> String {
merge(urls: [host + popular, listCompact])
host + popular
}
static func watchedList() -> String {
merge(urls: [host + watched, listCompact])
host + watched
}
static func moreWatchedList(pageNum: String, lastID: String) -> String {
merge(urls: [host + watched, page + pageNum, from + lastID])
}
static func favoritesList(favIndex: Int) -> String {
if favIndex == -1 {
return merge(urls: [host + favorites, listCompact])
return host + favorites
} else {
return merge(urls: [host + favorites, favcat + "\(favIndex)", listCompact])
return merge(urls: [host + favorites, favcat + "\(favIndex)"])
}
}
static func moreFavoritesList(favIndex: Int, pageNum: String, lastID: String) -> String {
Expand All @@ -180,7 +178,7 @@ extension Defaults.URL {
}
}
static func mangaDetail(url: String) -> String {
merge(urls: [url, ignoreOffensive, showComments, previewLarge])
merge(urls: [url, showComments])
}
static func mangaTorrents(gid: String, token: String) -> String {
merge(urls: [host + gallerytorrents, Defaults.URL.gid + gid, Defaults.URL.token + token])
Expand All @@ -196,7 +194,7 @@ extension Defaults.URL {
merge(keyword: keyword, pageNum: nil, lastID: nil)
}
static func similarGallery(keyword: String) -> String {
merge(urls: [host, listCompact, fSearch + keyword.urlEncoded()])
merge(urls: [host, fSearch + keyword.urlEncoded()])
}
static func moreAssociatedItemsRedir(keyword: AssociatedKeyword, lastID: String, pageNum: String) -> String {
if let title = keyword.title {
Expand All @@ -214,14 +212,13 @@ extension Defaults.URL {
static func moreSimilarGallery(keyword: String, pageNum: String, lastID: String) -> String {
merge(urls: [
host,
listCompact,
fSearch + keyword.urlEncoded(),
page + pageNum,
from + lastID
])
}
static func mangaContents(detailURL: String) -> String {
merge(urls: [detailURL, previewLarge, rowsLimit])
detailURL
}

// Account Associated Operations
Expand Down
71 changes: 37 additions & 34 deletions EhPanda/App/EhPandaApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct EhPandaApp: App {
.task(onStartTasks)
.environmentObject(store)
.accentColor(accentColor)
.onOpenURL(perform: onOpenURL)
.preferredColorScheme(preferredColorScheme)
}
}
Expand All @@ -37,29 +36,42 @@ private extension EhPandaApp {
}

func onStartTasks() {
syncGalleryHost()
configureLogging()
configureWebImage()
configureDomainFronting()
clearImageCachesIfNeeded()

DispatchQueue.main.async {
store.dispatch(.fetchUserInfo)
store.dispatch(.fetchFavoriteNames)
dispatchMainSync {
syncGalleryHost()
configureLogging()
configureWebImage()
configureDomainFronting()
configureIgnoreOffensive()
}
}
func onOpenURL(url: URL) {
switch url.host {
case "debugMode":
setDebugMode(with: url.pathComponents.last == "on")
default:
break
dispatchMainAsync {
fetchAccountInfoIfNeeded()
clearImageCachesIfNeeded()
}
}

func syncGalleryHost() {
setGalleryHost(with: setting.galleryHost)
}
func fetchAccountInfoIfNeeded() {
guard didLogin else { return }

store.dispatch(.verifyProfile)
store.dispatch(.fetchUserInfo)
store.dispatch(.fetchFavoriteNames)
}
func clearImageCachesIfNeeded() {
let threshold = 200 * 1024 * 1024

KingfisherManager.shared.cache.calculateDiskStorageSize { result in
if case .success(let size) = result, size > threshold {
KingfisherManager.shared.cache.clearDiskCache()
}
}
}
}

// MARK: Configuration
private extension EhPandaApp {
func configureLogging() {
var file = FileDestination()
var console = ConsoleDestination()
Expand Down Expand Up @@ -99,27 +111,18 @@ private extension EhPandaApp {
}

func configureWebImage() {
let config = KingfisherManager.shared
.downloader.sessionConfiguration
if setting.bypassSNIFiltering {
config.protocolClasses = [DFURLProtocol.self]
}
let config = KingfisherManager.shared.downloader.sessionConfiguration
config.httpCookieStorage = HTTPCookieStorage.shared
KingfisherManager.shared.downloader.sessionConfiguration = config
}
func configureDomainFronting() {
DFManager.shared.dfState = setting.bypassSNIFiltering
? .activated : .notActivated
}
func clearImageCachesIfNeeded() {
let threshold = 200 * 1024 * 1024

KingfisherManager.shared.cache.calculateDiskStorageSize { result in
if case .success(let size) = result {
if size > threshold {
KingfisherManager.shared.cache.clearDiskCache()
}
}
if setting.bypassSNIFiltering {
URLProtocol.registerClass(DFURLProtocol.self)
URLProtocol.registerWebview(scheme: "https")
}
}
func configureIgnoreOffensive() {
setCookie(url: Defaults.URL.ehentai.safeURL(), key: "nw", value: "1")
setCookie(url: Defaults.URL.exhentai.safeURL(), key: "nw", value: "1")
}
}
5 changes: 5 additions & 0 deletions EhPanda/App/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ extension String {
) ?? ""
}

func urlDecoded() -> String {
(removingPercentEncoding ?? "")
.replacingOccurrences(of: "%3F", with: "?")
}

var withComma: String? {
Int(self)?.formatted(.number)
}
Expand Down
35 changes: 24 additions & 11 deletions EhPanda/App/Tools/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ struct Parser {

// MARK: Content
static func parseImagePreContents(doc: HTMLDocument, previewMode: String, pageCount: Int) throws -> [(Int, URL)] {
copyHTMLIfNeeded(html: doc.toHTML)
var imageDetailURLs = [(Int, URL)]()

guard let gdtNode = doc.at_xpath("//div [@id='gdt']")
Expand All @@ -420,7 +419,6 @@ struct Parser {
}

static func parseMangaContent(doc: HTMLDocument, tag: Int) throws -> MangaContent {
copyHTMLIfNeeded(html: doc.toHTML)
guard let i3Node = doc.at_xpath("//div [@id='i3']"),
let imageURL = i3Node.at_css("img")?["src"]
else { throw AppError.parseFailed }
Expand All @@ -433,13 +431,8 @@ struct Parser {
let gdo4Node = gdoNode.at_xpath("//div [@id='gdo4']")
else { return "gdtm" }

for link in gdo4Node.xpath("//div") {
if link.text == "Large",
["tha nosel", "ths nosel"]
.contains(link["class"])
{
return "gdtl"
}
for link in gdo4Node.xpath("//div") where link.text == "Large" {
return link["class"] == "ths nosel" ? "gdtl" : "gdtm"
}
return "gdtm"
}
Expand Down Expand Up @@ -472,8 +465,6 @@ struct Parser {

// MARK: Archive
static func parseMangaArchive(doc: HTMLDocument) throws -> MangaArchive {
copyHTMLIfNeeded(html: doc.toHTML)

guard let node = doc.at_xpath("//table")
else { throw AppError.parseFailed }

Expand Down Expand Up @@ -952,6 +943,28 @@ extension Parser {
}
}

// MARK: Profile
static func parseProfile(doc: HTMLDocument) throws -> (Int?, Bool) {
var profileNotFound = true
var profileValue: Int?

let selector = doc.at_xpath(
"//select [@name='profile_set']"
)
let options = selector?.xpath("//option")

guard let options = options,
options.count >= 1
else { throw AppError.parseFailed }

for link in options where link.text == "EhPanda" {
profileNotFound = false
profileValue = Int(link["value"] ?? "")
}

return (profileValue, profileNotFound)
}

// MARK: CommentContent
static func parseCommentContent(node: XMLElement) -> [CommentContent] {
var contents = [CommentContent]()
Expand Down
17 changes: 7 additions & 10 deletions EhPanda/App/Utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,6 @@ func hideKeyboard() {
)
}

func copyHTMLIfNeeded(html: String?) {
if isDebugModeOn, let value = html {
saveToPasteboard(value: value)
}
}

func dispatchMainSync(execute work: () -> Void) {
if Thread.isMainThread {
work()
Expand Down Expand Up @@ -278,10 +272,6 @@ var pasteboardChangeCount: Int? {
UserDefaults.standard.integer(forKey: "PasteboardChangeCount")
}

func setDebugMode(with debugModeOn: Bool) {
UserDefaults.standard.set(debugModeOn, forKey: "debugModeOn")
}

func setGalleryHost(with host: GalleryHost) {
UserDefaults.standard.set(host.rawValue, forKey: "GalleryHost")
}
Expand Down Expand Up @@ -315,6 +305,13 @@ func postDetailViewOnDisappearNotification() {
)
}

func postBypassSNIFilteringDidChangeNotification() {
NotificationCenter.default.post(
name: NSNotification.Name("BypassSNIFilteringDidChange"),
object: nil
)
}

// MARK: Storage Management
func readableUnit<I: BinaryInteger>(bytes: I) -> String {
let formatter = ByteCountFormatter()
Expand Down
3 changes: 3 additions & 0 deletions EhPanda/DataFlow/AppAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ enum AppAction {
case fetchMoreMangaContents(gid: String)
case fetchMoreMangaContentsDone(result: Result<(Identity, PageNumber, [MangaContent]), AppError>)

case createProfile
case verifyProfile
case verifyProfileDone(result: Result<(Int?, Bool), AppError>)
case addFavorite(gid: String, favIndex: Int)
case deleteFavorite(gid: String)
case rate(gid: String, rating: Int)
Expand Down
Loading

0 comments on commit 1c91494

Please sign in to comment.