Skip to content

Commit

Permalink
Set output format via query param 'output-format
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAndBear committed Jul 15, 2024
1 parent e10b0c7 commit b16dbc7
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions internal/http/services/archiver/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"github.com/cs3org/reva/v2/pkg/storage/utils/walker"
"github.com/cs3org/reva/v2/pkg/storagespace"
"github.com/gdexlab/go-render/render"
ua "github.com/mileusna/useragent"
"github.com/mitchellh/mapstructure"
"github.com/rs/zerolog"
)
Expand Down Expand Up @@ -232,6 +231,10 @@ func (s *svc) Handler() http.Handler {
if !ok {
ids = []string{}
}
format := v.Get("output-format")
if format == "" {
format = "zip"
}

resources, err := s.getResources(ctx, paths, ids)
if err != nil {
Expand All @@ -248,13 +251,11 @@ func (s *svc) Handler() http.Handler {
return
}

userAgent := ua.Parse(r.Header.Get("User-Agent"))

archName := s.config.Name
if userAgent.OS == ua.Windows {
archName += ".zip"
} else {
if format == "tar" {
archName += ".tar"
} else {
archName += ".zip"
}

s.log.Debug().Msg("Requested the following resoucres to archive: " + render.Render(resources))
Expand All @@ -264,10 +265,10 @@ func (s *svc) Handler() http.Handler {

// create the archive
var closeArchive func()
if userAgent.OS == ua.Windows {
closeArchive, err = arch.CreateZip(ctx, rw)
} else {
if format == "tar" {
closeArchive, err = arch.CreateTar(ctx, rw)
} else {
closeArchive, err = arch.CreateZip(ctx, rw)
}
defer closeArchive()

Expand Down

0 comments on commit b16dbc7

Please sign in to comment.