π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add support for accessing preview url for public collections
Neeraj Gupta51235bf81bcd
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.goindex 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.goindex 2561c8011b..bf33a907fe 100644--- a/server/pkg/api/public_collection.go+++ b/server/pkg/api/public_collection.go@@ -2,7 +2,9 @@ package apiimport ("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.PublicCollectionControllerFileCtrl *controller.FileControllerCollectionCtrl *collections.CollectionController+ FileDataCtrl *filedata.ControllerStorageBonusController *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 locationfunc (h *PublicCollectionHandler) GetCollection(c *gin.Context) {collection, err := h.Controller.GetPublicCollection(c, false)