Skip to content

Commit

Permalink
add timestamp to the export filename (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
saivishnu725 authored Dec 2, 2024
1 parent c9fc3ce commit 8dca148
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion backend/app/api/handlers/v1/v1_ctrl_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"database/sql"
"encoding/csv"
"errors"
"fmt"
"math/big"
"net/http"
"net/url"
"strings"
"time"

"github.com/google/uuid"
"github.com/hay-kot/httpkit/errchain"
Expand Down Expand Up @@ -339,9 +341,12 @@ func (ctrl *V1Controller) HandleItemsExport() errchain.HandlerFunc {
log.Err(err).Msg("failed to export items")
return validate.NewRequestError(err, http.StatusInternalServerError)
}

timestamp := time.Now().Format("2006-01-02_15-04-05") // YYYY-MM-DD_HH-MM-SS format
filename := fmt.Sprintf("homebox-items_%s.csv", timestamp) // add timestamp to filename

w.Header().Set("Content-Type", "text/csv")
w.Header().Set("Content-Disposition", "attachment;filename=homebox-items.csv")
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment;filename=%s", filename))

writer := csv.NewWriter(w)
writer.Comma = ','
Expand Down

0 comments on commit 8dca148

Please sign in to comment.