Change time params to UNIX timestamp in console usage-report query (#1757)
This commit is contained in:
parent
65723afa9f
commit
f7409ab52b
@ -130,6 +130,8 @@ func (s *Server) bucketUsageReportHandler(w http.ResponseWriter, req *http.Reque
|
||||
|
||||
auth, err := s.service.Authorize(auth.WithAPIKey(req.Context(), []byte(tokenCookie.Value)))
|
||||
if err != nil {
|
||||
s.log.Error("bucket usage report error", zap.Error(err))
|
||||
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
http.ServeFile(w, req, filepath.Join(s.config.StaticDir, "static", "errors", "404.html"))
|
||||
return
|
||||
@ -137,6 +139,8 @@ func (s *Server) bucketUsageReportHandler(w http.ResponseWriter, req *http.Reque
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
s.log.Error("bucket usage report error", zap.Error(err))
|
||||
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
http.ServeFile(w, req, filepath.Join(s.config.StaticDir, "static", "errors", "404.html"))
|
||||
}
|
||||
@ -147,15 +151,18 @@ func (s *Server) bucketUsageReportHandler(w http.ResponseWriter, req *http.Reque
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
since, err = time.Parse(time.RFC3339, req.URL.Query().Get("since"))
|
||||
sinceStamp, err := strconv.ParseInt(req.URL.Query().Get("since"), 10, 64)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
before, err = time.Parse(time.RFC3339, req.URL.Query().Get("before"))
|
||||
beforeStamp, err := strconv.ParseInt(req.URL.Query().Get("before"), 10, 64)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
since = time.Unix(sinceStamp, 0)
|
||||
before = time.Unix(beforeStamp, 0)
|
||||
|
||||
s.log.Debug("querying bucket usage report",
|
||||
zap.String("projectID", projectID.String()),
|
||||
zap.String("since", since.String()),
|
||||
|
@ -69,6 +69,7 @@ import { Component, Vue } from 'vue-property-decorator';
|
||||
import ROUTES from '@/utils/constants/routerConstants';
|
||||
import Datepicker from '@/components/project/DatePicker.vue';
|
||||
import { NOTIFICATION_ACTIONS, PROJECT_USAGE_ACTIONS } from '@/utils/constants/actionNames';
|
||||
import { toUnixTimestamp } from '@/utils/time';
|
||||
|
||||
@Component(
|
||||
{
|
||||
@ -188,8 +189,8 @@ import { NOTIFICATION_ACTIONS, PROJECT_USAGE_ACTIONS } from '@/utils/constants/a
|
||||
let url = new URL(location.origin);
|
||||
url.pathname = 'usage-report';
|
||||
url.searchParams.append('projectID', projectID);
|
||||
url.searchParams.append('since', this.$data.dateRange.startDate.toISOString());
|
||||
url.searchParams.append('before', this.$data.dateRange.endDate.toISOString());
|
||||
url.searchParams.append('since', toUnixTimestamp(this.$data.dateRange.startDate).toString());
|
||||
url.searchParams.append('before', toUnixTimestamp(this.$data.dateRange.endDate).toString());
|
||||
|
||||
window.open(url.href, '_blank');
|
||||
},
|
||||
|
7
web/satellite/src/utils/time.ts
Normal file
7
web/satellite/src/utils/time.ts
Normal file
@ -0,0 +1,7 @@
|
||||
// Copyright (C) 2019 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
// toUnixTimestamp converts Date to unix timestamp
|
||||
export function toUnixTimestamp(time :Date) : number {
|
||||
return Math.floor(time.getTime() / 1000);
|
||||
}
|
Loading…
Reference in New Issue
Block a user