mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-09-14 23:00:31 -04:00
$expand=thumbnails was only honored by sharedByMe and sharedWithMe. The driveItem stat, the children listing and the root children listing now honor it as well, so a client that lists a folder learns which items have a preview instead of guessing from the mime type. The thumbnails are set from the resource info the listing already has, so a later preview check that needs more than the mime type has a single place to sit. The two share listings carry driveItems only, they keep matching on the mime type but share the url building.
81 lines
2.8 KiB
Go
81 lines
2.8 KiB
Go
package svc
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strings"
|
|
|
|
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
|
|
ocm "github.com/cs3org/go-cs3apis/cs3/sharing/ocm/v1beta1"
|
|
"github.com/go-chi/render"
|
|
libregraph "github.com/opencloud-eu/libre-graph-api-go"
|
|
"github.com/opencloud-eu/reva/v2/pkg/share"
|
|
|
|
"github.com/opencloud-eu/opencloud/services/graph/pkg/errorcode"
|
|
)
|
|
|
|
// ListSharedWithMe lists the files shared with the current user.
|
|
func (g Graph) ListSharedWithMe(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
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)
|
|
return
|
|
}
|
|
|
|
render.Status(r, http.StatusOK)
|
|
render.JSON(w, r, &ListResponse{Value: driveItems})
|
|
}
|
|
|
|
// listSharedWithMe is a helper function that lists the drive items shared with the current user.
|
|
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")
|
|
return nil, err
|
|
}
|
|
|
|
listReceivedSharesResponse, err := gatewayClient.ListReceivedShares(ctx, &collaboration.ListReceivedSharesRequest{
|
|
Filters: []*collaboration.Filter{
|
|
share.SpaceRootFilter(false),
|
|
},
|
|
})
|
|
if err := errorcode.FromCS3Status(listReceivedSharesResponse.GetStatus(), err); err != nil {
|
|
g.logger.Error().Err(err).Msg("listing shares failed")
|
|
return nil, err
|
|
}
|
|
driveItems, err := cs3ReceivedSharesToDriveItems(ctx, g.logger, gatewayClient, g.identityCache, listReceivedSharesResponse.GetShares(), g.availableRoles)
|
|
if err != nil {
|
|
g.logger.Error().Err(err).Msg("could not convert received shares to drive items")
|
|
return nil, err
|
|
}
|
|
|
|
if g.config.IncludeOCMSharees {
|
|
listReceivedOCMSharesResponse, err := gatewayClient.ListReceivedOCMShares(ctx, &ocm.ListReceivedOCMSharesRequest{})
|
|
if err := errorcode.FromCS3Status(listReceivedSharesResponse.GetStatus(), err); err != nil {
|
|
g.logger.Error().Err(err).Msg("listing shares failed")
|
|
return nil, err
|
|
}
|
|
ocmDriveItems, err := cs3ReceivedOCMSharesToDriveItems(ctx, g.logger, gatewayClient, g.identityCache, listReceivedOCMSharesResponse.GetShares(), g.availableRoles)
|
|
if err != nil {
|
|
g.logger.Error().Err(err).Msg("could not convert received ocm shares to drive items")
|
|
return nil, err
|
|
}
|
|
driveItems = append(driveItems, ocmDriveItems...)
|
|
}
|
|
|
|
if expandThumbnails {
|
|
for k, item := range driveItems {
|
|
setShareThumbnails(&item, item.RemoteItem.GetId(), g.config.Commons.OpenCloudURL)
|
|
driveItems[k] = item
|
|
}
|
|
}
|
|
|
|
return driveItems, err
|
|
}
|