mirror of
https://github.com/yattee/yattee.git
synced 2025-08-06 10:44:06 +00:00
Improve validation
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
@@ -27,7 +27,9 @@ final class InstancesModel: ObservableObject {
|
||||
}
|
||||
|
||||
static func add(app: VideosApp, name: String, url: String) -> Instance {
|
||||
let instance = Instance(app: app, id: UUID().uuidString, name: name, apiURL: url)
|
||||
let instance = Instance(
|
||||
app: app, id: UUID().uuidString, name: name, apiURL: standardizedURL(url)
|
||||
)
|
||||
Defaults[.instances].append(instance)
|
||||
|
||||
return instance
|
||||
@@ -36,7 +38,7 @@ final class InstancesModel: ObservableObject {
|
||||
static func setFrontendURL(_ instance: Instance, _ url: String) {
|
||||
if let index = Defaults[.instances].firstIndex(where: { $0.id == instance.id }) {
|
||||
var instance = Defaults[.instances][index]
|
||||
instance.frontendURL = url
|
||||
instance.frontendURL = standardizedURL(url)
|
||||
|
||||
Defaults[.instances][index] = instance
|
||||
}
|
||||
@@ -49,4 +51,12 @@ final class InstancesModel: ObservableObject {
|
||||
accounts.forEach { AccountsModel.remove($0) }
|
||||
}
|
||||
}
|
||||
|
||||
static func standardizedURL(_ url: String) -> String {
|
||||
if url.last == "/" {
|
||||
return String(url.dropLast())
|
||||
} else {
|
||||
return url
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user