Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion api/resolve_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func (app *ApiServer) getUserId(c *fiber.Ctx) int32 {
}

func (app *ApiServer) requireUserIdMiddleware(c *fiber.Ctx) error {
// Allow /users/me/* routes to pass through without userId resolution
if c.Params("userId") == "me" {
return c.Next()
}
Expand Down
2 changes: 1 addition & 1 deletion api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func NewApiServer(config config.Config) *ApiServer {
g.Get("/users/genre/top", app.v1UsersGenreTop)
g.Get("/users/account/:wallet", app.requireAuthMiddleware, app.v1UsersAccount)
g.Get("/users/verify_token", app.v1UsersVerifyToken)
g.Post("/users/me/ping", app.requireAuthMiddleware, app.postV1UsersPing)
g.Post("/users/me/ping", app.postV1UsersPing)

g.Use("/users/handle/:handle", app.requireHandleMiddleware)
g.Get("/users/handle/:handle", app.v1User)
Expand Down
9 changes: 6 additions & 3 deletions api/v1_users_ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ func (app *ApiServer) postV1UsersPing(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusServiceUnavailable, "writes not available")
}

wallet := app.getAuthedWallet(c)
myId := app.getMyId(c)
if myId == 0 {
return fiber.NewError(fiber.StatusBadRequest, "user_id query param is required")
}

_, err := app.writePool.Exec(c.Context(), `
UPDATE users
SET last_active_at = now()
WHERE wallet = $1
WHERE user_id = $1
AND is_current = true
`, wallet)
`, myId)
if err != nil {
app.logger.Error("postV1UsersPing: failed to update last_active_at", zap.Error(err))
return fiber.NewError(fiber.StatusInternalServerError, "failed to record activity")
Expand Down
Loading