mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-09-18 00:41:22 -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.
78 lines
2.0 KiB
Go
78 lines
2.0 KiB
Go
package svc
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
|
"github.com/go-chi/render"
|
|
libregraph "github.com/opencloud-eu/libre-graph-api-go"
|
|
|
|
"github.com/opencloud-eu/opencloud/services/graph/pkg/errorcode"
|
|
)
|
|
|
|
type driveItemsByResourceID map[string]libregraph.DriveItem
|
|
|
|
// GetSharedByMe implements the Service interface (/me/drives/sharedByMe endpoint)
|
|
func (g Graph) GetSharedByMe(w http.ResponseWriter, r *http.Request) {
|
|
g.logger.Debug().Msg("Calling GetRootDriveChildren")
|
|
ctx := r.Context()
|
|
|
|
driveItems, err := g.listUserShares(ctx, nil, make(driveItemsByResourceID))
|
|
if err != nil {
|
|
errorcode.RenderError(w, r, err)
|
|
return
|
|
}
|
|
|
|
if g.config.IncludeOCMSharees {
|
|
driveItems, err = g.listOCMShares(ctx, nil, driveItems)
|
|
if err != nil {
|
|
errorcode.RenderError(w, r, err)
|
|
return
|
|
}
|
|
}
|
|
|
|
driveItems, err = g.listPublicShares(ctx, nil, driveItems)
|
|
if err != nil {
|
|
errorcode.RenderError(w, r, err)
|
|
return
|
|
}
|
|
|
|
expand := r.URL.Query().Get("$expand")
|
|
expandThumbnails := strings.Contains(expand, "thumbnails")
|
|
if expandThumbnails {
|
|
for k, item := range driveItems {
|
|
setShareThumbnails(&item, item.GetId(), g.config.Commons.OpenCloudURL)
|
|
driveItems[k] = item
|
|
}
|
|
}
|
|
|
|
res := make([]libregraph.DriveItem, 0, len(driveItems))
|
|
for _, v := range driveItems {
|
|
res = append(res, v)
|
|
}
|
|
|
|
render.Status(r, http.StatusOK)
|
|
render.JSON(w, r, &ListResponse{Value: res})
|
|
}
|
|
|
|
func cs3StatusToErrCode(code rpc.Code) (errcode errorcode.ErrorCode) {
|
|
switch code {
|
|
case rpc.Code_CODE_UNAUTHENTICATED:
|
|
errcode = errorcode.Unauthenticated
|
|
case rpc.Code_CODE_PERMISSION_DENIED:
|
|
errcode = errorcode.AccessDenied
|
|
case rpc.Code_CODE_NOT_FOUND:
|
|
errcode = errorcode.ItemNotFound
|
|
case rpc.Code_CODE_LOCKED:
|
|
errcode = errorcode.ItemIsLocked
|
|
case rpc.Code_CODE_INVALID_ARGUMENT:
|
|
errcode = errorcode.InvalidRequest
|
|
case rpc.Code_CODE_FAILED_PRECONDITION:
|
|
errcode = errorcode.InvalidRequest
|
|
default:
|
|
errcode = errorcode.GeneralException
|
|
}
|
|
return errcode
|
|
}
|