Supports downloading apps from locked Patreon posts

Uses cached Patreon session cookies to access post attachments despite no official API support.
This commit is contained in:
Riley Testut
2023-11-30 14:28:57 -06:00
parent d9ebd21541
commit bd0220ea35
7 changed files with 258 additions and 20 deletions

View File

@@ -36,6 +36,10 @@ extension OperationError
case serverNotFound = 1200
case connectionFailed = 1201
case connectionDropped = 1202
/* Pledges */
case pledgeRequired = 1401
case pledgeInactive = 1402
}
static var cancelled: CancellationError { CancellationError() }
@@ -67,6 +71,14 @@ extension OperationError
static func forbidden(failureReason: String? = nil, file: String = #fileID, line: UInt = #line) -> OperationError {
OperationError(code: .forbidden, failureReason: failureReason, sourceFile: file, sourceLine: line)
}
static func pledgeRequired(appName: String, file: String = #fileID, line: UInt = #line) -> OperationError {
OperationError(code: .pledgeRequired, appName: appName, sourceFile: file, sourceLine: line)
}
static func pledgeInactive(appName: String, file: String = #fileID, line: UInt = #line) -> OperationError {
OperationError(code: .pledgeInactive, appName: appName, sourceFile: file, sourceLine: line)
}
}
struct OperationError: ALTLocalizedError
@@ -132,6 +144,14 @@ struct OperationError: ALTLocalizedError
case .serverNotFound: return NSLocalizedString("AltServer could not be found.", comment: "")
case .connectionFailed: return NSLocalizedString("A connection to AltServer could not be established.", comment: "")
case .connectionDropped: return NSLocalizedString("The connection to AltServer was dropped.", comment: "")
case .pledgeRequired:
let appName = self.appName ?? NSLocalizedString("This app", comment: "")
return String(format: NSLocalizedString("%@ requires an active pledge in order to be installed.", comment: ""), appName)
case .pledgeInactive:
let appName = self.appName ?? NSLocalizedString("this app", comment: "")
return String(format: NSLocalizedString("Your pledge is no longer active. Please renew it to continue using %@ normally.", comment: ""), appName)
}
}
private var _failureReason: String?