impl heartbeat
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import Vapor
|
import Vapor
|
||||||
|
import JWT
|
||||||
|
|
||||||
struct OpenApiController: RouteCollection {
|
struct OpenApiController: RouteCollection {
|
||||||
func boot(routes: any RoutesBuilder) throws {
|
func boot(routes: any RoutesBuilder) throws {
|
||||||
@@ -10,5 +11,33 @@ struct OpenApiController: RouteCollection {
|
|||||||
req.logger.log(level: .debug, .init(stringLiteral: req.body.string ?? ""))
|
req.logger.log(level: .debug, .init(stringLiteral: req.body.string ?? ""))
|
||||||
return Response()
|
return Response()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group.post("v3", "player", "heartbeat") { req in
|
||||||
|
let beat = try req.content.decode(Heartbeat.self, as: .json)
|
||||||
|
guard let zatToken = req.headers["zat"].first else {
|
||||||
|
throw Abort(.badRequest, reason: "Missing zat header.")
|
||||||
|
}
|
||||||
|
let jwt = try await req.jwt.verify(zatToken, as: SessionPayload.self)
|
||||||
|
guard jwt.accountId.value == beat.playerId else {
|
||||||
|
throw Abort(.unauthorized, reason: "zat invalid")
|
||||||
|
}
|
||||||
|
return "{}"
|
||||||
|
}
|
||||||
|
|
||||||
|
group.post("v3", "push", "token", "register") { req in
|
||||||
|
let beat = try req.content.decode(Heartbeat.self, as: .json)
|
||||||
|
guard let zatToken = req.headers["zat"].first else {
|
||||||
|
throw Abort(.badRequest, reason: "Missing zat header.")
|
||||||
|
}
|
||||||
|
let jwt = try await req.jwt.verify(zatToken, as: SessionPayload.self)
|
||||||
|
guard jwt.accountId.value == beat.playerId else {
|
||||||
|
throw Abort(.unauthorized, reason: "zat invalid")
|
||||||
|
}
|
||||||
|
return "{}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Heartbeat: Content {
|
||||||
|
let playerId: String
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user