Skip to content

Commit 1c91494

Browse files
author
たつぞう
committed
Merge branch 'develop'
2 parents 12f15e1 + 5d0b343 commit 1c91494

File tree

17 files changed

+360
-225
lines changed

17 files changed

+360
-225
lines changed

EhPanda.xcodeproj/project.pbxproj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
AB358315269D821D009466A5 /* DFExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB358314269D821D009466A5 /* DFExtensions.swift */; };
1818
AB358317269D826B009466A5 /* DFStreamHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB358316269D826B009466A5 /* DFStreamHandler.swift */; };
1919
AB358319269D9996009466A5 /* DomainResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB358318269D9996009466A5 /* DomainResolver.swift */; };
20-
AB35831B269DADE7009466A5 /* DFManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB35831A269DADE7009466A5 /* DFManager.swift */; };
2120
AB38A0CB25CA993D00764D64 /* ColorCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB38A0CA25CA993D00764D64 /* ColorCodable.swift */; };
2221
AB47FD9F25BC81A40007765D /* Normal@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = AB47FD9925BC81A40007765D /* Normal@3x.png */; };
2322
AB47FDA025BC81A40007765D /* Normal@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = AB47FD9A25BC81A40007765D /* Normal@2x.png */; };
@@ -101,7 +100,6 @@
101100
AB358314269D821D009466A5 /* DFExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFExtensions.swift; sourceTree = "<group>"; };
102101
AB358316269D826B009466A5 /* DFStreamHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFStreamHandler.swift; sourceTree = "<group>"; };
103102
AB358318269D9996009466A5 /* DomainResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainResolver.swift; sourceTree = "<group>"; };
104-
AB35831A269DADE7009466A5 /* DFManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFManager.swift; sourceTree = "<group>"; };
105103
AB38A0CA25CA993D00764D64 /* ColorCodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorCodable.swift; sourceTree = "<group>"; };
106104
AB47FD9925BC81A40007765D /* Normal@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Normal@3x.png"; sourceTree = "<group>"; };
107105
AB47FD9A25BC81A40007765D /* Normal@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Normal@2x.png"; sourceTree = "<group>"; };
@@ -299,7 +297,6 @@
299297
children = (
300298
ABCD2F09259763FC008E5A20 /* Request.swift */,
301299
AB358318269D9996009466A5 /* DomainResolver.swift */,
302-
AB35831A269DADE7009466A5 /* DFManager.swift */,
303300
AB358312269D7E89009466A5 /* DFRequest.swift */,
304301
AB358316269D826B009466A5 /* DFStreamHandler.swift */,
305302
AB358314269D821D009466A5 /* DFExtensions.swift */,
@@ -574,7 +571,6 @@
574571
ABF45ABA25F3312F00ECB568 /* AppCommand.swift in Sources */,
575572
ABF45AE425F3313D00ECB568 /* TagCloudView.swift in Sources */,
576573
ABCA93C22691929D00A98BC6 /* MangaDetailMO+CoreDataClass.swift in Sources */,
577-
AB35831B269DADE7009466A5 /* DFManager.swift in Sources */,
578574
ABF45AEE25F3313D00ECB568 /* ArchiveView.swift in Sources */,
579575
ABF45AEC25F3313D00ECB568 /* ContentView.swift in Sources */,
580576
ABEA1FE625A9B40B002966B9 /* Setting.swift in Sources */,
@@ -751,7 +747,7 @@
751747
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
752748
CODE_SIGN_ENTITLEMENTS = EhPanda/EhPanda.entitlements;
753749
CODE_SIGN_STYLE = Automatic;
754-
CURRENT_PROJECT_VERSION = 60;
750+
CURRENT_PROJECT_VERSION = 61;
755751
DEVELOPMENT_ASSET_PATHS = "";
756752
DEVELOPMENT_TEAM = 9SKQ7QTZ74;
757753
ENABLE_PREVIEWS = YES;
@@ -778,7 +774,7 @@
778774
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
779775
CODE_SIGN_ENTITLEMENTS = EhPanda/EhPanda.entitlements;
780776
CODE_SIGN_STYLE = Automatic;
781-
CURRENT_PROJECT_VERSION = 60;
777+
CURRENT_PROJECT_VERSION = 61;
782778
DEVELOPMENT_ASSET_PATHS = "";
783779
DEVELOPMENT_TEAM = 9SKQ7QTZ74;
784780
ENABLE_PREVIEWS = YES;

