π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add upload eligibility endpoint
Neeraj Gupta5de4a8cdf506
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.goindex 36ccef410e..8f7bad938f 100644--- a/server/cmd/museum/main.go+++ b/server/cmd/museum/main.go@@ -569,6 +569,7 @@ func main() {FileUrlCtrl: fileLinkCtrl,}pasteHandler := &api.PasteHandler{Controller: pasteCtrl}+ privateAPI.GET("/files/upload-eligibility", fileHandler.ValidateUploadEligibility)privateAPI.GET("/files/upload-urls", fileHandler.GetUploadURLs)privateAPI.GET("/files/multipart-upload-urls", fileHandler.GetMultipartUploadURLs)privateAPI.POST("/files/upload-url", fileHandler.GetUploadURLV2)diff --git a/server/pkg/api/file.go b/server/pkg/api/file.goindex b7ed0f4a69..caae591b8d 100644--- a/server/pkg/api/file.go+++ b/server/pkg/api/file.go@@ -150,6 +150,17 @@ func (h *FileHandler) GetUploadURLs(c *gin.Context) {})}+// ValidateUploadEligibility verifies that the user can upload without minting upload URLs.+func (h *FileHandler) ValidateUploadEligibility(c *gin.Context) {+ enteApp := auth.GetApp(c)+ userID := auth.GetUserID(c.Request.Header)+ if err := h.Controller.ValidateUploadEligibility(c, userID, enteApp); err != nil {+ handler.Error(c, stacktrace.Propagate(err, ""))+ return+ }+ c.Status(http.StatusOK)+}+// GetUploadURLV2 returns a single upload URL that enforces checksum + content-length headersfunc (h *FileHandler) GetUploadURLV2(c *gin.Context) {enteApp := auth.GetApp(c)diff --git a/server/pkg/controller/file.go b/server/pkg/controller/file.goindex 00872ddf80..11a821733c 100644--- a/server/pkg/controller/file.go+++ b/server/pkg/controller/file.go@@ -347,6 +347,14 @@ func (c *FileController) GetUploadURLs(ctx context.Context, userID int64, countreturn urls, nil}+// ValidateUploadEligibility checks if a user is allowed to upload without minting upload URLs.+func (c *FileController) ValidateUploadEligibility(ctx context.Context, userID int64, app ente.App) error {+ if err := c.UsageCtrl.CanUploadFile(ctx, userID, nil, app); err != nil {+ return stacktrace.Propagate(err, "")+ }+ return nil+}+// GetUploadURLWithMetadata returns a single presigned URL that enforces checksum & lengthfunc (c *FileController) GetUploadURLWithMetadata(ctx context.Context, userID int64, req ente.UploadURLRequest, app ente.App) (ente.UploadURL, error) {if req.ContentLength <= 0 {