mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-09-14 06:39:07 -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.
69 lines
2.3 KiB
Go
69 lines
2.3 KiB
Go
package svc
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
|
libregraph "github.com/opencloud-eu/libre-graph-api-go"
|
|
"github.com/opencloud-eu/reva/v2/pkg/storagespace"
|
|
|
|
"github.com/opencloud-eu/opencloud/services/thumbnails/pkg/thumbnail"
|
|
)
|
|
|
|
const (
|
|
thumbnailBoxSmall = 36
|
|
thumbnailBoxMedium = 48
|
|
thumbnailBoxLarge = 96
|
|
)
|
|
|
|
func (g Graph) setDriveItemsThumbnails(r *http.Request, items []libregraph.DriveItem, infos []*provider.ResourceInfo) {
|
|
if !driveItemRelationExpanded(r, _expandThumbnails) {
|
|
return
|
|
}
|
|
for i := range items {
|
|
if i < len(infos) {
|
|
setDriveItemThumbnails(&items[i], infos[i], g.config.Commons.OpenCloudURL)
|
|
}
|
|
}
|
|
}
|
|
|
|
func setDriveItemThumbnails(item *libregraph.DriveItem, res *provider.ResourceInfo, baseURL string) {
|
|
if set := previewThumbnailSet(res, baseURL); set != nil {
|
|
item.SetThumbnails([]libregraph.ThumbnailSet{*set})
|
|
}
|
|
}
|
|
|
|
// previewThumbnailSet returns nil when the thumbnailer cannot render the resource.
|
|
func previewThumbnailSet(res *provider.ResourceInfo, baseURL string) *libregraph.ThumbnailSet {
|
|
if !thumbnail.IsMimeTypeSupported(res.GetMimeType()) {
|
|
return nil
|
|
}
|
|
return thumbnailSetFor(baseURL, storagespace.FormatResourceID(res.GetId()))
|
|
}
|
|
|
|
// thumbnailSetFor builds the urls of the WebDAV preview endpoint.
|
|
func thumbnailSetFor(baseURL, itemID string) *libregraph.ThumbnailSet {
|
|
base := fmt.Sprintf("%s/dav/spaces/%s?scalingup=0&preview=1&processor=thumbnail", baseURL, itemID)
|
|
return &libregraph.ThumbnailSet{
|
|
Small: previewThumbnail(base, thumbnailBoxSmall),
|
|
Medium: previewThumbnail(base, thumbnailBoxMedium),
|
|
Large: previewThumbnail(base, thumbnailBoxLarge),
|
|
}
|
|
}
|
|
|
|
func previewThumbnail(base string, box int32) *libregraph.Thumbnail {
|
|
url := fmt.Sprintf("%s&x=%d&y=%d", base, box, box)
|
|
return &libregraph.Thumbnail{Url: &url}
|
|
}
|
|
|
|
// setShareThumbnails works off the driveItem, the share listings have no resource
|
|
// info. The id comes separately, a received share carries it on its remote item.
|
|
func setShareThumbnails(item *libregraph.DriveItem, itemID, baseURL string) {
|
|
mimeType := item.GetFile().MimeType
|
|
if itemID == "" || mimeType == nil || !thumbnail.IsMimeTypeSupported(*mimeType) {
|
|
return
|
|
}
|
|
item.SetThumbnails([]libregraph.ThumbnailSet{*thumbnailSetFor(baseURL, itemID)})
|
|
}
|