Improve validation

This commit is contained in:
Arkadiusz Fal
2021-11-07 22:39:28 +01:00
parent 278c4cad69
commit 08d2165bf3
7 changed files with 182 additions and 35 deletions

View File

@@ -53,34 +53,21 @@ final class AccountValidator: Service {
func validateInstance() {
reset()
// TODO: validation for Piped instances
guard app.wrappedValue == .invidious else {
isValid.wrappedValue = true
error?.wrappedValue = nil
isValidated.wrappedValue = true
isValidating.wrappedValue = false
return
}
stats
neverGonnaGiveYouUp
.load()
.onSuccess { response in
guard self.url == self.formObjectID.wrappedValue else {
return
}
if response
.json
.dictionaryValue["software"]?
.dictionaryValue["name"]?
.stringValue == "invidious"
{
let json = response.json.dictionaryValue
let author = self.app.wrappedValue == .invidious ? json["author"] : json["uploader"]
if author == "Rick Astley" {
self.isValid.wrappedValue = true
self.error?.wrappedValue = nil
} else {
self.isValid.wrappedValue = false
self.error?.wrappedValue = "Not an Invidious Instance"
}
}
.onFailure { error in
@@ -133,11 +120,15 @@ final class AccountValidator: Service {
"SID=\(account!.sid)"
}
var stats: Resource {
resource("/api/v1/stats")
}
var feed: Resource {
resource("/api/v1/auth/feed")
}
var videoResourceBasePath: String {
app.wrappedValue == .invidious ? "/api/v1/videos" : "/streams"
}
var neverGonnaGiveYouUp: Resource {
resource("\(videoResourceBasePath)/dQw4w9WgXcQ")
}
}