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

@@ -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
}
}
}