1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
enum BooruProvider: CaseIterable, Codable, Hashable, Equatable {
case custom(BooruProviderCustom)
case danbooru
case gelbooru
case konachan
case safebooru
case sakugabooru
case yandere
// MARK: - Computed Properties
var domain: String {
switch self {
case .custom(let provider):
provider.self.domain
default:
Self.domains[self] ?? rawValue.lowercased()
}
}
var asFileNameComponent: String {
rawValue.lowercased().replacingOccurrences(of: ".", with: "_")
}
static var allCases: [Self] {
[.danbooru, .gelbooru, .konachan, .safebooru, .sakugabooru, .yandere]
}
static func == (lhs: Self, rhs: Self) -> Bool {
lhs.rawValue == rhs.rawValue
}
var rawValue: String {
switch self {
case .danbooru:
"Danbooru"
case .gelbooru:
"Gelbooru"
case .konachan:
"Konachan.com"
case .safebooru:
"Safebooru"
case .sakugabooru:
"sakugabooru.com"
case .yandere:
"yande.re"
case .custom(let provider):
provider.domain
}
}
// MARK: - Private
private static let domains: [Self: String] = [
.yandere: "yande.re",
.konachan: "konachan.com",
.sakugabooru: "sakugabooru.com",
.safebooru: "safebooru.org",
.gelbooru: "gelbooru.com",
.danbooru: "danbooru.donmai.us",
]
}
|