diff --git a/changelog/unreleased/ocdav-versions-api.md b/changelog/unreleased/ocdav-versions-api.md new file mode 100644 index 0000000000..2e5e1fa3bc --- /dev/null +++ b/changelog/unreleased/ocdav-versions-api.md @@ -0,0 +1,6 @@ +Enhancement: Add download endpoint to ocdav versions API + +Added missing endpoints to the ocdav versions API. This enables downloads of previous file versions. + +https://github.com/owncloud/ocis/issues/3741 +https://github.com/cs3org/reva/pull/2855 diff --git a/internal/http/services/owncloud/ocdav/get.go b/internal/http/services/owncloud/ocdav/get.go index 4022532407..4a6a41b11e 100644 --- a/internal/http/services/owncloud/ocdav/get.go +++ b/internal/http/services/owncloud/ocdav/get.go @@ -144,7 +144,7 @@ func (s *svc) handleGet(ctx context.Context, w http.ResponseWriter, r *http.Requ w.Header().Set(net.HeaderContentType, info.MimeType) w.Header().Set(net.HeaderContentDisposistion, "attachment; filename*=UTF-8''"+ - path.Base(r.URL.Path)+"; filename=\""+path.Base(r.URL.Path)+"\"") + path.Base(info.Path)+"; filename=\""+path.Base(info.Path)+"\"") w.Header().Set(net.HeaderETag, info.Etag) w.Header().Set(net.HeaderOCFileID, storagespace.FormatResourceID(*info.Id)) w.Header().Set(net.HeaderOCETag, info.Etag) diff --git a/internal/http/services/owncloud/ocdav/versions.go b/internal/http/services/owncloud/ocdav/versions.go index 90d2a751f9..c448ada3ce 100644 --- a/internal/http/services/owncloud/ocdav/versions.go +++ b/internal/http/services/owncloud/ocdav/versions.go @@ -28,6 +28,7 @@ import ( "github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/propfind" "github.com/cs3org/reva/v2/pkg/storagespace" rtrace "github.com/cs3org/reva/v2/pkg/trace" + "github.com/cs3org/reva/v2/pkg/utils" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" @@ -71,12 +72,36 @@ func (h *VersionsHandler) Handler(s *svc, rid *provider.ResourceId) http.Handler h.doListVersions(w, r, s, rid) return } - if key != "" && r.Method == MethodCopy { - // TODO(jfd) it seems we cannot directly GET version content with cs3 ... - // TODO(jfd) cs3api has no delete file version call - // TODO(jfd) restore version to given Destination, but cs3api has no destination - h.doRestore(w, r, s, rid, key) - return + if key != "" { + switch r.Method { + case MethodCopy: + // TODO(jfd) cs3api has no delete file version call + // TODO(jfd) restore version to given Destination, but cs3api has no destination + h.doRestore(w, r, s, rid, key) + return + case http.MethodHead: + log := appctx.GetLogger(ctx) + ref := &provider.Reference{ + ResourceId: &provider.ResourceId{ + StorageId: rid.StorageId, + OpaqueId: key, + }, + Path: utils.MakeRelativePath(r.URL.Path), + } + s.handleHead(ctx, w, r, ref, *log) + return + case http.MethodGet: + log := appctx.GetLogger(ctx) + ref := &provider.Reference{ + ResourceId: &provider.ResourceId{ + StorageId: rid.StorageId, + OpaqueId: key, + }, + Path: utils.MakeRelativePath(r.URL.Path), + } + s.handleGet(ctx, w, r, ref, "spaces", *log) + return + } } http.Error(w, "501 Forbidden", http.StatusNotImplemented) diff --git a/tests/acceptance/expected-failures-on-OCIS-storage.md b/tests/acceptance/expected-failures-on-OCIS-storage.md index e84db024c3..9632e57c52 100644 --- a/tests/acceptance/expected-failures-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-on-OCIS-storage.md @@ -1421,8 +1421,6 @@ _ocs: api compatibility, return correct status code_ - [apiWebdavProperties1/copyFile.feature:484](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavProperties1/copyFile.feature#L484) #### [downloading an old version of a file returns 501](https://github.com/owncloud/ocis/issues/2261) -- [apiVersions/fileVersions.feature:444](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersions.feature#L444) -- [apiVersions/fileVersions.feature:462](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersions.feature#L462) - [apiVersions/fileVersionsSharingToShares.feature:306](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersionsSharingToShares.feature#L306) #### [file versions do not report the version author](https://github.com/owncloud/ocis/issues/2914) diff --git a/tests/acceptance/expected-failures-on-S3NG-storage.md b/tests/acceptance/expected-failures-on-S3NG-storage.md index 4a0a4b696f..ce814ebb84 100644 --- a/tests/acceptance/expected-failures-on-S3NG-storage.md +++ b/tests/acceptance/expected-failures-on-S3NG-storage.md @@ -10,8 +10,6 @@ Basic file management like up and download, move, copy, properties, quota, trash - [apiTrashbin/trashbinFilesFolders.feature:291](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiTrashbin/trashbinFilesFolders.feature#L291) #### [downloading an old version of a file returns 501](https://github.com/owncloud/ocis/issues/2261) -- [apiVersions/fileVersions.feature:444](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersions.feature#L444) -- [apiVersions/fileVersions.feature:462](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersions.feature#L462) - [apiVersions/fileVersionsSharingToShares.feature:306](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiVersions/fileVersionsSharingToShares.feature#L306) #### [file versions do not report the version author](https://github.com/owncloud/ocis/issues/2914)