feat: add /s5/account/stats endpoint

This commit is contained in:
Derrick Hammer 2024-01-17 12:03:08 -05:00
parent ef872bf344
commit cf422aef0e
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 35 additions and 0 deletions

View File

@ -34,5 +34,6 @@ func getRoutes(h *s5.HttpHandler, portal interfaces.Portal) map[string]jape.Hand
"GET /s5/account/login": h.AccountLoginChallenge, "GET /s5/account/login": h.AccountLoginChallenge,
"POST /s5/account/login": h.AccountLogin, "POST /s5/account/login": h.AccountLogin,
"GET /s5/account": s5.AuthMiddleware(h.AccountInfo, portal), "GET /s5/account": s5.AuthMiddleware(h.AccountInfo, portal),
"GET /s5/account/stats": s5.AuthMiddleware(h.AccountStats, portal),
} }
} }

View File

@ -532,6 +532,27 @@ func (h *HttpHandler) AccountInfo(jc jape.Context) {
jc.Encode(info) jc.Encode(info)
} }
func (h *HttpHandler) AccountStats(jc jape.Context) {
_, user := h.portal.Accounts().AccountExists(jc.Request.Context().Value(AuthUserIDKey).(uint64))
info := &AccountStatsResponse{
AccountInfoResponse: AccountInfoResponse{
Email: user.Email,
QuotaExceeded: false,
EmailConfirmed: false,
IsRestricted: false,
Tier: 0,
},
Stats: AccountStats{
Total: AccountStatsTotal{
UsedStorage: 0,
},
},
}
jc.Encode(info)
}
func setAuthCookie(jwt string, jc jape.Context) { func setAuthCookie(jwt string, jc jape.Context) {
authCookie := http.Cookie{ authCookie := http.Cookie{
Name: "s5-auth-token", Name: "s5-auth-token",

View File

@ -29,3 +29,16 @@ type AccountInfoResponse struct {
IsRestricted bool `json:"isRestricted"` IsRestricted bool `json:"isRestricted"`
Tier uint8 `json:"tier"` Tier uint8 `json:"tier"`
} }
type AccountStatsResponse struct {
AccountInfoResponse
Stats AccountStats `json:"stats"`
}
type AccountStats struct {
Total AccountStatsTotal `json:"total"`
}
type AccountStatsTotal struct {
UsedStorage uint64 `json:"usedStorage"`
}