From 4c2b723ab0431e98fd96fe26105b21413437f4f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Tue, 22 Jul 2025 10:43:00 +0200 Subject: [PATCH] Implement $expand=thumbnails for sharedwithme --- services/graph/pkg/service/v0/sharedwithme.go | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/services/graph/pkg/service/v0/sharedwithme.go b/services/graph/pkg/service/v0/sharedwithme.go index 796d46f914..f6e645e193 100644 --- a/services/graph/pkg/service/v0/sharedwithme.go +++ b/services/graph/pkg/service/v0/sharedwithme.go @@ -2,7 +2,9 @@ package svc import ( "context" + "fmt" "net/http" + "strings" collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1" ocm "github.com/cs3org/go-cs3apis/cs3/sharing/ocm/v1beta1" @@ -10,12 +12,17 @@ import ( libregraph "github.com/opencloud-eu/libre-graph-api-go" "github.com/opencloud-eu/opencloud/services/graph/pkg/errorcode" + "github.com/opencloud-eu/opencloud/services/thumbnails/pkg/thumbnail" ) // ListSharedWithMe lists the files shared with the current user. func (g Graph) ListSharedWithMe(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - driveItems, err := g.listSharedWithMe(ctx) + + expand := r.URL.Query().Get("$expand") + expandThumbnails := strings.Contains(expand, "thumbnails") + + driveItems, err := g.listSharedWithMe(ctx, expandThumbnails) if err != nil { g.logger.Error().Err(err).Msg("listSharedWithMe failed") errorcode.RenderError(w, r, err) @@ -27,7 +34,7 @@ func (g Graph) ListSharedWithMe(w http.ResponseWriter, r *http.Request) { } // listSharedWithMe is a helper function that lists the drive items shared with the current user. -func (g Graph) listSharedWithMe(ctx context.Context) ([]libregraph.DriveItem, error) { +func (g Graph) listSharedWithMe(ctx context.Context, expandThumbnails bool) ([]libregraph.DriveItem, error) { gatewayClient, err := g.gatewaySelector.Next() if err != nil { g.logger.Error().Err(err).Msg("could not select next gateway client") @@ -59,5 +66,34 @@ func (g Graph) listSharedWithMe(ctx context.Context) ([]libregraph.DriveItem, er driveItems = append(driveItems, ocmDriveItems...) } + if expandThumbnails { + for k, item := range driveItems { + mt := item.GetFile().MimeType + if mt == nil { + continue + } + + _, match := thumbnail.SupportedMimeTypes[*mt] + if match { + baseUrl := fmt.Sprintf("%s/dav/spaces/%s?scalingup=0&preview=1&processor=thumbnail", + g.config.Commons.OpenCloudURL, + item.RemoteItem.GetId()) + smallUrl := baseUrl + "&x=36&y=36" + mediumUrl := baseUrl + "&x=48&y=48" + largeUrl := baseUrl + "&x=96&y=96" + + item.SetThumbnails([]libregraph.ThumbnailSet{ + { + Small: &libregraph.Thumbnail{Url: &smallUrl}, + Medium: &libregraph.Thumbnail{Url: &mediumUrl}, + Large: &libregraph.Thumbnail{Url: &largeUrl}, + }, + }) + + driveItems[k] = item // assign modified item back to the map + } + } + } + return driveItems, err }