Skip to content

armgit / ente

Public Imported from GitHub
0

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

Hook APIs to get file or thumbnail from fileLink

Neeraj Gupta2d0d914fd3d9
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.go
index 5533a17563..e006f9c2a5 100644
--- a/server/cmd/museum/main.go
+++ b/server/cmd/museum/main.go
@@ -597,6 +597,10 @@ func main() {
StorageBonusController: storageBonusCtrl,
}
+ fileLinkApi.GET("/info", fileHandler.LinkInfo)
+ fileLinkApi.GET("/thumbnail", fileHandler.LinkThumbnail)
+ fileLinkApi.GET("/file", fileHandler.LinkFile)
+
publicCollectionAPI.GET("/files/preview/:fileID", publicCollectionHandler.GetThumbnail)
publicCollectionAPI.GET("/files/download/:fileID", publicCollectionHandler.GetFile)
publicCollectionAPI.GET("/files/data/fetch", publicCollectionHandler.GetFileData)
diff --git a/server/ente/file_link.go b/server/ente/file_link.go
index a69034bf11..e817e35da0 100644
--- a/server/ente/file_link.go
+++ b/server/ente/file_link.go
@@ -90,4 +90,5 @@ type FileLinkAccessContext struct {
IP string
UserAgent string
FileID int64
+ OwnerID int64
}
diff --git a/server/pkg/api/file_url.go b/server/pkg/api/file_url.go
index 1780345bfc..aefb47daba 100644
--- a/server/pkg/api/file_url.go
+++ b/server/pkg/api/file_url.go
@@ -2,6 +2,7 @@ package api
import (
"github.com/ente-io/museum/ente"
+ "github.com/ente-io/museum/pkg/utils/auth"
"github.com/ente-io/museum/pkg/utils/handler"
"github.com/ente-io/stacktrace"
"github.com/gin-gonic/gin"
@@ -25,6 +26,30 @@ func (h *FileHandler) ShareUrl(c *gin.Context) {
c.JSON(http.StatusOK, response)
}
+func (h *FileHandler) LinkInfo(c *gin.Context) {
+
+}
+
+func (h *FileHandler) LinkThumbnail(c *gin.Context) {
+ linkCtx := auth.MustGetFileLinkAccessContext(c)
+ url, err := h.Controller.GetThumbnailURL(c, linkCtx.OwnerID, linkCtx.FileID)
+ if err != nil {
+ handler.Error(c, stacktrace.Propagate(err, ""))
+ return
+ }
+ c.Redirect(http.StatusTemporaryRedirect, url)
+}
+
+func (h *FileHandler) LinkFile(c *gin.Context) {
+ linkCtx := auth.MustGetFileLinkAccessContext(c)
+ url, err := h.Controller.GetFileURL(c, linkCtx.OwnerID, linkCtx.FileID)
+ if err != nil {
+ handler.Error(c, stacktrace.Propagate(err, ""))
+ return
+ }
+ c.Redirect(http.StatusTemporaryRedirect, url)
+}
+
func (h *FileHandler) DisableUrl(c *gin.Context) {
cID, err := strconv.ParseInt(c.Param("fileID"), 10, 64)
if err != nil {
diff --git a/server/pkg/middleware/file_link.go b/server/pkg/middleware/file_link.go
index d861e9f0f4..e5dcf48a3d 100644
--- a/server/pkg/middleware/file_link.go
+++ b/server/pkg/middleware/file_link.go
@@ -106,6 +106,7 @@ func (m *FileLinkMiddleware) Authenticate(urlSanitizer func(_ *gin.Context) stri
IP: clientIP,
UserAgent: userAgent,
FileID: fileLinkRow.FileID,
+ OwnerID: fileLinkRow.OwnerID,
})
c.Next()
}
@@ -151,8 +152,11 @@ func (m *FileLinkMiddleware) isDeviceLimitReached(ctx context.Context,
}
// validatePassword will verify if the user is provided correct password for the public album
-func (m *FileLinkMiddleware) validatePassword(c *gin.Context, reqPath string,
- fileLinkRow *ente.FileLinkRow) error {
+func (m *FileLinkMiddleware) validatePassword(
+ c *gin.Context,
+ reqPath string,
+ fileLinkRow *ente.FileLinkRow,
+) error {
accessTokenJWT := auth.GetAccessTokenJWT(c)
if accessTokenJWT == "" {
if array.StringInList(reqPath, filePasswordWhiteListedURLs) {