Skip to content

Commit

Permalink
expose shares as spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Nov 14, 2023
1 parent ab88cef commit c74e76c
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions internal/http/services/owncloud/ocgraph/drives.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@
package ocgraph

import (
"context"
"encoding/json"
"net/http"
"net/url"
"path"
"strings"

"github.com/CiscoM31/godata"
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
collaborationv1beta1 "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
providerpb "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/spaces"
Expand Down Expand Up @@ -76,6 +80,16 @@ func (s *svc) listMySpaces(w http.ResponseWriter, r *http.Request) {
return
}

if isMountpointRequest(odataReq) {
shares, err := resolveMountpointSpaces(ctx, gw)
if err != nil {
log.Error().Err(err).Msg("error getting share spaces")
w.WriteHeader(http.StatusInternalServerError)
return
}
res.StorageSpaces = append(res.StorageSpaces, shares...)
}

me := appctx.ContextMustGetUser(ctx)

spaces := list.Map(res.StorageSpaces, func(space *providerpb.StorageSpace) *libregraph.Drive {
Expand All @@ -91,6 +105,44 @@ func (s *svc) listMySpaces(w http.ResponseWriter, r *http.Request) {
}
}

func isMountpointRequest(request *godata.GoDataRequest) bool {
if request.Query.Filter == nil {
return false
}
if request.Query.Filter.Tree.Token.Value != "eq" {
return false
}
return request.Query.Filter.Tree.Children[0].Token.Value == "driveType" && strings.Trim(request.Query.Filter.Tree.Children[1].Token.Value, "'") == "mountpoint"
}

func resolveMountpointSpaces(ctx context.Context, gw gateway.GatewayAPIClient) ([]*providerpb.StorageSpace, error) {
res, err := gw.ListReceivedShares(ctx, &collaborationv1beta1.ListReceivedSharesRequest{})
if err != nil {
return nil, err
}

spacesRes := make([]*providerpb.StorageSpace, 0, len(res.Shares))
for _, s := range res.Shares {
stat, err := gw.Stat(ctx, &providerpb.StatRequest{
Ref: &providerpb.Reference{
ResourceId: s.Share.ResourceId,
},
})
if err != nil {
return nil, err
}

space := &providerpb.StorageSpace{
RootInfo: stat.Info,
Id: &providerpb.StorageSpaceId{OpaqueId: stat.Info.Path},
Name: path.Base(stat.Info.Path),
SpaceType: "mountpoint",
}
spacesRes = append(spacesRes, space)
}
return spacesRes, nil
}

func generateCs3Filters(request *godata.GoDataRequest) ([]*providerpb.ListStorageSpacesRequest_Filter, error) {
var filters spaces.ListStorageSpaceFilter
if request.Query.Filter != nil {
Expand Down

0 comments on commit c74e76c

Please sign in to comment.