From 243f2febab4e0c82615e7f8492bfdca23d1c0d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Fri, 2 Aug 2024 12:27:49 +0200 Subject: [PATCH] fix: code review fixes --- .../collaboration/pkg/connector/fileconnector.go | 13 +++++++++---- services/collaboration/pkg/connector/httpadapter.go | 11 +++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/services/collaboration/pkg/connector/fileconnector.go b/services/collaboration/pkg/connector/fileconnector.go index 4b01a4c495..9bca8866f5 100644 --- a/services/collaboration/pkg/connector/fileconnector.go +++ b/services/collaboration/pkg/connector/fileconnector.go @@ -21,6 +21,7 @@ import ( rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" providerv1beta1 "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" + "github.com/cs3org/reva/v2/pkg/storagespace" "github.com/cs3org/reva/v2/pkg/utils" "github.com/google/uuid" "github.com/owncloud/ocis/v2/services/collaboration/pkg/config" @@ -35,11 +36,15 @@ const ( lockDuration time.Duration = 30 * time.Minute ) +// PutRelativeHeaders contains the values for headers used in a +// "PutRelative" WOPI response type PutRelativeHeaders struct { ValidTarget string LockID string } +// PutRelativeResponse contains the values for the body used in a +// "PutRelative" WOPI response type PutRelativeResponse struct { Name string Url string @@ -49,6 +54,8 @@ type PutRelativeResponse struct { HostEdit string } +// RenameResponse contains the values for the body used in a +// "RenameFile" WOPI response type RenameResponse struct { Name string } @@ -717,7 +724,7 @@ func (f *FileConnector) PutRelativeFileRelative(ctx context.Context, ccs Content newCtx := middleware.WopiContextToCtx(newLogger.WithContext(ctx), wopiContext) var conError *ConnectorError - // try to put the file. It mustn't return a 400 or 409 + // try to put the file lockID, err := ccs.PutFile(newCtx, stream, streamLength, "") if err != nil { // if the error isn't a connectorError, fail the request @@ -757,8 +764,6 @@ func (f *FileConnector) PutRelativeFileRelative(ctx context.Context, ccs Content Msg("PutRelativeFileRelative: error conflict") return response, headers, err } else { - // TODO: code 400 might happen, what to do? - // in other cases, just return the error newLogger.Error(). Err(err). Str("LockID", lockID). @@ -1203,7 +1208,7 @@ func (f *FileConnector) generateWOPISrc(ctx context.Context, wopiContext middlew // get the reference resourceId := wopiContext.FileReference.GetResourceId() c := sha256.New() - c.Write([]byte(resourceId.GetStorageId() + "$" + resourceId.GetSpaceId() + "!" + resourceId.GetOpaqueId())) + c.Write([]byte(storagespace.FormatResourceID(resourceId))) fileRef := hex.EncodeToString(c.Sum(nil)) // generate the URL for the WOPI app to access the new created file diff --git a/services/collaboration/pkg/connector/httpadapter.go b/services/collaboration/pkg/connector/httpadapter.go index e0dfe18256..2486ec7682 100644 --- a/services/collaboration/pkg/connector/httpadapter.go +++ b/services/collaboration/pkg/connector/httpadapter.go @@ -259,6 +259,10 @@ func (h *HttpAdapter) PutFile(w http.ResponseWriter, r *http.Request) { // It has 2 mutually exclusive operation methods that are used based on the // provided headers in the request. // Note that this method won't used locks (not documented). +// +// The file name must be encoded in utf7. This method will decode the utf7 name +// into utf8. The utf8 (not utf7) name must have less than 512 bytes, otherwise +// the request will fail. func (h *HttpAdapter) PutRelativeFile(w http.ResponseWriter, r *http.Request) { relativeTarget := r.Header.Get(HeaderWopiRT) suggestedTarget := r.Header.Get(HeaderWopiST) @@ -354,6 +358,13 @@ func (h *HttpAdapter) DeleteFile(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) } +// RenameFile will rename the file. The name might be automatically adjusted. +// Note that this method will also send a json body in the response. The +// adjusted file name will be returned in the body. +// +// The file name must be encoded in utf7. This method will decode the utf7 name +// into utf8. The utf8 (not utf7) name must have less than 495 bytes, otherwise +// the request will fail. func (h *HttpAdapter) RenameFile(w http.ResponseWriter, r *http.Request) { lockID := r.Header.Get(HeaderWopiLock) requestedName := r.Header.Get(HeaderWopiRequestedName)