Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set output format via query param 'output-format' #4766

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: Set archiver output format via query parameter

Sets the archive output format e.G "tar" via the url query parameter "output-format",
possible params are "zip" and "tar", falls back to "zip".

https://github.com/cs3org/reva/pull/4766
https://github.com/owncloud/ocis/issues/9399
https://github.com/owncloud/web/issues/11080
21 changes: 11 additions & 10 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,26 +251,24 @@ 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))
s.log.Debug().Msg("Requested the following resources to archive: " + render.Render(resources))

rw.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", archName))
rw.Header().Set("Content-Transfer-Encoding", "binary")

// 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
Loading