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 = ','