Compare commits
2 Commits
6e5cc06d31
...
e7a54ec8ec
Author | SHA1 | Date | |
---|---|---|---|
|
e7a54ec8ec | ||
|
b094762297 |
@ -120,6 +120,19 @@ extension CapServer {
|
|||||||
}
|
}
|
||||||
return try encoder.encode(cap)
|
return try encoder.encode(cap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete a cap completely, with all images
|
||||||
|
app.postCatching("delete", ":cap") { request in
|
||||||
|
guard let cap = request.parameters.get("cap", as: Int.self) else {
|
||||||
|
log("/delete/:cap/: Invalid 'cap' parameter for image deletion")
|
||||||
|
throw Abort(.badRequest)
|
||||||
|
}
|
||||||
|
try self.ensureOperability()
|
||||||
|
try authenticator.authorize(request)
|
||||||
|
guard self.delete(cap: cap) else {
|
||||||
|
throw Abort(.gone)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,9 +358,10 @@ final class CapServer {
|
|||||||
log("Failed to write image \(id) for cap \(cap): \(error)")
|
log("Failed to write image \(id) for cap \(cap): \(error)")
|
||||||
throw CapError.invalidFile
|
throw CapError.invalidFile
|
||||||
}
|
}
|
||||||
caps[cap]!.count = try count(of: cap)
|
let count = try count(of: cap)
|
||||||
|
caps[cap]!.count = count
|
||||||
addChangedImageToLog(cap: cap, image: id)
|
addChangedImageToLog(cap: cap, image: id)
|
||||||
log("Added image \(id) for cap \(cap)")
|
log("Added image \(id) for cap \(cap) (\(count) total)")
|
||||||
}
|
}
|
||||||
|
|
||||||
private func writeChangedImagesToDisk() throws {
|
private func writeChangedImagesToDisk() throws {
|
||||||
@ -504,6 +505,39 @@ final class CapServer {
|
|||||||
organizeImages(for: cap)
|
organizeImages(for: cap)
|
||||||
return caps[capId]!
|
return caps[capId]!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func delete(cap capId: Int) -> Bool {
|
||||||
|
guard caps[capId] != nil else {
|
||||||
|
log("Attempting to delete unknown cap \(capId)")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// 1. Remove all images
|
||||||
|
do {
|
||||||
|
let imageFolderUrl = folder(of: capId)
|
||||||
|
if exists(imageFolderUrl) {
|
||||||
|
try fm.removeItem(at: imageFolderUrl)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
log("Failed to delete image folder of cap \(capId): \(error)")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// 2. Remove thumbnail
|
||||||
|
do {
|
||||||
|
let url = thumbnail(of: capId)
|
||||||
|
if exists(url) {
|
||||||
|
try fm.removeItem(at: url)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
log("Failed to delete thumbnail of cap \(capId): \(error)")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Remove cap
|
||||||
|
caps[capId] = nil
|
||||||
|
saveCapCountHTML()
|
||||||
|
updateGridCapCount()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Classifier
|
// MARK: Classifier
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user