1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

feat: allow unlimited date ranges

This commit is contained in:
Ferdinand Mütsch
2021-02-06 23:23:26 +01:00
parent 2f5973cfa3
commit 6d2697ec37
5 changed files with 7 additions and 11 deletions

View File

@ -68,7 +68,8 @@ func (h *BadgeHandler) Get(w http.ResponseWriter, r *http.Request) {
_, rangeFrom, rangeTo := utils.ResolveInterval(interval)
minStart := utils.StartOfDay(rangeTo.Add(-24 * time.Hour * time.Duration(user.ShareDataMaxDays)))
if rangeFrom.Before(minStart) {
// negative value means no limit
if rangeFrom.Before(minStart) && user.ShareDataMaxDays >= 0 {
w.WriteHeader(http.StatusForbidden)
w.Write([]byte("requested time range too broad"))
return

View File

@ -65,7 +65,7 @@ func (h *StatsHandler) Get(w http.ResponseWriter, r *http.Request) {
minStart := utils.StartOfDay(rangeTo.Add(-24 * time.Hour * time.Duration(requestedUser.ShareDataMaxDays)))
if (authorizedUser == nil || requestedUser.ID != authorizedUser.ID) &&
(requestedUser.ShareDataMaxDays == 0 || rangeFrom.Before(minStart)) {
rangeFrom.Before(minStart) && requestedUser.ShareDataMaxDays >= 0 {
w.WriteHeader(http.StatusForbidden)
w.Write([]byte("requested time range too broad"))
return