From 6f307f744672de3d9727351e70e539c5f431d118 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Tue, 27 Oct 2020 12:49:15 +0100 Subject: [PATCH] Move http utils to pkg --- internal/http/services/dataprovider/put.go | 2 +- internal/http/services/owncloud/ocdav/get.go | 2 +- internal/http/services/owncloud/ocdav/head.go | 2 +- .../http/services/owncloud/ocdav/propfind.go | 2 +- internal/http/services/owncloud/ocdav/put.go | 2 +- .../http/services/owncloud/ocdav/trashbin.go | 2 +- internal/http/services/owncloud/ocdav/tus.go | 2 +- internal/http/utils/utils.go | 36 ------------------- pkg/utils/utils.go | 14 ++++++++ 9 files changed, 21 insertions(+), 43 deletions(-) delete mode 100644 internal/http/utils/utils.go diff --git a/internal/http/services/dataprovider/put.go b/internal/http/services/dataprovider/put.go index 300433893d..13e957688e 100644 --- a/internal/http/services/dataprovider/put.go +++ b/internal/http/services/dataprovider/put.go @@ -117,7 +117,7 @@ func (s *svc) doTusPut(w http.ResponseWriter, r *http.Request) { "dir": path.Dir(fp), } - upload := tus.NewUpload(r.Body, length, metadata, "") + upload := tus.NewUpload(fd, length, metadata, "") defer r.Body.Close() // create the uploader. diff --git a/internal/http/services/owncloud/ocdav/get.go b/internal/http/services/owncloud/ocdav/get.go index 3571223600..1517e3a803 100644 --- a/internal/http/services/owncloud/ocdav/get.go +++ b/internal/http/services/owncloud/ocdav/get.go @@ -29,9 +29,9 @@ import ( rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" - "github.com/cs3org/reva/internal/http/utils" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/rhttp" + "github.com/cs3org/reva/pkg/utils" ) func (s *svc) handleGet(w http.ResponseWriter, r *http.Request, ns string) { diff --git a/internal/http/services/owncloud/ocdav/head.go b/internal/http/services/owncloud/ocdav/head.go index 8760d37d39..02e776b560 100644 --- a/internal/http/services/owncloud/ocdav/head.go +++ b/internal/http/services/owncloud/ocdav/head.go @@ -26,8 +26,8 @@ import ( rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" - "github.com/cs3org/reva/internal/http/utils" "github.com/cs3org/reva/pkg/appctx" + "github.com/cs3org/reva/pkg/utils" ) func (s *svc) handleHead(w http.ResponseWriter, r *http.Request, ns string) { diff --git a/internal/http/services/owncloud/ocdav/propfind.go b/internal/http/services/owncloud/ocdav/propfind.go index 3b18e2db17..f570315087 100644 --- a/internal/http/services/owncloud/ocdav/propfind.go +++ b/internal/http/services/owncloud/ocdav/propfind.go @@ -36,8 +36,8 @@ import ( rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" "github.com/cs3org/reva/internal/http/services/owncloud/ocs/conversions" - "github.com/cs3org/reva/internal/http/utils" "github.com/cs3org/reva/pkg/appctx" + "github.com/cs3org/reva/pkg/utils" "github.com/pkg/errors" ) diff --git a/internal/http/services/owncloud/ocdav/put.go b/internal/http/services/owncloud/ocdav/put.go index b1a1bfffcf..9ac9c40878 100644 --- a/internal/http/services/owncloud/ocdav/put.go +++ b/internal/http/services/owncloud/ocdav/put.go @@ -30,8 +30,8 @@ import ( rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" - "github.com/cs3org/reva/internal/http/utils" "github.com/cs3org/reva/pkg/appctx" + "github.com/cs3org/reva/pkg/utils" ) func isChunked(fn string) (bool, error) { diff --git a/internal/http/services/owncloud/ocdav/trashbin.go b/internal/http/services/owncloud/ocdav/trashbin.go index 4a43afa3d5..6386d01643 100644 --- a/internal/http/services/owncloud/ocdav/trashbin.go +++ b/internal/http/services/owncloud/ocdav/trashbin.go @@ -32,11 +32,11 @@ import ( userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" - "github.com/cs3org/reva/internal/http/utils" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/pkg/rhttp/router" ctxuser "github.com/cs3org/reva/pkg/user" + "github.com/cs3org/reva/pkg/utils" ) // TrashbinHandler handles trashbin requests diff --git a/internal/http/services/owncloud/ocdav/tus.go b/internal/http/services/owncloud/ocdav/tus.go index e3dc016948..d9319cc051 100644 --- a/internal/http/services/owncloud/ocdav/tus.go +++ b/internal/http/services/owncloud/ocdav/tus.go @@ -28,9 +28,9 @@ import ( rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" - "github.com/cs3org/reva/internal/http/utils" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/rhttp" + "github.com/cs3org/reva/pkg/utils" tusd "github.com/tus/tusd/pkg/handler" ) diff --git a/internal/http/utils/utils.go b/internal/http/utils/utils.go deleted file mode 100644 index 2a74ab1ed6..0000000000 --- a/internal/http/utils/utils.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2018-2020 CERN -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// In applying this license, CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -package utils - -import ( - "time" - - types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" -) - -// TSToUnixNano converts a protobuf Timestamp to uint64 -// with nanoseconds resolution. -func TSToUnixNano(ts *types.Timestamp) uint64 { - return uint64(time.Unix(int64(ts.Seconds), int64(ts.Nanos)).UnixNano()) -} - -// TSToTime converts a protobuf Timestamp to Go's time.Time. -func TSToTime(ts *types.Timestamp) time.Time { - return time.Unix(int64(ts.Seconds), int64(ts.Nanos)) -} diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 427e0427cf..428725e077 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -25,6 +25,9 @@ import ( "path/filepath" "regexp" "strings" + "time" + + types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" ) var ( @@ -92,3 +95,14 @@ func ResolvePath(path string) (string, error) { return path, nil } + +// TSToUnixNano converts a protobuf Timestamp to uint64 +// with nanoseconds resolution. +func TSToUnixNano(ts *types.Timestamp) uint64 { + return uint64(time.Unix(int64(ts.Seconds), int64(ts.Nanos)).UnixNano()) +} + +// TSToTime converts a protobuf Timestamp to Go's time.Time. +func TSToTime(ts *types.Timestamp) time.Time { + return time.Unix(int64(ts.Seconds), int64(ts.Nanos)) +}