Protect thumbnail upload, remove unused function

This commit is contained in:
Christoph Hagen 2023-01-15 16:45:27 +01:00
parent 267a71d78c
commit f956b8b4d2
2 changed files with 2 additions and 13 deletions

View File

@ -246,19 +246,6 @@ final class CapServer: ServerOwner {
}
// MARK: Counts
private func updateCounts() throws {
do {
caps = try caps.mapValues {
var cap = $0
cap.count = try count(of: $0.id)
return cap
}
} catch {
log("Failed to update counts: \(error)")
throw error
}
}
private func images(in folder: URL) throws -> [URL] {
try fm.contentsOfDirectory(at: folder, includingPropertiesForKeys: nil)

View File

@ -84,11 +84,13 @@ func routes(_ app: Application) {
return missingThumbnails.map(String.init).joined(separator: ",")
}
// Upload the thumbnail of a cap
app.postCatching("thumbnails", ":cap") { request in
guard let cap = request.parameters.get("cap", as: Int.self) else {
log("Invalid cap parameter for thumbnail upload")
throw Abort(.badRequest)
}
try authorize(request)
let data = try request.getBodyData()
server.saveThumbnail(data, for: cap)
}