Skip to content

Commit

Permalink
Merge pull request #139 from tatsuz0u/develop
Browse files Browse the repository at this point in the history
IP address banned alert
  • Loading branch information
tatsuz0u authored Sep 19, 2021
2 parents 34791a2 + 6afae10 commit dc17d1e
Show file tree
Hide file tree
Showing 22 changed files with 489 additions and 289 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
types: [closed]
env:
DEVELOPER_DIR: /Applications/Xcode_13.0.app
APP_VERSION: '1.1.2'
APP_VERSION: '1.2.0'
SCHEME_NAME: 'EhPanda'
ALTSTORE_JSON_PATH: './AltStore.json'
FILTER_PATH: './ReleaseNotesFilter'
Expand Down
4 changes: 4 additions & 0 deletions EhPanda.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
ABBC332826BE31AE0084A331 /* EhSettingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABBC332726BE31AE0084A331 /* EhSettingView.swift */; };
ABBC332A26BE7C940084A331 /* SettingTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABBC332926BE7C940084A331 /* SettingTextField.swift */; };
ABBCCC9026C95F6E007D8A36 /* GalleryInfosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABBCCC8F26C95F6E007D8A36 /* GalleryInfosView.swift */; };
ABC0A8D126F7037F008EC24C /* IPBanned.html in Resources */ = {isa = PBXBuildFile; fileRef = ABC0A8D026F7037F008EC24C /* IPBanned.html */; };
ABC1FAB6264152C800A9F352 /* StoreAccessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC1FAB5264152C800A9F352 /* StoreAccessor.swift */; };
ABC1FAB82642C37D00A9F352 /* NewDawnView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC1FAB72642C37D00A9F352 /* NewDawnView.swift */; };
ABC3C7852593699B00E0C11B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ABC3C7692593699A00E0C11B /* Assets.xcassets */; };
Expand Down Expand Up @@ -212,6 +213,7 @@
ABBC332726BE31AE0084A331 /* EhSettingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EhSettingView.swift; sourceTree = "<group>"; };
ABBC332926BE7C940084A331 /* SettingTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingTextField.swift; sourceTree = "<group>"; };
ABBCCC8F26C95F6E007D8A36 /* GalleryInfosView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GalleryInfosView.swift; sourceTree = "<group>"; };
ABC0A8D026F7037F008EC24C /* IPBanned.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = IPBanned.html; sourceTree = "<group>"; };
ABC1FAB5264152C800A9F352 /* StoreAccessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreAccessor.swift; sourceTree = "<group>"; };
ABC1FAB72642C37D00A9F352 /* NewDawnView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewDawnView.swift; sourceTree = "<group>"; };
ABC3C7542593696C00E0C11B /* EhPanda.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = EhPanda.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -332,6 +334,7 @@
AB3E9E6326D210B1008FE518 /* Parser */ = {
isa = PBXGroup;
children = (
ABC0A8D026F7037F008EC24C /* IPBanned.html */,
AB3E9E6426D210B1008FE518 /* Gallery */,
AB3E9E6626D210B1008FE518 /* List */,
);
Expand Down Expand Up @@ -786,6 +789,7 @@
buildActionMask = 2147483647;
files = (
AB3E9E6F26D210B1008FE518 /* Favorites.html in Resources */,
ABC0A8D126F7037F008EC24C /* IPBanned.html in Resources */,
ABF9720A26DE6E1300118887 /* GalleryDetailWithGreeting.html in Resources */,
AB3E9E6E26D210B1008FE518 /* GalleryDetail.html in Resources */,
AB30E34826D277F7007420BC /* Toplists.html in Resources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"repositoryURL": "https://github.com/tatsuz0u/Kingfisher.git",
"state": {
"branch": "fix/binder-loaded",
"revision": "37c6740f5d6433309f813f5a99300710becfb51f",
"revision": "31268315fed1d0f5846a592deab3b3959751e482",
"version": null
}
},
Expand All @@ -51,7 +51,7 @@
"repositoryURL": "https://github.com/SwiftyBeaver/SwiftyBeaver.git",
"state": {
"branch": "master",
"revision": "607fc8d64388652135f4dcf6a1a340e3a0641088",
"revision": "2a2e1552c41d2e82b86f5822a95a03d0587e0683",
"version": null
}
},
Expand All @@ -69,7 +69,7 @@
"repositoryURL": "https://github.com/tatsuz0u/TTProgressHUD.git",
"state": {
"branch": "master",
"revision": "1caaa9cb7d53e3224fe61bbf1b02e88eefa5aae9",
"revision": "1d6360603a1f3d7b8dac9ecd46f3ed504d19c2bd",
"version": null
}
},
Expand Down
12 changes: 12 additions & 0 deletions EhPanda/App/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ extension Data {
func toObject<O: Decodable>() -> O? {
try? JSONDecoder().decode(O.self, from: self)
}
var utf8InvalidCharactersRipped: Data {
var data = self
data.append(0)

let str = Array(self).withUnsafeBufferPointer { ptr -> String? in
guard let address = ptr.baseAddress else { return nil }
return String(cString: address)
}
guard let string = str else { return data }
data = string.data(using: .utf8) ?? self
return data
}
}

extension Float {
Expand Down
66 changes: 62 additions & 4 deletions EhPanda/App/Tools/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import Kanna
import UIKit
import Foundation
import SwiftUI
import SwiftyBeaver

struct Parser {
// MARK: List
static func parseListItems(doc: HTMLDocument) -> [Gallery] {
static func parseListItems(doc: HTMLDocument) throws -> [Gallery] {
func parseCoverURL(node: XMLElement?) throws -> String {
guard let node = node?.at_xpath("//div [@class='glthumb']")?.at_css("img")
else { throw AppError.parseFailed }
Expand Down Expand Up @@ -128,6 +129,10 @@ struct Parser {
)
}

if galleryItems.isEmpty, let banInterval = parseBanInterval(doc: doc) {
throw AppError.ipBanned(interval: banInterval)
}

return galleryItems
}

Expand Down Expand Up @@ -255,9 +260,11 @@ struct Parser {
infoPanel[2] = gdt2Text
}
if gdt1Text.contains("Language") {
infoPanel[3] = gdt2Text
.replacingOccurrences(of: "  TR", with: "")
.trimmingCharacters(in: .whitespaces)
let words = gdt2Text.split(separator: " ")
if !words.isEmpty {
infoPanel[3] = words[0]
.trimmingCharacters(in: .whitespaces)
}
}
if gdt1Text.contains("File Size") {
infoPanel[4] = gdt2Text
Expand Down Expand Up @@ -376,6 +383,8 @@ struct Parser {
} else {
throw AppError.expunged(reason: reason)
}
} else if let banInterval = parseBanInterval(doc: doc) {
throw AppError.ipBanned(interval: banInterval)
} else {
throw AppError.parseFailed
}
Expand Down Expand Up @@ -1506,4 +1515,53 @@ extension Parser {

return (rippedText, wrappedHex)
}

// MARK: parseBanInterval
static func parseBanInterval(doc: HTMLDocument) -> BanInterval? {
guard let text = doc.body?.text, let range = text.range(of: "The ban expires in ")
else { return nil }

let expireDescription = String(text[range.upperBound...])
guard let andRange = expireDescription.range(of: "and") else {
SwiftyBeaver.error(
"Unrecognized BanInterval format", context: [
"expireDescription": expireDescription
]
)
return .unrecognized(content: expireDescription)
}

if let daysRange = expireDescription.range(of: "days"),
let hoursRange = expireDescription.range(of: "hours"),
let days = Int(expireDescription[..<daysRange.lowerBound]
.trimmingCharacters(in: .whitespaces)),
let hours = Int(expireDescription[andRange.upperBound..<hoursRange.lowerBound]
.trimmingCharacters(in: .whitespaces))
{
return .days(days, hours: hours)
} else if let hoursRange = expireDescription.range(of: "hours"),
let minutesRange = expireDescription.range(of: "minutes"),
let hours = Int(expireDescription[..<hoursRange.lowerBound]
.trimmingCharacters(in: .whitespaces)),
let minutes = Int(expireDescription[andRange.upperBound..<minutesRange.lowerBound]
.trimmingCharacters(in: .whitespaces))
{
return .hours(hours, minutes: minutes)
} else if let minutesRange = expireDescription.range(of: "minutes"),
let secondsRange = expireDescription.range(of: "seconds"),
let minutes = Int(expireDescription[..<minutesRange.lowerBound]
.trimmingCharacters(in: .whitespaces)),
let seconds = Int(expireDescription[andRange.upperBound..<secondsRange.lowerBound]
.trimmingCharacters(in: .whitespaces))
{
return .minutes(minutes, seconds: seconds)
} else {
SwiftyBeaver.error(
"Unrecognized BanInterval format", context: [
"expireDescription": expireDescription
]
)
return .unrecognized(content: expireDescription)
}
}
}
8 changes: 8 additions & 0 deletions EhPanda/App/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@
//"A parsing error occurred." = "";
//"An unknown error occurred." = "";
//"Please try again later." = "";
//"This gallery has been removed or is unavailable." = "";
//"This gallery is unavailable due to a copyright claim by PLACEHOLDER. Sorry about that." = "";
//"Your IP address has been temporarily banned for excessive pageloads which indicates that you are using automated mirroring / harvesting software." = "";
//"The ban expires in PLACEHOLDER." = "";
//"BAN_INTERVAL_AND" = "";
//"BAN_INTERVAL_DAYS" = "";
//"BAN_INTERVAL_HOURS" = "";
//"BAN_INTERVAL_MINUTES" = "";
//"BAN_INTERVAL_SECONDS" = "";

// MARK: DetailView
"Archive" = "Archiv";
Expand Down
7 changes: 7 additions & 0 deletions EhPanda/App/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@

// MARK: EhSettingView
"LOAD_THROUGH_HATH_NO" = "No";

// MARK: AlertView
"BAN_INTERVAL_AND" = " and ";
"BAN_INTERVAL_DAYS" = " days";
"BAN_INTERVAL_HOURS" = " hours";
"BAN_INTERVAL_MINUTES" = " minutes";
"BAN_INTERVAL_SECONDS" = " seconds";
Loading

0 comments on commit dc17d1e

Please sign in to comment.