mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-05-28 09:25:37 +02:00
v1/account API response, rate limiting bla
This commit is contained in:
parent
ac56fa36ba
commit
56ab34a57f
2 changed files with 34 additions and 4 deletions
server
|
@ -40,9 +40,7 @@ func (s *Server) handleAccountGet(w http.ResponseWriter, r *http.Request, v *vis
|
|||
return err
|
||||
}
|
||||
response := &apiAccountSettingsResponse{
|
||||
Usage: &apiAccountUsageLimits{
|
||||
Basis: "ip",
|
||||
},
|
||||
Usage: &apiAccountUsageLimits{},
|
||||
}
|
||||
if v.user != nil {
|
||||
response.Username = v.user.Name
|
||||
|
@ -66,11 +64,37 @@ func (s *Server) handleAccountGet(w http.ResponseWriter, r *http.Request, v *vis
|
|||
EmailsLimit: v.user.Plan.EmailsLimit,
|
||||
AttachmentsBytesLimit: v.user.Plan.AttachmentBytesLimit,
|
||||
}
|
||||
} else {
|
||||
if v.user.Role == auth.RoleAdmin {
|
||||
response.Usage.Basis = "account"
|
||||
response.Plan = &apiAccountSettingsPlan{
|
||||
Name: "Unlimited",
|
||||
MessagesLimit: 0,
|
||||
EmailsLimit: 0,
|
||||
AttachmentsBytesLimit: 0,
|
||||
}
|
||||
} else {
|
||||
response.Usage.Basis = "ip"
|
||||
response.Plan = &apiAccountSettingsPlan{
|
||||
Name: "Free",
|
||||
MessagesLimit: s.config.VisitorRequestLimitBurst,
|
||||
EmailsLimit: s.config.VisitorEmailLimitBurst,
|
||||
AttachmentsBytesLimit: s.config.VisitorAttachmentTotalSizeLimit,
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
response.Username = auth.Everyone
|
||||
response.Role = string(auth.RoleAnonymous)
|
||||
response.Usage.Basis = "account"
|
||||
response.Plan = &apiAccountSettingsPlan{
|
||||
Name: "Anonymous",
|
||||
MessagesLimit: s.config.VisitorRequestLimitBurst,
|
||||
EmailsLimit: s.config.VisitorEmailLimitBurst,
|
||||
AttachmentsBytesLimit: s.config.VisitorAttachmentTotalSizeLimit,
|
||||
}
|
||||
}
|
||||
response.Usage.Messages = int(v.requests.Tokens())
|
||||
response.Usage.AttachmentsBytes = stats.VisitorAttachmentBytesUsed
|
||||
if err := json.NewEncoder(w).Encode(response); err != nil {
|
||||
return err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue