π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add HLS video streaming endpoints for public memory shares
AmanRajSinghMourya6271ad6fac2c
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.goindex f2a695796a..1fae34410c 100644--- a/server/cmd/museum/main.go+++ b/server/cmd/museum/main.go@@ -736,7 +736,8 @@ func main() {Controller: memoryShareController,}publicMemoryShareHandler := &api.PublicMemoryShareHandler{- PublicCtrl: memorySharePublicController,+ PublicCtrl: memorySharePublicController,+ FileDataCtrl: fileDataCtrl,}privateAPI.POST("/memory-share", memoryShareHandler.Create)@@ -747,6 +748,9 @@ func main() {publicMemoryAPI.GET("/info", publicMemoryShareHandler.GetInfo)publicMemoryAPI.GET("/files", publicMemoryShareHandler.GetFiles)publicMemoryAPI.GET("/files/preview/:fileID", publicMemoryShareHandler.GetThumbnail)+ publicMemoryAPI.GET("/files/:fileID", publicMemoryShareHandler.GetFile)+ publicMemoryAPI.GET("/file-data", publicMemoryShareHandler.GetFileData)+ publicMemoryAPI.GET("/files/data/preview", publicMemoryShareHandler.GetPreviewURL)castAPI := server.Group("/cast")@@ -1236,6 +1240,7 @@ func cacheHeaders() gin.HandlerFunc {strings.HasPrefix(reqPath, "/public-collection/files/preview/") ||strings.HasPrefix(reqPath, "/public-collection/files/download/") ||strings.HasPrefix(reqPath, "/public-memory/files/preview/") ||+ strings.HasPrefix(reqPath, "/public-memory/files/") ||strings.HasPrefix(reqPath, "/cast/files/preview/") ||strings.HasPrefix(reqPath, "/cast/files/download/") {// Exclude those that redirect to S3 for file downloads.diff --git a/server/pkg/api/public_memory_share.go b/server/pkg/api/public_memory_share.goindex 36d667f7be..9b06d62802 100644--- a/server/pkg/api/public_memory_share.go+++ b/server/pkg/api/public_memory_share.go@@ -5,6 +5,8 @@ import ("strconv""github.com/ente-io/museum/ente"+ fileData "github.com/ente-io/museum/ente/filedata"+ "github.com/ente-io/museum/pkg/controller/filedata""github.com/ente-io/museum/pkg/controller/public""github.com/ente-io/museum/pkg/utils/auth""github.com/ente-io/museum/pkg/utils/handler"@@ -14,7 +16,8 @@ import (// PublicMemoryShareHandler exposes request handlers for publicly accessible memory sharestype PublicMemoryShareHandler struct {- PublicCtrl *public.MemoryShareController+ PublicCtrl *public.MemoryShareController+ FileDataCtrl *filedata.Controller}// GetInfo returns the public memory share metadata@@ -50,6 +53,73 @@ func (h *PublicMemoryShareHandler) GetThumbnail(c *gin.Context) {h.getFileForType(c, ente.THUMBNAIL)}+// GetFile redirects to the file's full location+func (h *PublicMemoryShareHandler) GetFile(c *gin.Context) {+ h.getFileForType(c, ente.FILE)+}++// GetFileData returns HLS playlist data for video streaming+func (h *PublicMemoryShareHandler) GetFileData(c *gin.Context) {+ var req fileData.GetFileData+ if err := c.ShouldBindQuery(&req); err != nil {+ handler.Error(c, ente.NewBadRequestWithMessage(err.Error()))+ return+ }+ if req.Type != ente.PreviewVideo {+ handler.Error(c, ente.NewBadRequestWithMessage("unsupported object type"))+ return+ }++ accessCtx := auth.MustGetMemoryShareAccessContext(c)+ exists, ownerID, err := h.PublicCtrl.Repo.FileExistsInShare(c, accessCtx.ShareID, req.FileID)+ if err != nil {+ handler.Error(c, stacktrace.Propagate(err, "failed to check file existence"))+ return+ }+ if !exists {+ handler.Error(c, ente.ErrNotFound)+ return+ }++ resp, err := h.FileDataCtrl.GetFileData(c, ownerID, req)+ if err != nil {+ handler.Error(c, err)+ return+ }+ if resp == nil {+ c.Status(http.StatusNoContent)+ return+ }+ c.JSON(http.StatusOK, gin.H{"data": resp})+}++// GetPreviewURL returns pre-signed URL for video preview data+func (h *PublicMemoryShareHandler) GetPreviewURL(c *gin.Context) {+ var req fileData.GetPreviewURLRequest+ if err := c.ShouldBindQuery(&req); err != nil {+ handler.Error(c, ente.NewBadRequestWithMessage(err.Error()))+ return+ }++ accessCtx := auth.MustGetMemoryShareAccessContext(c)+ exists, ownerID, err := h.PublicCtrl.Repo.FileExistsInShare(c, accessCtx.ShareID, req.FileID)+ if err != nil {+ handler.Error(c, stacktrace.Propagate(err, "failed to check file existence"))+ return+ }+ if !exists {+ handler.Error(c, ente.ErrNotFound)+ return+ }++ url, err := h.FileDataCtrl.GetPreviewUrl(c, ownerID, req)+ if err != nil {+ handler.Error(c, stacktrace.Propagate(err, "failed to get preview URL"))+ return+ }+ c.JSON(http.StatusOK, gin.H{"url": url})+}+func (h *PublicMemoryShareHandler) getFileForType(c *gin.Context, objType ente.ObjectType) {fileID, err := strconv.ParseInt(c.Param("fileID"), 10, 64)if err != nil {