Protect thumbnail upload, remove unused function
This commit is contained in:
parent
267a71d78c
commit
f956b8b4d2
@ -246,19 +246,6 @@ final class CapServer: ServerOwner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Counts
|
// 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] {
|
private func images(in folder: URL) throws -> [URL] {
|
||||||
try fm.contentsOfDirectory(at: folder, includingPropertiesForKeys: nil)
|
try fm.contentsOfDirectory(at: folder, includingPropertiesForKeys: nil)
|
||||||
|
@ -84,11 +84,13 @@ func routes(_ app: Application) {
|
|||||||
return missingThumbnails.map(String.init).joined(separator: ",")
|
return missingThumbnails.map(String.init).joined(separator: ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Upload the thumbnail of a cap
|
||||||
app.postCatching("thumbnails", ":cap") { request in
|
app.postCatching("thumbnails", ":cap") { request in
|
||||||
guard let cap = request.parameters.get("cap", as: Int.self) else {
|
guard let cap = request.parameters.get("cap", as: Int.self) else {
|
||||||
log("Invalid cap parameter for thumbnail upload")
|
log("Invalid cap parameter for thumbnail upload")
|
||||||
throw Abort(.badRequest)
|
throw Abort(.badRequest)
|
||||||
}
|
}
|
||||||
|
try authorize(request)
|
||||||
let data = try request.getBodyData()
|
let data = try request.getBodyData()
|
||||||
server.saveThumbnail(data, for: cap)
|
server.saveThumbnail(data, for: cap)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user