π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Rename
Neeraj Gupta8d108dc719f4
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.goindex 90845fbba9..ed731b51da 100644--- a/server/cmd/museum/main.go+++ b/server/cmd/museum/main.go@@ -6,6 +6,7 @@ import (b64 "encoding/base64""fmt""github.com/ente-io/museum/pkg/controller/collections"+ publicCtrl "github.com/ente-io/museum/pkg/controller/public""github.com/ente-io/museum/pkg/repo/public""net/http""os"@@ -300,7 +301,7 @@ func main() {UsageRepo: usageRepo,}- publicCollectionCtrl := &controller.PublicCollectionController{+ collectionLinkCtrl := &publicCtrl.CollectionLinkController{FileController: fileController,EmailNotificationCtrl: emailNotificationCtrl,PublicCollectionRepo: publicCollectionRepo,@@ -310,16 +311,16 @@ func main() {}collectionController := &collections.CollectionController{- CollectionRepo: collectionRepo,- EmailCtrl: emailNotificationCtrl,- AccessCtrl: accessCtrl,- PublicCollectionCtrl: publicCollectionCtrl,- UserRepo: userRepo,- FileRepo: fileRepo,- CastRepo: &castDb,- BillingCtrl: billingController,- QueueRepo: queueRepo,- TaskRepo: taskLockingRepo,+ CollectionRepo: collectionRepo,+ EmailCtrl: emailNotificationCtrl,+ AccessCtrl: accessCtrl,+ CollectionLinkController: collectionLinkCtrl,+ UserRepo: userRepo,+ FileRepo: fileRepo,+ CastRepo: &castDb,+ BillingCtrl: billingController,+ QueueRepo: queueRepo,+ TaskRepo: taskLockingRepo,}kexCtrl := &kexCtrl.Controller{@@ -360,7 +361,7 @@ func main() {authMiddleware := middleware.AuthMiddleware{UserAuthRepo: userAuthRepo, Cache: authCache, UserController: userController}collectionTokenMiddleware := middleware.CollectionTokenMiddleware{PublicCollectionRepo: publicCollectionRepo,- PublicCollectionCtrl: publicCollectionCtrl,+ PublicCollectionCtrl: collectionLinkCtrl,CollectionRepo: collectionRepo,Cache: accessTokenCache,BillingCtrl: billingController,@@ -568,7 +569,7 @@ func main() {privateAPI.PUT("/collections/sharee-magic-metadata", collectionHandler.ShareeMagicMetadataUpdate)publicCollectionHandler := &api.PublicCollectionHandler{- Controller: publicCollectionCtrl,+ Controller: collectionLinkCtrl,FileCtrl: fileController,CollectionCtrl: collectionController,FileDataCtrl: fileDataCtrl,diff --git a/server/ente/jwt/jwt.go b/server/ente/jwt/jwt.goindex 94cfa995f2..c4d210b66c 100644--- a/server/ente/jwt/jwt.go+++ b/server/ente/jwt/jwt.go@@ -40,13 +40,13 @@ func (w WebCommonJWTClaim) Valid() error {return nil}-// PublicAlbumPasswordClaim refer to token granted post public album password verification-type PublicAlbumPasswordClaim struct {+// LinkPasswordClaim refer to token granted post link password verification+type LinkPasswordClaim struct {PassHash string `json:"passKey"`ExpiryTime int64 `json:"expiryTime"`}-func (c PublicAlbumPasswordClaim) Valid() error {+func (c LinkPasswordClaim) Valid() error {if c.ExpiryTime < time.Microseconds() {return errors.New("token expired")}diff --git a/server/ente/public_collection.go b/server/ente/public_collection.goindex eb1bd8c385..f34c0bf2f1 100644--- a/server/ente/public_collection.go+++ b/server/ente/public_collection.go@@ -40,8 +40,8 @@ type VerifyPasswordResponse struct {JWTToken string `json:"jwtToken"`}-// PublicCollectionToken represents row entity for public_collection_token table-type PublicCollectionToken struct {+// CollectionLinkRow represents row entity for public_collection_token table+type CollectionLinkRow struct {ID int64CollectionID int64Token string@@ -57,7 +57,7 @@ type PublicCollectionToken struct {EnableJoin bool}-func (p PublicCollectionToken) CanJoin() error {+func (p CollectionLinkRow) CanJoin() error {if p.IsDisabled {return NewBadRequestWithMessage("link disabled")}diff --git a/server/pkg/api/collection.go b/server/pkg/api/collection.goindex 9318f5c329..d5f918c672 100644--- a/server/pkg/api/collection.go+++ b/server/pkg/api/collection.go@@ -3,6 +3,7 @@ package apiimport ("fmt""github.com/ente-io/museum/pkg/controller/collections"+ "github.com/ente-io/museum/pkg/controller/public""net/http""strconv"@@ -10,7 +11,6 @@ import (log "github.com/sirupsen/logrus""github.com/ente-io/museum/ente"- "github.com/ente-io/museum/pkg/controller""github.com/ente-io/museum/pkg/utils/auth""github.com/ente-io/museum/pkg/utils/handler""github.com/ente-io/museum/pkg/utils/time"@@ -178,7 +178,7 @@ func (h *CollectionHandler) UpdateShareURL(c *gin.Context) {return}- if req.DeviceLimit != nil && (*req.DeviceLimit < 0 || *req.DeviceLimit > controller.DeviceLimitThreshold) {+ if req.DeviceLimit != nil && (*req.DeviceLimit < 0 || *req.DeviceLimit > public.DeviceLimitThreshold) {handler.Error(c, stacktrace.Propagate(ente.ErrBadRequest, fmt.Sprintf("device limit: %d out of range", *req.DeviceLimit)))return}diff --git a/server/pkg/api/file.go b/server/pkg/api/file.goindex 1de2880de6..4ec205d1bb 100644--- a/server/pkg/api/file.go+++ b/server/pkg/api/file.go@@ -4,6 +4,7 @@ import ("fmt""github.com/ente-io/museum/pkg/controller/file_copy""github.com/ente-io/museum/pkg/controller/filedata"+ "github.com/ente-io/museum/pkg/controller/public""net/http""os""strconv"@@ -24,7 +25,7 @@ import (// FileHandler exposes request handlers for all encrypted file related requeststype FileHandler struct {Controller *controller.FileController- FileUrlCtrl *controller.PublicFileLinkController+ FileUrlCtrl *public.FileLinkControllerFileCopyCtrl *file_copy.FileCopyControllerFileDataCtrl *filedata.Controller}diff --git a/server/pkg/api/file_url.go b/server/pkg/api/file_url.goindex 2e9da338dc..9073a0a331 100644--- a/server/pkg/api/file_url.go+++ b/server/pkg/api/file_url.go@@ -16,7 +16,7 @@ func (h *FileHandler) ShareUrl(c *gin.Context) {return}- response, err := h.FileUrlCtrl.CreateFileUrl(c, file)+ response, err := h.FileUrlCtrl.CreateLink(c, file)if err != nil {handler.Error(c, stacktrace.Propagate(err, ""))returndiff --git a/server/pkg/api/public_collection.go b/server/pkg/api/public_collection.goindex 9f61ba788e..81e1836f90 100644--- a/server/pkg/api/public_collection.go+++ b/server/pkg/api/public_collection.go@@ -5,6 +5,7 @@ import (fileData "github.com/ente-io/museum/ente/filedata""github.com/ente-io/museum/pkg/controller/collections""github.com/ente-io/museum/pkg/controller/filedata"+ "github.com/ente-io/museum/pkg/controller/public""net/http""strconv"@@ -20,7 +21,7 @@ import (// PublicCollectionHandler exposes request handlers for publicly accessible collectionstype PublicCollectionHandler struct {- Controller *controller.PublicCollectionController+ Controller *public.CollectionLinkControllerFileCtrl *controller.FileControllerCollectionCtrl *collections.CollectionControllerFileDataCtrl *filedata.Controllerdiff --git a/server/pkg/controller/collections/collection.go b/server/pkg/controller/collections/collection.goindex 5f096bc133..52a36df782 100644--- a/server/pkg/controller/collections/collection.go+++ b/server/pkg/controller/collections/collection.go@@ -6,6 +6,7 @@ import ("github.com/ente-io/museum/pkg/controller""github.com/ente-io/museum/pkg/controller/access""github.com/ente-io/museum/pkg/controller/email"+ "github.com/ente-io/museum/pkg/controller/public""github.com/ente-io/museum/pkg/repo/cast""github.com/ente-io/museum/pkg/utils/array""github.com/ente-io/museum/pkg/utils/auth"@@ -24,16 +25,16 @@ const (// CollectionController encapsulates logic that deals with collectionstype CollectionController struct {- PublicCollectionCtrl *controller.PublicCollectionController- EmailCtrl *email.EmailNotificationController- AccessCtrl access.Controller- BillingCtrl *controller.BillingController- CollectionRepo *repo.CollectionRepository- UserRepo *repo.UserRepository- FileRepo *repo.FileRepository- QueueRepo *repo.QueueRepository- CastRepo *cast.Repository- TaskRepo *repo.TaskLockRepository+ CollectionLinkController *public.CollectionLinkController+ EmailCtrl *email.EmailNotificationController+ AccessCtrl access.Controller+ BillingCtrl *controller.BillingController+ CollectionRepo *repo.CollectionRepository+ UserRepo *repo.UserRepository+ FileRepo *repo.FileRepository+ QueueRepo *repo.QueueRepository+ CastRepo *cast.Repository+ TaskRepo *repo.TaskLockRepository}// Create creates a collection@@ -148,7 +149,7 @@ func (c *CollectionController) TrashV3(ctx *gin.Context, req ente.TrashCollectio}}- err = c.PublicCollectionCtrl.Disable(ctx, cID)+ err = c.CollectionLinkController.Disable(ctx, cID)if err != nil {return stacktrace.Propagate(err, "failed to disabled public share url")}@@ -209,7 +210,7 @@ func (c *CollectionController) HandleAccountDeletion(ctx context.Context, userIDif err != nil {return stacktrace.Propagate(err, "failed to revoke cast token for user")}- err = c.PublicCollectionCtrl.HandleAccountDeletion(ctx, userID, logger)+ err = c.CollectionLinkController.HandleAccountDeletion(ctx, userID, logger)return stacktrace.Propagate(err, "")}diff --git a/server/pkg/controller/collections/share.go b/server/pkg/controller/collections/share.goindex ced64f0fdf..7651266ece 100644--- a/server/pkg/controller/collections/share.go+++ b/server/pkg/controller/collections/share.go@@ -70,21 +70,21 @@ func (c *CollectionController) JoinViaLink(ctx *gin.Context, req ente.JoinCollecif !collection.AllowSharing() {return stacktrace.Propagate(ente.ErrBadRequest, fmt.Sprintf("joining %s is not allowed", collection.Type))}- publicCollectionToken, err := c.PublicCollectionCtrl.GetActivePublicCollectionToken(ctx, req.CollectionID)+ collectionLinkToken, err := c.CollectionLinkController.GetActiveCollectionLinkToken(ctx, req.CollectionID)if err != nil {return stacktrace.Propagate(err, "")}- if canJoin := publicCollectionToken.CanJoin(); canJoin != nil {+ if canJoin := collectionLinkToken.CanJoin(); canJoin != nil {return stacktrace.Propagate(ente.ErrBadRequest, fmt.Sprintf("can not join collection: %s", canJoin.Error()))}accessToken := auth.GetAccessToken(ctx)- if publicCollectionToken.Token != accessToken {+ if collectionLinkToken.Token != accessToken {return stacktrace.Propagate(ente.ErrPermissionDenied, "token doesn't match collection")}- if publicCollectionToken.PassHash != nil && *publicCollectionToken.PassHash != "" {+ if collectionLinkToken.PassHash != nil && *collectionLinkToken.PassHash != "" {accessTokenJWT := auth.GetAccessTokenJWT(ctx)- if passCheckErr := c.PublicCollectionCtrl.ValidateJWTToken(ctx, accessTokenJWT, *publicCollectionToken.PassHash); passCheckErr != nil {+ if passCheckErr := c.CollectionLinkController.ValidateJWTToken(ctx, accessTokenJWT, *collectionLinkToken.PassHash); passCheckErr != nil {return stacktrace.Propagate(passCheckErr, "")}}@@ -93,7 +93,7 @@ func (c *CollectionController) JoinViaLink(ctx *gin.Context, req ente.JoinCollecreturn stacktrace.Propagate(err, "")}role := ente.VIEWER- if publicCollectionToken.EnableCollect {+ if collectionLinkToken.EnableCollect {role = ente.COLLABORATOR}joinErr := c.CollectionRepo.Share(req.CollectionID, collection.Owner.ID, userID, req.EncryptedKey, role, time.Microseconds())@@ -197,7 +197,7 @@ func (c *CollectionController) ShareURL(ctx context.Context, userID int64, req eif err != nil {return ente.PublicURL{}, stacktrace.Propagate(err, "")}- response, err := c.PublicCollectionCtrl.CreateAccessToken(ctx, req)+ response, err := c.CollectionLinkController.CreateLink(ctx, req)if err != nil {return ente.PublicURL{}, stacktrace.Propagate(err, "")}@@ -214,7 +214,7 @@ func (c *CollectionController) UpdateShareURL(ctx context.Context, userID int64,if err != nil {return ente.PublicURL{}, stacktrace.Propagate(err, "")}- response, err := c.PublicCollectionCtrl.UpdateSharedUrl(ctx, req)+ response, err := c.CollectionLinkController.UpdateSharedUrl(ctx, req)if err != nil {return ente.PublicURL{}, stacktrace.Propagate(err, "")}@@ -226,7 +226,7 @@ func (c *CollectionController) DisableSharedURL(ctx context.Context, userID int6if err := c.verifyOwnership(cID, userID); err != nil {return stacktrace.Propagate(err, "")}- err := c.PublicCollectionCtrl.Disable(ctx, cID)+ err := c.CollectionLinkController.Disable(ctx, cID)return stacktrace.Propagate(err, "")}diff --git a/server/pkg/controller/public_collection.go b/server/pkg/controller/public/collection_link.gosimilarity index 86%rename from server/pkg/controller/public_collection.gorename to server/pkg/controller/public/collection_link.goindex 7f51a46330..1c47b04cd9 100644--- a/server/pkg/controller/public_collection.go+++ b/server/pkg/controller/public/collection_link.go@@ -1,9 +1,10 @@-package controller+package publicimport ("context""errors""fmt"+ "github.com/ente-io/museum/pkg/controller""github.com/ente-io/museum/pkg/repo/public""github.com/ente-io/museum/ente"@@ -50,9 +51,9 @@ const (AbuseLimitExceededTemplate = "report_limit_exceeded_alert.html")-// PublicCollectionController controls share collection operations-type PublicCollectionController struct {- FileController *FileController+// CollectionLinkController controls share collection operations+type CollectionLinkController struct {+ FileController *controller.FileControllerEmailNotificationCtrl *emailCtrl.EmailNotificationControllerPublicCollectionRepo *public.PublicCollectionRepositoryCollectionRepo *repo.CollectionRepository@@ -60,7 +61,7 @@ type PublicCollectionController struct {JwtSecret []byte}-func (c *PublicCollectionController) CreateAccessToken(ctx context.Context, req ente.CreatePublicAccessTokenRequest) (ente.PublicURL, error) {+func (c *CollectionLinkController) CreateLink(ctx context.Context, req ente.CreatePublicAccessTokenRequest) (ente.PublicURL, error) {accessToken := shortuuid.New()[0:AccessTokenLength]err := c.PublicCollectionRepo.Insert(ctx, req.CollectionID, accessToken, req.ValidTill, req.DeviceLimit, req.EnableCollect, req.EnableJoin)@@ -92,11 +93,11 @@ func (c *PublicCollectionController) CreateAccessToken(ctx context.Context, reqreturn response, nil}-func (c *PublicCollectionController) GetActivePublicCollectionToken(ctx context.Context, collectionID int64) (ente.PublicCollectionToken, error) {+func (c *CollectionLinkController) GetActiveCollectionLinkToken(ctx context.Context, collectionID int64) (ente.CollectionLinkRow, error) {return c.PublicCollectionRepo.GetActivePublicCollectionToken(ctx, collectionID)}-func (c *PublicCollectionController) CreateFile(ctx *gin.Context, file ente.File, app ente.App) (ente.File, error) {+func (c *CollectionLinkController) CreateFile(ctx *gin.Context, file ente.File, app ente.App) (ente.File, error) {collection, err := c.GetPublicCollection(ctx, true)if err != nil {return ente.File{}, stacktrace.Propagate(err, "")@@ -119,12 +120,12 @@ func (c *PublicCollectionController) CreateFile(ctx *gin.Context, file ente.File}// Disable all public accessTokens generated for the given cID till date.-func (c *PublicCollectionController) Disable(ctx context.Context, cID int64) error {+func (c *CollectionLinkController) Disable(ctx context.Context, cID int64) error {err := c.PublicCollectionRepo.DisableSharing(ctx, cID)return stacktrace.Propagate(err, "")}-func (c *PublicCollectionController) UpdateSharedUrl(ctx context.Context, req ente.UpdatePublicAccessTokenRequest) (ente.PublicURL, error) {+func (c *CollectionLinkController) UpdateSharedUrl(ctx context.Context, req ente.UpdatePublicAccessTokenRequest) (ente.PublicURL, error) {publicCollectionToken, err := c.PublicCollectionRepo.GetActivePublicCollectionToken(ctx, req.CollectionID)if err != nil {return ente.PublicURL{}, err@@ -177,7 +178,7 @@ func (c *PublicCollectionController) UpdateSharedUrl(ctx context.Context, req en// used by the client to pass in other requests for public collection.// Having a separate endpoint for password validation allows us to easily rate-limit the attempts for brute-force// attack for guessing password.-func (c *PublicCollectionController) VerifyPassword(ctx *gin.Context, req ente.VerifyPasswordRequest) (*ente.VerifyPasswordResponse, error) {+func (c *CollectionLinkController) VerifyPassword(ctx *gin.Context, req ente.VerifyPasswordRequest) (*ente.VerifyPasswordResponse, error) {accessContext := auth.MustGetPublicAccessContext(ctx)publicCollectionToken, err := c.PublicCollectionRepo.GetActivePublicCollectionToken(ctx, accessContext.CollectionID)if err != nil {@@ -189,7 +190,7 @@ func (c *PublicCollectionController) VerifyPassword(ctx *gin.Context, req ente.Vif req.PassHash != *publicCollectionToken.PassHash {return nil, stacktrace.Propagate(ente.ErrInvalidPassword, "incorrect password for link")}- token := jwt.NewWithClaims(jwt.SigningMethodHS256, &enteJWT.PublicAlbumPasswordClaim{+ token := jwt.NewWithClaims(jwt.SigningMethodHS256, &enteJWT.LinkPasswordClaim{PassHash: req.PassHash,ExpiryTime: time.NDaysFromNow(365),})@@ -204,8 +205,8 @@ func (c *PublicCollectionController) VerifyPassword(ctx *gin.Context, req ente.V}, nil}-func (c *PublicCollectionController) ValidateJWTToken(ctx *gin.Context, jwtToken string, passwordHash string) error {- token, err := jwt.ParseWithClaims(jwtToken, &enteJWT.PublicAlbumPasswordClaim{}, func(token *jwt.Token) (interface{}, error) {+func (c *CollectionLinkController) ValidateJWTToken(ctx *gin.Context, jwtToken string, passwordHash string) error {+ token, err := jwt.ParseWithClaims(jwtToken, &enteJWT.LinkPasswordClaim{}, func(token *jwt.Token) (interface{}, error) {if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {return stacktrace.Propagate(fmt.Errorf("unexpected signing method: %v", token.Header["alg"]), ""), nil}@@ -214,7 +215,7 @@ func (c *PublicCollectionController) ValidateJWTToken(ctx *gin.Context, jwtTokenif err != nil {return stacktrace.Propagate(err, "JWT parsed failed")}- claims, ok := token.Claims.(*enteJWT.PublicAlbumPasswordClaim)+ claims, ok := token.Claims.(*enteJWT.LinkPasswordClaim)if !ok {return stacktrace.Propagate(errors.New("no claim in jwt token"), "")@@ -228,7 +229,7 @@ func (c *PublicCollectionController) ValidateJWTToken(ctx *gin.Context, jwtToken// ReportAbuse captures abuse report for a publicly shared collection.// It will also disable the accessToken for the collection if total abuse reports for the said collection// reaches AutoDisableAbuseThreshold-func (c *PublicCollectionController) ReportAbuse(ctx *gin.Context, req ente.AbuseReportRequest) error {+func (c *CollectionLinkController) ReportAbuse(ctx *gin.Context, req ente.AbuseReportRequest) error {accessContext := auth.MustGetPublicAccessContext(ctx)readableReason, found := AllowedReasons[req.Reason]if !found {@@ -254,7 +255,7 @@ func (c *PublicCollectionController) ReportAbuse(ctx *gin.Context, req ente.Abusreturn nil}-func (c *PublicCollectionController) onAbuseReportReceived(collectionID int64, report ente.AbuseReportRequest, readableReason string, abuseCount int64) {+func (c *CollectionLinkController) onAbuseReportReceived(collectionID int64, report ente.AbuseReportRequest, readableReason string, abuseCount int64) {collection, err := c.CollectionRepo.Get(collectionID)if err != nil {logrus.Error("Could not get collection for abuse report")@@ -293,7 +294,7 @@ func (c *PublicCollectionController) onAbuseReportReceived(collectionID int64, r}}-func (c *PublicCollectionController) HandleAccountDeletion(ctx context.Context, userID int64, logger *logrus.Entry) error {+func (c *CollectionLinkController) HandleAccountDeletion(ctx context.Context, userID int64, logger *logrus.Entry) error {logger.Info("updating public collection on account deletion")collectionIDs, err := c.PublicCollectionRepo.GetActivePublicTokenForUser(ctx, userID)if err != nil {@@ -311,7 +312,7 @@ func (c *PublicCollectionController) HandleAccountDeletion(ctx context.Context,// GetPublicCollection will return collection info for a public url.// is mustAllowCollect is set to true but the underlying collection doesn't allow uploading-func (c *PublicCollectionController) GetPublicCollection(ctx *gin.Context, mustAllowCollect bool) (ente.Collection, error) {+func (c *CollectionLinkController) GetPublicCollection(ctx *gin.Context, mustAllowCollect bool) (ente.Collection, error) {accessContext := auth.MustGetPublicAccessContext(ctx)collection, err := c.CollectionRepo.Get(accessContext.CollectionID)if err != nil {diff --git a/server/pkg/controller/public_file.go b/server/pkg/controller/public/file_link.gosimilarity index 64%rename from server/pkg/controller/public_file.gorename to server/pkg/controller/public/file_link.goindex c74f1050df..bf1ad07865 100644--- a/server/pkg/controller/public_file.go+++ b/server/pkg/controller/public/file_link.go@@ -1,8 +1,8 @@-package controller+package publicimport ("github.com/ente-io/museum/ente"- emailCtrl "github.com/ente-io/museum/pkg/controller/email"+ "github.com/ente-io/museum/pkg/controller""github.com/ente-io/museum/pkg/repo""github.com/ente-io/museum/pkg/repo/public""github.com/ente-io/museum/pkg/utils/auth"@@ -11,18 +11,16 @@ import ("github.com/lithammer/shortuuid/v3")-// PublicFileLinkController controls share collection operations-type PublicFileLinkController struct {- FileController *FileController- EmailNotificationCtrl *emailCtrl.EmailNotificationController- PublicCollectionRepo *public.PublicCollectionRepository- FileLinkRepo *public.FileLinkRepository- CollectionRepo *repo.CollectionRepository- UserRepo *repo.UserRepository- JwtSecret []byte+// FileLinkController controls share collection operations+type FileLinkController struct {+ FileController *controller.FileController+ FileLinkRepo *public.FileLinkRepository+ CollectionRepo *repo.CollectionRepository+ UserRepo *repo.UserRepository+ JwtSecret []byte}-func (c *PublicFileLinkController) CreateFileUrl(ctx *gin.Context, req ente.CreateFileUrl) (*ente.FileUrl, error) {+func (c *FileLinkController) CreateLink(ctx *gin.Context, req ente.CreateFileUrl) (*ente.FileUrl, error) {actorUserID := auth.GetUserID(ctx.Request.Header)accessToken := shortuuid.New()[0:AccessTokenLength]_, err := c.FileLinkRepo.Insert(ctx, req.FileID, actorUserID, accessToken)@@ -36,7 +34,7 @@ func (c *PublicFileLinkController) CreateFileUrl(ctx *gin.Context, req ente.Creareturn nil, stacktrace.Propagate(err, "failed to create public file link")}-func (c *PublicFileLinkController) mapRowToFileUrl(ctx *gin.Context, row *ente.FileLinkRow) *ente.FileUrl {+func (c *FileLinkController) mapRowToFileUrl(ctx *gin.Context, row *ente.FileLinkRow) *ente.FileUrl {app := auth.GetApp(ctx)var url stringif app == ente.Locker {diff --git a/server/pkg/controller/public/link_common.go b/server/pkg/controller/public/link_common.gonew file mode 100644index 0000000000..9fd24e5c1e--- /dev/null+++ b/server/pkg/controller/public/link_common.go@@ -0,0 +1 @@+package publicdiff --git a/server/pkg/middleware/collection_token.go b/server/pkg/middleware/collection_token.goindex 079f6f6f95..37ff02458e 100644--- a/server/pkg/middleware/collection_token.go+++ b/server/pkg/middleware/collection_token.go@@ -5,6 +5,7 @@ import ("context""crypto/sha256""fmt"+ public2 "github.com/ente-io/museum/pkg/controller/public""github.com/ente-io/museum/pkg/repo/public""net/http"@@ -28,7 +29,7 @@ var whitelistedCollectionShareIDs = []int64{111}// CollectionTokenMiddleware intercepts and authenticates incoming requeststype CollectionTokenMiddleware struct {PublicCollectionRepo *public.PublicCollectionRepository- PublicCollectionCtrl *controller.PublicCollectionController+ PublicCollectionCtrl *public2.CollectionLinkControllerCollectionRepo *repo.CollectionRepositoryCache *cache.CacheBillingCtrl *controller.BillingController@@ -143,11 +144,11 @@ func (m *CollectionTokenMiddleware) isDeviceLimitReached(ctx context.Context,}deviceLimit := int64(collectionSummary.DeviceLimit)- if deviceLimit == controller.DeviceLimitThreshold {- deviceLimit = controller.DeviceLimitThresholdMultiplier * controller.DeviceLimitThreshold+ if deviceLimit == public2.DeviceLimitThreshold {+ deviceLimit = public2.DeviceLimitThresholdMultiplier * public2.DeviceLimitThreshold}- if count >= controller.DeviceLimitWarningThreshold {+ if count >= public2.DeviceLimitWarningThreshold {if !array.Int64InList(sharedID, whitelistedCollectionShareIDs) {m.DiscordController.NotifyPotentialAbuse(fmt.Sprintf("Album exceeds warning threshold: {CollectionID: %d, ShareID: %d}",diff --git a/server/pkg/middleware/file_link_token.go b/server/pkg/middleware/file_link_token.goindex 9ff26d2533..5c230882b5 100644--- a/server/pkg/middleware/file_link_token.go+++ b/server/pkg/middleware/file_link_token.go@@ -3,6 +3,7 @@ package middlewareimport ("context""fmt"+ publicCtrl "github.com/ente-io/museum/pkg/controller/public""github.com/ente-io/museum/pkg/repo/public""net/http"@@ -25,7 +26,7 @@ var filePasswordWhiteListedURLs = []string{"/public-collection/info", "/public-c// FileLinkMiddleware intercepts and authenticates incoming requeststype FileLinkMiddleware struct {FileLinkRepo *public.FileLinkRepository- PublicCollectionCtrl *controller.PublicCollectionController+ PublicCollectionCtrl *publicCtrl.CollectionLinkControllerCollectionRepo *repo.CollectionRepositoryCache *cache.CacheBillingCtrl *controller.BillingController@@ -140,13 +141,13 @@ func (m *FileLinkMiddleware) isDeviceLimitReached(ctx context.Context,}deviceLimit := int64(collectionSummary.DeviceLimit)- if deviceLimit == controller.DeviceLimitThreshold {- deviceLimit = controller.DeviceLimitThresholdMultiplier * controller.DeviceLimitThreshold+ if deviceLimit == publicCtrl.DeviceLimitThreshold {+ deviceLimit = publicCtrl.DeviceLimitThresholdMultiplier * publicCtrl.DeviceLimitThreshold}- if count >= controller.DeviceLimitWarningThreshold {+ if count >= publicCtrl.DeviceLimitWarningThreshold {m.DiscordController.NotifyPotentialAbuse(- fmt.Sprintf("Album exceeds warning threshold: {FileID: %d, ShareID: %s}",+ fmt.Sprintf("FileLink exceeds warning threshold: {FileID: %d, ShareID: %s}",collectionSummary.FileID, collectionSummary.LinkID))}diff --git a/server/pkg/repo/public/public_collection.go b/server/pkg/repo/public/public_collection.goindex 600c213c11..077d1889e8 100644--- a/server/pkg/repo/public/public_collection.go+++ b/server/pkg/repo/public/public_collection.go@@ -92,26 +92,26 @@ func (pcr *PublicCollectionRepository) GetCollectionToActivePublicURLMap(ctx conreturn result, nil}-// GetActivePublicCollectionToken will return ente.PublicCollectionToken for given collection ID+// GetActivePublicCollectionToken will return ente.CollectionLinkRow for given collection ID// Note: The token could be expired or deviceLimit is already reached-func (pcr *PublicCollectionRepository) GetActivePublicCollectionToken(ctx context.Context, collectionID int64) (ente.PublicCollectionToken, error) {+func (pcr *PublicCollectionRepository) GetActivePublicCollectionToken(ctx context.Context, collectionID int64) (ente.CollectionLinkRow, error) {row := pcr.DB.QueryRowContext(ctx, `SELECT id, collection_id, access_token, valid_till, device_limit,is_disabled, pw_hash, pw_nonce, mem_limit, ops_limit, enable_download, enable_collect, enable_join FROMpublic_collection_tokens WHERE collection_id = $1 and is_disabled = FALSE`,collectionID)//defer rows.Close()- ret := ente.PublicCollectionToken{}+ ret := ente.CollectionLinkRow{}err := row.Scan(&ret.ID, &ret.CollectionID, &ret.Token, &ret.ValidTill, &ret.DeviceLimit,&ret.IsDisabled, &ret.PassHash, &ret.Nonce, &ret.MemLimit, &ret.OpsLimit, &ret.EnableDownload, &ret.EnableCollect, &ret.EnableJoin)if err != nil {- return ente.PublicCollectionToken{}, stacktrace.Propagate(err, "")+ return ente.CollectionLinkRow{}, stacktrace.Propagate(err, "")}return ret, nil}// UpdatePublicCollectionToken will update the row for corresponding public collection token-func (pcr *PublicCollectionRepository) UpdatePublicCollectionToken(ctx context.Context, pct ente.PublicCollectionToken) error {+func (pcr *PublicCollectionRepository) UpdatePublicCollectionToken(ctx context.Context, pct ente.CollectionLinkRow) error {_, err := pcr.DB.ExecContext(ctx, `UPDATE public_collection_tokens SET valid_till = $1, device_limit = $2,pw_hash = $3, pw_nonce = $4, mem_limit = $5, ops_limit = $6, enable_download = $7, enable_collect = $8, enable_join = $9where id = $10`,diff --git a/server/pkg/repo/public/public_file.go b/server/pkg/repo/public/public_file.goindex 022a6ba7b0..20573031a7 100644--- a/server/pkg/repo/public/public_file.go+++ b/server/pkg/repo/public/public_file.go@@ -63,7 +63,7 @@ func (pcr *FileLinkRepository) Insert(return id, nil}-// GetActiveFileUrlToken will return ente.PublicCollectionToken for given collection ID+// GetActiveFileUrlToken will return ente.CollectionLinkRow for given collection ID// Note: The token could be expired or deviceLimit is already reachedfunc (pcr *FileLinkRepository) GetActiveFileUrlToken(ctx context.Context, fileID int64) (*ente.FileLinkRow, error) {row := pcr.DB.QueryRowContext(ctx, `SELECT id, file_id, owner_id, access_token, valid_till, device_limit,