Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add support for accessing preview url for public collections

Neeraj Gupta51235bf81bcd
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.go
index f3a92cf210..af222d4d37 100644
--- a/server/cmd/museum/main.go
+++ b/server/cmd/museum/main.go
@@ -570,6 +570,8 @@ func main() {
publicCollectionAPI.GET("/files/preview/:fileID", publicCollectionHandler.GetThumbnail)
publicCollectionAPI.GET("/files/download/:fileID", publicCollectionHandler.GetFile)
+ publicCollectionAPI.GET("/files/data/fetch", publicCollectionHandler.GetFileData)
+ publicCollectionAPI.GET("/files/data/preview", publicCollectionHandler.GetPreviewURL)
publicCollectionAPI.GET("/diff", publicCollectionHandler.GetDiff)
publicCollectionAPI.GET("/info", publicCollectionHandler.GetCollection)
publicCollectionAPI.GET("/upload-urls", publicCollectionHandler.GetUploadUrls)
diff --git a/server/pkg/api/public_collection.go b/server/pkg/api/public_collection.go
index 2561c8011b..bf33a907fe 100644
--- a/server/pkg/api/public_collection.go
+++ b/server/pkg/api/public_collection.go
@@ -2,7 +2,9 @@ package api
import (
"fmt"
+ fileData "github.com/ente-io/museum/ente/filedata"
"github.com/ente-io/museum/pkg/controller/collections"
+ "github.com/ente-io/museum/pkg/controller/filedata"
"net/http"
"strconv"
@@ -21,6 +23,7 @@ type PublicCollectionHandler struct {
Controller *controller.PublicCollectionController
FileCtrl *controller.FileController
CollectionCtrl *collections.CollectionController
+ FileDataCtrl *filedata.Controller
StorageBonusController *storagebonus.Controller
}
@@ -34,6 +37,65 @@ func (h *PublicCollectionHandler) GetFile(c *gin.Context) {
h.getFileForType(c, ente.FILE)
}
+func (h *PublicCollectionHandler) GetPreviewURL(c *gin.Context) {
+ var req fileData.GetPreviewURLRequest
+ if err := c.ShouldBindQuery(&req); err != nil {
+ handler.Error(c, stacktrace.Propagate(ente.ErrBadRequest, fmt.Sprintf("Request binding failed %s", err)))
+ return
+ }
+ collectionOwner, err := h.getCollectionOwnerAndVerifyAccess(c, req.FileID)
+ if err != nil {
+ handler.Error(c, stacktrace.Propagate(err, ""))
+ return
+ }
+ url, err := h.FileDataCtrl.GetPreviewUrl(c, *collectionOwner, req)
+ if err != nil {
+ handler.Error(c, stacktrace.Propagate(err, ""))
+ return
+ }
+ c.JSON(http.StatusOK, gin.H{
+ "url": url,
+ })
+}
+
+func (h *PublicCollectionHandler) GetFileData(c *gin.Context) {
+ var req fileData.GetFileData
+ if err := c.ShouldBindQuery(&req); err != nil {
+ c.JSON(http.StatusBadRequest, ente.NewBadRequestWithMessage(err.Error()))
+ return
+ }
+ if req.Type != ente.PreviewVideo {
+ errorMessage := fmt.Sprintf("unsupported object type %s", req.Type)
+ handler.Error(c, stacktrace.Propagate(ente.NewBadRequestWithMessage(errorMessage), ""))
+ return
+ }
+ collectionOwner, err := h.getCollectionOwnerAndVerifyAccess(c, req.FileID)
+ if err != nil {
+ handler.Error(c, stacktrace.Propagate(err, ""))
+ return
+ }
+ resp, err := h.FileDataCtrl.GetFileData(c, *collectionOwner, req)
+ if err != nil {
+ handler.Error(c, err)
+ return
+ }
+ c.JSON(http.StatusOK, gin.H{
+ "data": resp,
+ })
+}
+
+func (h *PublicCollectionHandler) getCollectionOwnerAndVerifyAccess(c *gin.Context, fileID int64) (*int64, error) {
+ accessContext := auth.MustGetPublicAccessContext(c)
+ if accessErr := h.FileCtrl.DoesFileExistInCollection(c, fileID, accessContext.CollectionID); accessErr != nil {
+ return nil, stacktrace.Propagate(accessErr, "")
+ }
+ collection, err := h.Controller.GetPublicCollection(c, false)
+ if err != nil {
+ return nil, stacktrace.Propagate(err, "")
+ }
+ return &collection.Owner.ID, nil
+}
+
// GetCollection redirects the request to the collection location
func (h *PublicCollectionHandler) GetCollection(c *gin.Context) {
collection, err := h.Controller.GetPublicCollection(c, false)