From 8dca14850b9404612ecb1d447803a4d967d93e4c Mon Sep 17 00:00:00 2001 From: Sai Vishnu M Date: Mon, 2 Dec 2024 19:30:25 +0530 Subject: [PATCH] add timestamp to the export filename (#366) --- backend/app/api/handlers/v1/v1_ctrl_items.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/app/api/handlers/v1/v1_ctrl_items.go b/backend/app/api/handlers/v1/v1_ctrl_items.go index 1eddc0fc..b23534d6 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_items.go +++ b/backend/app/api/handlers/v1/v1_ctrl_items.go @@ -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" @@ -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 = ','