EhPanda/App/Defaults.swift

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ extension Defaults.URL {
126126
// Fetch
127127
static func searchList(keyword: String, filter: Filter) -> String {
128128
merge(urls: [
129-
host,
130-
listCompact,
131-
fSearch + keyword.urlEncoded()
129+
host, fSearch
130+
+ keyword.urlEncoded()
132131
]
133132
+ applyFilters(filter: filter)
134133
)
@@ -142,7 +141,6 @@ extension Defaults.URL {
142141
merge(
143142
urls: [
144143
host,
145-
listCompact,
146144
fSearch + keyword.urlEncoded(),
147145
page + pageNum,
148146
from + lastID
@@ -151,25 +149,25 @@ extension Defaults.URL {
151149
)
152150
}
153151
static func frontpageList() -> String {
154-
merge(urls: [host, listCompact])
152+
host
155153
}
156154
static func moreFrontpageList(pageNum: String, lastID: String) -> String {
157-
merge(urls: [host, listCompact, page + pageNum, from + lastID])
155+
merge(urls: [host, page + pageNum, from + lastID])
158156
}
159157
static func popularList() -> String {
160-
merge(urls: [host + popular, listCompact])
158+
host + popular
161159
}
162160
static func watchedList() -> String {
163-
merge(urls: [host + watched, listCompact])
161+
host + watched
164162
}
165163
static func moreWatchedList(pageNum: String, lastID: String) -> String {
166164
merge(urls: [host + watched, page + pageNum, from + lastID])
167165
}
168166
static func favoritesList(favIndex: Int) -> String {
169167
if favIndex == -1 {
170-
return merge(urls: [host + favorites, listCompact])
168+
return host + favorites
171169
} else {
172-
return merge(urls: [host + favorites, favcat + "\(favIndex)", listCompact])
170+
return merge(urls: [host + favorites, favcat + "\(favIndex)"])
173171
}
174172
}
175173
static func moreFavoritesList(favIndex: Int, pageNum: String, lastID: String) -> String {
@@ -180,7 +178,7 @@ extension Defaults.URL {
180178
}
181179
}
182180
static func mangaDetail(url: String) -> String {
183-
merge(urls: [url, ignoreOffensive, showComments, previewLarge])
181+
merge(urls: [url, showComments])
184182
}
185183
static func mangaTorrents(gid: String, token: String) -> String {
186184
merge(urls: [host + gallerytorrents, Defaults.URL.gid + gid, Defaults.URL.token + token])
@@ -196,7 +194,7 @@ extension Defaults.URL {
196194
merge(keyword: keyword, pageNum: nil, lastID: nil)
197195
}
198196
static func similarGallery(keyword: String) -> String {
199-
merge(urls: [host, listCompact, fSearch + keyword.urlEncoded()])
197+
merge(urls: [host, fSearch + keyword.urlEncoded()])
200198
}
201199
static func moreAssociatedItemsRedir(keyword: AssociatedKeyword, lastID: String, pageNum: String) -> String {
202200
if let title = keyword.title {
@@ -214,14 +212,13 @@ extension Defaults.URL {
214212
static func moreSimilarGallery(keyword: String, pageNum: String, lastID: String) -> String {
215213
merge(urls: [
216214
host,
217-
listCompact,
218215
fSearch + keyword.urlEncoded(),
219216
page + pageNum,
220217
from + lastID
221218
])
222219
}
223220
static func mangaContents(detailURL: String) -> String {
224-
merge(urls: [detailURL, previewLarge, rowsLimit])
221+
detailURL
225222
}
226223

227224
// Account Associated Operations

EhPanda/App/EhPandaApp.swift

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ struct EhPandaApp: App {
1919
.task(onStartTasks)
2020
.environmentObject(store)
2121
.accentColor(accentColor)
22-
.onOpenURL(perform: onOpenURL)
2322
.preferredColorScheme(preferredColorScheme)
2423
}
2524
}
@@ -37,29 +36,42 @@ private extension EhPandaApp {
3736
}
3837

3938
func onStartTasks() {
40-
syncGalleryHost()
41-
configureLogging()
42-
configureWebImage()
43-
configureDomainFronting()
44-
clearImageCachesIfNeeded()
45-
46-
DispatchQueue.main.async {
47-
store.dispatch(.fetchUserInfo)
48-
store.dispatch(.fetchFavoriteNames)
39+
dispatchMainSync {
40+
syncGalleryHost()
41+
configureLogging()
42+
configureWebImage()
43+
configureDomainFronting()
44+
configureIgnoreOffensive()
4945
}
50-
}
51-
func onOpenURL(url: URL) {
52-
switch url.host {
53-
case "debugMode":
54-
setDebugMode(with: url.pathComponents.last == "on")
55-
default:
56-
break
46+
dispatchMainAsync {
47+
fetchAccountInfoIfNeeded()
48+
clearImageCachesIfNeeded()
5749
}
5850
}
5951

6052
func syncGalleryHost() {
6153
setGalleryHost(with: setting.galleryHost)
6254
}
55+
func fetchAccountInfoIfNeeded() {
56+
guard didLogin else { return }
57+
58+
store.dispatch(.verifyProfile)
59+
store.dispatch(.fetchUserInfo)
60+
store.dispatch(.fetchFavoriteNames)
61+
}
62+
func clearImageCachesIfNeeded() {
63+
let threshold = 200 * 1024 * 1024
64+
65+
KingfisherManager.shared.cache.calculateDiskStorageSize { result in
66+
if case .success(let size) = result, size > threshold {
67+
KingfisherManager.shared.cache.clearDiskCache()
68+
}
69+
}
70+
}
71+
}
72+
73+
// MARK: Configuration
74+
private extension EhPandaApp {
6375
func configureLogging() {
6476
var file = FileDestination()
6577
var console = ConsoleDestination()
@@ -99,27 +111,18 @@ private extension EhPandaApp {
99111
}
100112

101113
func configureWebImage() {
102-
let config = KingfisherManager.shared
103-
.downloader.sessionConfiguration
104-
if setting.bypassSNIFiltering {
105-
config.protocolClasses = [DFURLProtocol.self]
106-
}
114+
let config = KingfisherManager.shared.downloader.sessionConfiguration
107115
config.httpCookieStorage = HTTPCookieStorage.shared
108116
KingfisherManager.shared.downloader.sessionConfiguration = config
109117
}
110118
func configureDomainFronting() {
111-
DFManager.shared.dfState = setting.bypassSNIFiltering
112-
? .activated : .notActivated
113-
}
114-
func clearImageCachesIfNeeded() {
115-
let threshold = 200 * 1024 * 1024
116-
117-
KingfisherManager.shared.cache.calculateDiskStorageSize { result in
118-
if case .success(let size) = result {
119-
if size > threshold {
120-
KingfisherManager.shared.cache.clearDiskCache()
121-
}
122-
}
119+
if setting.bypassSNIFiltering {
120+
URLProtocol.registerClass(DFURLProtocol.self)
121+
URLProtocol.registerWebview(scheme: "https")
123122
}
124123
}
124+
func configureIgnoreOffensive() {
125+
setCookie(url: Defaults.URL.ehentai.safeURL(), key: "nw", value: "1")
126+
setCookie(url: Defaults.URL.exhentai.safeURL(), key: "nw", value: "1")
127+
}
125128
}

EhPanda/App/Extensions.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ extension String {
8585
) ?? ""
8686
}
8787

88+
func urlDecoded() -> String {
89+
(removingPercentEncoding ?? "")
90+
.replacingOccurrences(of: "%3F", with: "?")
91+
}
92+
8893
var withComma: String? {
8994
Int(self)?.formatted(.number)
9095
}

EhPanda/App/Tools/Parser.swift

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ struct Parser {
402402

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

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

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

436-
for link in gdo4Node.xpath("//div") {
437-
if link.text == "Large",
438-
["tha nosel", "ths nosel"]
439-
.contains(link["class"])
440-
{
441-
return "gdtl"
442-
}
434+
for link in gdo4Node.xpath("//div") where link.text == "Large" {
435+
return link["class"] == "ths nosel" ? "gdtl" : "gdtm"
443436
}
444437
return "gdtm"
445438
}
@@ -472,8 +465,6 @@ struct Parser {
472465

473466
// MARK: Archive
474467
static func parseMangaArchive(doc: HTMLDocument) throws -> MangaArchive {
475-
copyHTMLIfNeeded(html: doc.toHTML)
476-
477468
guard let node = doc.at_xpath("//table")
478469
else { throw AppError.parseFailed }
479470

@@ -952,6 +943,28 @@ extension Parser {
952943
}
953944
}
954945

946+
// MARK: Profile
947+
static func parseProfile(doc: HTMLDocument) throws -> (Int?, Bool) {
948+
var profileNotFound = true
949+
var profileValue: Int?
950+
951+
let selector = doc.at_xpath(
952+
"//select [@name='profile_set']"
953+
)
954+
let options = selector?.xpath("//option")
955+
956+
guard let options = options,
957+
options.count >= 1
958+
else { throw AppError.parseFailed }
959+
960+
for link in options where link.text == "EhPanda" {
961+
profileNotFound = false
962+
profileValue = Int(link["value"] ?? "")
963+
}
964+
965+
return (profileValue, profileNotFound)
966+
}
967+
955968
// MARK: CommentContent
956969
static func parseCommentContent(node: XMLElement) -> [CommentContent] {
957970
var contents = [CommentContent]()

EhPanda/App/Utility.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,6 @@ func hideKeyboard() {
227227
)
228228
}
229229

230-
func copyHTMLIfNeeded(html: String?) {
231-
if isDebugModeOn, let value = html {
232-
saveToPasteboard(value: value)
233-
}
234-
}
235-
236230
func dispatchMainSync(execute work: () -> Void) {
237231
if Thread.isMainThread {
238232
work()
@@ -278,10 +272,6 @@ var pasteboardChangeCount: Int? {
278272
UserDefaults.standard.integer(forKey: "PasteboardChangeCount")
279273
}
280274

281-
func setDebugMode(with debugModeOn: Bool) {
282-
UserDefaults.standard.set(debugModeOn, forKey: "debugModeOn")
283-
}
284-
285275
func setGalleryHost(with host: GalleryHost) {
286276
UserDefaults.standard.set(host.rawValue, forKey: "GalleryHost")
287277
}
@@ -315,6 +305,13 @@ func postDetailViewOnDisappearNotification() {
315305
)
316306
}
317307

308+
func postBypassSNIFilteringDidChangeNotification() {
309+
NotificationCenter.default.post(
310+
name: NSNotification.Name("BypassSNIFilteringDidChange"),
311+
object: nil
312+
)
313+
}
314+
318315
// MARK: Storage Management
319316
func readableUnit<I: BinaryInteger>(bytes: I) -> String {
320317
let formatter = ByteCountFormatter()

EhPanda/DataFlow/AppAction.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ enum AppAction {
7878
case fetchMoreMangaContents(gid: String)
7979
case fetchMoreMangaContentsDone(result: Result<(Identity, PageNumber, [MangaContent]), AppError>)
8080

81+
case createProfile
82+
case verifyProfile
83+
case verifyProfileDone(result: Result<(Int?, Bool), AppError>)
8184
case addFavorite(gid: String, favIndex: Int)
8285
case deleteFavorite(gid: String)
8386
case rate(gid: String, rating: Int)

0 commit comments

Comments
 (0)