Fix counts on upload
This commit is contained in:
parent
23692377e8
commit
2860b5c3fc
@ -176,7 +176,7 @@ final class CapServer {
|
||||
f = file(of: cap, version: id)
|
||||
}
|
||||
try data.write(to: f)
|
||||
caps[cap]!.count += 1
|
||||
caps[cap]!.count = try count(of: cap)
|
||||
log("Added image \(id) for cap \(cap)")
|
||||
}
|
||||
|
||||
@ -192,21 +192,23 @@ final class CapServer {
|
||||
|
||||
func addOrUpdate(_ cap: Cap) throws {
|
||||
if let existingCap = caps[cap.id] {
|
||||
try update(existingCap, with: cap)
|
||||
update(existingCap, with: cap)
|
||||
} else {
|
||||
try add(cap)
|
||||
}
|
||||
}
|
||||
|
||||
private func add(_ cap: Cap) throws {
|
||||
guard cap.mainImage == 0, cap.count == 0 else {
|
||||
guard cap.mainImage == 0 else {
|
||||
throw CapError.invalidData
|
||||
}
|
||||
var cap = cap
|
||||
cap.count = 0
|
||||
caps[cap.id] = cap
|
||||
log("Added cap \(cap.id) '\(cap.name)'")
|
||||
}
|
||||
|
||||
private func update(_ existingCap: Cap, with cap: Cap) throws {
|
||||
private func update(_ existingCap: Cap, with cap: Cap) {
|
||||
var updatedCap = existingCap
|
||||
if cap.name != "" {
|
||||
updatedCap.name = cap.name
|
||||
|
Loading…
Reference in New Issue
Block a user