Skip to content

Commit 87693ac

Browse files
committed
Removed duplication of relativePathToSpaceID
1 parent 02f339f commit 87693ac

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

internal/http/services/owncloud/ocgraph/drives.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ func (s *svc) convertShareToSpace(rsi *gateway.ReceivedShareResourceInfo) *libre
158158
Id: libregraph.PtrString(fmt.Sprintf("%s$%s!%s", shareJailID, shareJailID, rsi.ReceivedShare.Share.Id.OpaqueId)),
159159
WebDavUrl: libregraph.PtrString(fullURL(s.c.WebDavBase, rsi.ResourceInfo.Path)),
160160
RemoteItem: &libregraph.RemoteItem{
161-
DriveAlias: libregraph.PtrString(strings.TrimSuffix(strings.TrimPrefix(rsi.ResourceInfo.Path, "/"), relativePathToSpaceID(rsi.ResourceInfo))), // the drive alias must not start with /
161+
DriveAlias: libregraph.PtrString(strings.TrimSuffix(strings.TrimPrefix(rsi.ResourceInfo.Path, "/"), spaces.RelativePathToSpaceID(rsi.ResourceInfo))), // the drive alias must not start with /
162162
ETag: libregraph.PtrString(rsi.ResourceInfo.Etag),
163163
Folder: &libregraph.Folder{},
164164
// The Id must correspond to the id in the OCS response, for the time being
165165
// It is in the form <something>!<something-else>
166166
Id: libregraph.PtrString(spaces.EncodeResourceID(rsi.ResourceInfo.Id)),
167167
LastModifiedDateTime: libregraph.PtrTime(time.Unix(int64(rsi.ResourceInfo.Mtime.Seconds), int64(rsi.ResourceInfo.Mtime.Nanos))),
168168
Name: libregraph.PtrString(filepath.Base(rsi.ResourceInfo.Path)),
169-
Path: libregraph.PtrString(relativePathToSpaceID(rsi.ResourceInfo)),
169+
Path: libregraph.PtrString(spaces.RelativePathToSpaceID(rsi.ResourceInfo)),
170170
// RootId must have the same token before ! as Id
171171
// the second part for the time being is not used
172172
RootId: libregraph.PtrString(fmt.Sprintf("%s!unused_root_id", spaces.EncodeSpaceID(rsi.ResourceInfo.Id.StorageId, rsi.ResourceInfo.Id.SpaceId))),
@@ -176,10 +176,6 @@ func (s *svc) convertShareToSpace(rsi *gateway.ReceivedShareResourceInfo) *libre
176176
}
177177
}
178178

179-
func relativePathToSpaceID(info *providerpb.ResourceInfo) string {
180-
return strings.TrimPrefix(info.Path, info.Id.SpaceId)
181-
}
182-
183179
func generateCs3Filters(request *godata.GoDataRequest) ([]*providerpb.ListStorageSpacesRequest_Filter, error) {
184180
var filters spaces.ListStorageSpaceFilter
185181
if request.Query.Filter != nil {

internal/http/services/owncloud/ocgraph/shares.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (s *svc) cs3ReceivedShareToDriveItem(ctx context.Context, rsi *gateway.Rece
135135
Id: libregraph.PtrString(encodeSpaceIDForShareJail(rsi.ResourceInfo)),
136136
LastModifiedDateTime: libregraph.PtrTime(utils.TSToTime(rsi.ResourceInfo.Mtime)),
137137
Name: libregraph.PtrString(rsi.ResourceInfo.Name),
138-
Path: libregraph.PtrString(relativePathToSpaceID(rsi.ResourceInfo)),
138+
Path: libregraph.PtrString(spaces.RelativePathToSpaceID(rsi.ResourceInfo)),
139139
// ParentReference: &libregraph.ItemReference{
140140
// DriveId: libregraph.PtrString(spaces.EncodeResourceID(share.ResourceInfo.ParentId)),
141141
// DriveType: nil, // FIXME: no way to know it unless we hardcode it
@@ -322,7 +322,7 @@ func (s *svc) getSharedByMe(w http.ResponseWriter, r *http.Request) {
322322

323323
func (s *svc) cs3ShareToDriveItem(ctx context.Context, info *provider.ResourceInfo, shares []*share) (*libregraph.DriveItem, error) {
324324

325-
parentRelativePath := path.Dir(relativePathToSpaceID(info))
325+
parentRelativePath := path.Dir(spaces.RelativePathToSpaceID(info))
326326

327327
permissions, err := s.cs3sharesToPermissions(ctx, shares)
328328
if err != nil {

internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -1167,10 +1167,6 @@ func (h *Handler) addFilters(w http.ResponseWriter, r *http.Request, prefix stri
11671167
return collaborationFilters, linkFilters, nil
11681168
}
11691169

1170-
func relativePathToSpaceID(info *provider.ResourceInfo) string {
1171-
return strings.TrimPrefix(info.Path, info.Id.SpaceId)
1172-
}
1173-
11741170
func (h *Handler) addFileInfo(ctx context.Context, s *conversions.ShareData, info *provider.ResourceInfo) error {
11751171
log := appctx.GetLogger(ctx)
11761172
if info != nil {
@@ -1189,8 +1185,8 @@ func (h *Handler) addFileInfo(ctx context.Context, s *conversions.ShareData, inf
11891185
s.FileSource = s.ItemSource
11901186
switch {
11911187
case h.sharePrefix == "/":
1192-
s.FileTarget = relativePathToSpaceID(info)
1193-
s.Path = relativePathToSpaceID(info)
1188+
s.FileTarget = spaces.RelativePathToSpaceID(info)
1189+
s.Path = spaces.RelativePathToSpaceID(info)
11941190
case s.ShareType == conversions.ShareTypePublicLink:
11951191
s.FileTarget = path.Join("/", path.Base(info.Path))
11961192
s.Path = path.Join("/", path.Base(info.Path))

pkg/spaces/utils.go

+4
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,7 @@ func EncodeSpaceID(storageID, path string) string {
8585
encodedPath := base32.StdEncoding.EncodeToString([]byte(path))
8686
return fmt.Sprintf("%s$%s", storageID, encodedPath)
8787
}
88+
89+
func RelativePathToSpaceID(info *provider.ResourceInfo) string {
90+
return strings.TrimPrefix(info.Path, info.Id.SpaceId)
91+
}

0 commit comments

Comments
 (0)