Redirect Rules: implements redirect rules UI

This commit is contained in:
James Magahern
2021-12-14 18:50:33 -08:00
parent 2ac814cd4e
commit 3cedd3f387
7 changed files with 198 additions and 39 deletions

View File

@@ -28,6 +28,19 @@ public struct SettingProperty<T: RawRepresentable>
}
}
extension Dictionary: RawRepresentable where Key == String, Value == String {
public typealias RawValue = [String: String]
public init?(rawValue: [String : String]) {
self.init()
self.merge(rawValue, uniquingKeysWith: { $1 })
}
public var rawValue: [String : String] {
return self
}
}
class Settings
{
static let shared = Settings()
@@ -50,4 +63,18 @@ class Settings
@SettingProperty(key: "searchProvider")
public var searchProvider: SearchProviderSetting = .searxnor
@SettingProperty(key: "redirectRules")
public var redirectRules: [String: String] = [:]
func redirectRule(for url: URL) -> URL? {
if var components = URLComponents(url: url, resolvingAgainstBaseURL: false), let host = url.host {
if let alternateHost = redirectRules[host] {
components.host = alternateHost
return components.url
}
}
return nil
}
}