Add view of all images for a cap
This commit is contained in:
@@ -24,12 +24,20 @@ struct Cap {
|
||||
|
||||
/// The subpath to the main image on the server
|
||||
var mainImagePath: String {
|
||||
String(format: "images/%04d/%04d-%02d.jpg", id, id, mainImage)
|
||||
imagePath(version: mainImage)
|
||||
}
|
||||
|
||||
func imagePath(version: Int) -> String {
|
||||
String(format: "images/%04d/%04d-%02d.jpg", id, id, version)
|
||||
}
|
||||
|
||||
var image: CapImage {
|
||||
.init(cap: id, version: mainImage)
|
||||
}
|
||||
|
||||
func image(version: Int) -> CapImage {
|
||||
.init(cap: id, version: version)
|
||||
}
|
||||
|
||||
/**
|
||||
Create a new cap.
|
||||
|
||||
@@ -6,3 +6,8 @@ struct CapImage: Codable, Equatable, Hashable {
|
||||
|
||||
let version: Int
|
||||
}
|
||||
|
||||
extension CapImage: Identifiable {
|
||||
|
||||
var id: Int { version }
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ final class Database: ObservableObject {
|
||||
|
||||
@discardableResult
|
||||
func downloadCaps() async -> Bool {
|
||||
print("Downloading cap data")
|
||||
print("Downloading cap data from \(serverDbUrl)")
|
||||
let data: Data
|
||||
let response: URLResponse
|
||||
do {
|
||||
@@ -250,7 +250,11 @@ final class Database: ObservableObject {
|
||||
print("Failed to download classifier version: \(error)")
|
||||
return false
|
||||
}
|
||||
guard (response as? HTTPURLResponse)?.statusCode == 200 else {
|
||||
guard let httpResponse = response as? HTTPURLResponse else {
|
||||
return false
|
||||
}
|
||||
guard httpResponse.statusCode == 200 else {
|
||||
print("Failed to download caps: \(httpResponse.statusCode)")
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -261,6 +265,7 @@ final class Database: ObservableObject {
|
||||
print("Failed to decode server database: \(error)")
|
||||
return false
|
||||
}
|
||||
print("Downloaded \(capData) caps")
|
||||
var inserts = 0
|
||||
var updates = 0
|
||||
for cap in capData {
|
||||
@@ -358,6 +363,10 @@ final class Database: ObservableObject {
|
||||
func hasPendingOperations(for cap: Int) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func cap(for id: Int) -> Cap? {
|
||||
caps[id]
|
||||
}
|
||||
|
||||
// MARK: Adding new data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user