Skip to content
This repository was archived by the owner on Sep 22, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions Sources/Server/Controllers/AnalyticsEntryController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,34 @@ struct AnalyticsEntryController: RouteCollection {
}

private func read(_ request: Request) async throws -> AnalyticsEntry {
let entry = try await AnalyticsEntry.find(
request.parameters.get("id"),
on: request.db(.psql)
)
guard let entry else {
throw Abort(.notFound)

// decode retrieval request

let retrievalRequest = try request.query.decode(AnalyticsEntry.RetrievalRequest.self)

guard let idString = request.parameters.get("id"), let id = UUID(uuidString: idString) else {
throw Abort(.badRequest)
}

// cryptogrpahic verification
guard let data = id.uuidString.data(using: .utf8) else {
throw Abort(.internalServerError)
}

// crytographic signature
if try CryptographyUtilities.verify(signature: retrievalRequest.signature, of: data) {
let entry = try await AnalyticsEntry.find(
id,
on: request.db(.psql)
)
guard let entry else {
throw Abort(.notFound)
}
return entry
} else {
throw Abort(.forbidden)
}
return entry
}

}