π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Prune more server comments
Manav Rathicc34ae76939f
diff --git a/server/ente/authenticator/authenticator.go b/server/ente/authenticator/authenticator.goindex 82c36b06e8..ebafd7de67 100644--- a/server/ente/authenticator/authenticator.go+++ b/server/ente/authenticator/authenticator.go@@ -36,7 +36,7 @@ type UpdateEntityRequest struct {}type GetEntityDiffRequest struct {- // SinceTime *int64. Pointer allows us to pass 0 value otherwise binding fails for zero Value.+ // Keep this a pointer so binding accepts zero.SinceTime *int64 `form:"sinceTime" binding:"required"`Limit int16 `form:"limit" binding:"required"`}diff --git a/server/ente/embedding.go b/server/ente/embedding.goindex 667e232b5f..58dfbda80e 100644--- a/server/ente/embedding.go+++ b/server/ente/embedding.go@@ -25,7 +25,7 @@ type InsertOrUpdateEmbeddingRequest struct {type GetEmbeddingDiffRequest struct {Model Model `form:"model"`- // SinceTime *int64. Pointer allows us to pass 0 value otherwise binding fails for zero Value.+ // Keep this a pointer so binding accepts zero.SinceTime *int64 `form:"sinceTime" binding:"required"`Limit int16 `form:"limit" binding:"required"`}diff --git a/server/ente/userentity/entity.go b/server/ente/userentity/entity.goindex a27bd6c8df..e91022e6d5 100644--- a/server/ente/userentity/entity.go+++ b/server/ente/userentity/entity.go@@ -12,18 +12,13 @@ type EntityType stringconst (Location EntityType = "location"// Person entity is deprecated and will be removed in the future.- //Deprecated ..Person EntityType = "person"- // CGroup is a new version of Person entity, where the data is gzipped before encryption- CGroup EntityType = "cgroup"- // SmartAlbum is a new entity type for storing smart album config data+ // CGroup replaces Person; its data is gzipped before encryption.+ CGroup EntityType = "cgroup"SmartAlbum EntityType = "smart_album"- // Memory is the entity type for memory share encryption keys- Memory EntityType = "memory"- // Contact is the entity type for the shared contact root key.- Contact EntityType = "contact"- // Space is the entity type for the space root key.- Space EntityType = "space"+ Memory EntityType = "memory"+ Contact EntityType = "contact"+ Space EntityType = "space")func (et EntityType) IsValid() error {@@ -75,7 +70,7 @@ type EntityDataRequest struct {Type EntityType `json:"type" binding:"required"`EncryptedData string `json:"encryptedData" binding:"required"`Header string `json:"header" binding:"required"`- ID *string `json:"id"` // Optional ID, if not provided a new ID will be generated+ ID *string `json:"id"`}func (edr *EntityDataRequest) IsValid(userID int64) error {@@ -105,7 +100,7 @@ type UpdateEntityDataRequest struct {type GetEntityDiffRequest struct {Type EntityType `form:"type" binding:"required"`- // SinceTime *int64. Pointer allows us to pass 0 value otherwise binding fails for zero Value.+ // Keep this a pointer so binding accepts zero.SinceTime *int64 `form:"sinceTime" binding:"required"`Limit int16 `form:"limit" binding:"required"`}diff --git a/server/pkg/api/cast.go b/server/pkg/api/cast.goindex de40bc222f..e294b15ebb 100644--- a/server/pkg/api/cast.go+++ b/server/pkg/api/cast.go@@ -127,13 +127,11 @@ func (h *CastHandler) GetThumbnail(c *gin.Context) {h.getFileForType(c, ente.THUMBNAIL)}-// GetFileURLV3 returns the file URL and reserves HTTP 404 for an unavailable endpoint.func (h *CastHandler) GetFileURLV3(c *gin.Context) {url, err := h.getFileURL(c, ente.FILE)writeFileURLV3(c, url, err)}-// GetThumbnailURLV3 returns the thumbnail URL and reserves HTTP 404 for an unavailable endpoint.func (h *CastHandler) GetThumbnailURLV3(c *gin.Context) {url, err := h.getFileURL(c, ente.THUMBNAIL)writeFileURLV3(c, url, err)diff --git a/server/pkg/api/collection.go b/server/pkg/api/collection.goindex 21c6183257..0cbec76790 100644--- a/server/pkg/api/collection.go+++ b/server/pkg/api/collection.go@@ -321,8 +321,6 @@ func (h *CollectionHandler) RemoveFilesV3(c *gin.Context) {c.Status(http.StatusOK)}-// SuggestDeleteInSharedCollection allows collection owner or admins to suggest deletion-// of files owned by others in a shared collection. The request must exclude files owned by the actor.func (h *CollectionHandler) SuggestDeleteInSharedCollection(c *gin.Context) {var request ente.SuggestDeleteRequestif err := handler.BindJSON(c, &request); err != nil {diff --git a/server/pkg/api/file.go b/server/pkg/api/file.goindex b74211fff8..c06a02ed17 100644--- a/server/pkg/api/file.go+++ b/server/pkg/api/file.go@@ -222,7 +222,6 @@ func (h *FileHandler) GetURL(c *gin.Context) {c.JSON(http.StatusOK, gin.H{"url": url})}-// GetURLV3 returns the URL of the file and reserves HTTP 404 for an unavailable endpoint.func (h *FileHandler) GetURLV3(c *gin.Context) {userID, fileID := getUserAndFileIDs(c)url, err := h.Controller.GetFileURL(c, userID, fileID)@@ -250,7 +249,6 @@ func (h *FileHandler) GetThumbnailURL(c *gin.Context) {c.JSON(http.StatusOK, gin.H{"url": url})}-// GetThumbnailURLV3 returns the thumbnail URL and reserves HTTP 404 for an unavailable endpoint.func (h *FileHandler) GetThumbnailURLV3(c *gin.Context) {userID, fileID := getUserAndFileIDs(c)url, err := h.Controller.GetThumbnailURL(c, userID, fileID)@@ -265,6 +263,7 @@ func writeFileURLV3(c *gin.Context, url string, err error) {c.JSON(http.StatusOK, gin.H{"url": url})}+// V3 uses 400 for missing objects so 404 can signal endpoint unavailability.func fileURLV3Error(err error) error {var apiErr *ente.ApiErrorif errors.Is(err, sql.ErrNoRows) ||diff --git a/server/pkg/api/file_data.go b/server/pkg/api/file_data.goindex 0e7365ffe2..655534fa7c 100644--- a/server/pkg/api/file_data.go+++ b/server/pkg/api/file_data.go@@ -74,8 +74,8 @@ func (h *FileHandler) GetFilesData(ctx *gin.Context) {ctx.JSON(http.StatusOK, resp)}-// FileDataStatusDiff API won't really return status/diff for deleted files. The clients will primarily use this data to identify for which all files we already have preview generated or it's ML inference is done.-// This doesn't simulate perfect diff behaviour as we won't maintain a tombstone entries for the deleted API.+// This is not a full diff: Deleted files are omitted because file-data status+// does not retain tombstones.func (h *FileHandler) FileDataStatusDiff(ctx *gin.Context) {var req fileData.FDDiffRequestif err := handler.BindJSON(ctx, &req); err != nil {diff --git a/server/pkg/api/file_link.go b/server/pkg/api/file_link.goindex 318d138962..5ad2a6a07d 100644--- a/server/pkg/api/file_link.go+++ b/server/pkg/api/file_link.go@@ -78,14 +78,12 @@ func (h *FileHandler) LinkFile(c *gin.Context) {c.Redirect(http.StatusTemporaryRedirect, url)}-// LinkThumbnailURLV3 returns the thumbnail URL and reserves HTTP 404 for an unavailable endpoint.func (h *FileHandler) LinkThumbnailURLV3(c *gin.Context) {linkCtx := auth.MustGetFileLinkAccessContext(c)url, err := h.Controller.GetThumbnailURLForOwner(c, linkCtx.OwnerID, linkCtx.FileID)writeFileURLV3(c, url, err)}-// LinkFileURLV3 returns the file URL and reserves HTTP 404 for an unavailable endpoint.func (h *FileHandler) LinkFileURLV3(c *gin.Context) {linkCtx := auth.MustGetFileLinkAccessContext(c)url, err := h.Controller.GetFileURLForOwner(c, linkCtx.OwnerID, linkCtx.FileID)diff --git a/server/pkg/api/public_collection.go b/server/pkg/api/public_collection.goindex 38c441cbdd..b28fe9221d 100644--- a/server/pkg/api/public_collection.go+++ b/server/pkg/api/public_collection.go@@ -36,13 +36,11 @@ func (h *PublicCollectionHandler) GetFile(c *gin.Context) {h.getFileForType(c, ente.FILE)}-// GetThumbnailURLV3 returns the thumbnail URL and reserves HTTP 404 for an unavailable endpoint.func (h *PublicCollectionHandler) GetThumbnailURLV3(c *gin.Context) {url, err := h.getFileURL(c, ente.THUMBNAIL)writeFileURLV3(c, url, err)}-// GetFileURLV3 returns the file URL and reserves HTTP 404 for an unavailable endpoint.func (h *PublicCollectionHandler) GetFileURLV3(c *gin.Context) {url, err := h.getFileURL(c, ente.FILE)writeFileURLV3(c, url, err)diff --git a/server/pkg/api/public_memory_share.go b/server/pkg/api/public_memory_share.goindex bce89df597..d50183d9bb 100644--- a/server/pkg/api/public_memory_share.go+++ b/server/pkg/api/public_memory_share.go@@ -53,13 +53,11 @@ func (h *PublicMemoryShareHandler) GetFile(c *gin.Context) {h.getFileForType(c, ente.FILE)}-// GetThumbnailURLV3 returns the thumbnail URL and reserves HTTP 404 for an unavailable endpoint.func (h *PublicMemoryShareHandler) GetThumbnailURLV3(c *gin.Context) {url, err := h.getFileURL(c, ente.THUMBNAIL)writeFileURLV3(c, url, err)}-// GetFileURLV3 returns the file URL and reserves HTTP 404 for an unavailable endpoint.func (h *PublicMemoryShareHandler) GetFileURLV3(c *gin.Context) {url, err := h.getFileURL(c, ente.FILE)writeFileURLV3(c, url, err)diff --git a/server/pkg/api/remotestore.go b/server/pkg/api/remotestore.goindex 6d56375795..1639c5d8bd 100644--- a/server/pkg/api/remotestore.go+++ b/server/pkg/api/remotestore.go@@ -68,7 +68,6 @@ func (h *RemoteStoreHandler) GetFeatureFlags(c *gin.Context) {c.JSON(http.StatusOK, resp)}-// CheckDomain returns 200 ok if the custom domain is claimed by any ente userfunc (h *RemoteStoreHandler) CheckDomain(c *gin.Context) {domain := c.Query("domain")if domain == "" {diff --git a/server/pkg/controller/access/collection.go b/server/pkg/controller/access/collection.goindex 07f5d92d4b..afc58aee51 100644--- a/server/pkg/controller/access/collection.go+++ b/server/pkg/controller/access/collection.go@@ -7,14 +7,10 @@ import ()type GetCollectionParams struct {- CollectionID int64- ActorUserID int64- // IncludeDeleted defaults to false. If false and user is trying to fetch deletion collection- // then the request fails+ CollectionID int64+ ActorUserID int64IncludeDeleted bool-- // VerifyOwner deafults to false. If the flag is set to true, the method will verify that the actor actually owns the collection- VerifyOwner bool+ VerifyOwner bool// todo: Add accessType in params for verifying read/write/can-upload/owner types of access}diff --git a/server/pkg/controller/discountcoupon/controller.go b/server/pkg/controller/discountcoupon/controller.goindex a3e55ee13b..39522274e2 100644--- a/server/pkg/controller/discountcoupon/controller.go+++ b/server/pkg/controller/discountcoupon/controller.go@@ -19,7 +19,6 @@ import (const MaxSendCount = 10-// AllowedProviders is a set of valid provider names for discount coupons.// While adding new providers, consider adding customized templates in email package.var AllowedProviders = map[string]bool{"Kagi": true,diff --git a/server/pkg/controller/usage.go b/server/pkg/controller/usage.goindex 61766d62cd..a809a47ac5 100644--- a/server/pkg/controller/usage.go+++ b/server/pkg/controller/usage.go@@ -51,8 +51,6 @@ func GetLockerLimitsForTier(isPaid bool) LockerLimits {return limits}-// CanUploadFile returns error if the file of given size (with StorageOverflowAboveSubscriptionLimit buffer) can be-// uploaded or not. If size is not passed, it validates if current usage is less than subscription storage.func (c *UsageController) CanUploadFile(ctx context.Context, userID int64, size *int64, app ente.App) error {if app != ente.Locker && (size == nil || *size < hundredMBInBytes) {c.mu.Lock()@@ -84,8 +82,6 @@ func (c *UsageController) canUploadFile(ctx context.Context, userID int64, sizevar subscriptionAdminID int64var subscriptionUserIDs []int64- // if user is part of a family group, validate if subscription of familyAdmin is valid & member's total storage- // is less than the storage accordingly to subscription plan of the adminvar memberStorageLimit *int64if familyAdminID != nil {familyMembers, err := c.FamilyRepo.GetMembersWithStatus(*familyAdminID, repo.ActiveFamilyMemberStatus)diff --git a/server/pkg/middleware/cast_auth.go b/server/pkg/middleware/cast_auth.goindex 4821a83d69..ee23d9a6f5 100644--- a/server/pkg/middleware/cast_auth.go+++ b/server/pkg/middleware/cast_auth.go@@ -35,7 +35,6 @@ func (m *CastMiddleware) CastAuthMiddleware() gin.HandlerFunc {c.Set(auth.CastContext, *castCtx)} else {c.Set(auth.CastContext, cachedCastCtx)- // validate async validate that the token is still activego func() {_, err := m.CastCtrl.GetCollectionAndCasterIDForToken(c, token)if err != nil {diff --git a/server/pkg/middleware/collection_link.go b/server/pkg/middleware/collection_link.goindex 7a864eeab0..fbaf7804f1 100644--- a/server/pkg/middleware/collection_link.go+++ b/server/pkg/middleware/collection_link.go@@ -202,8 +202,6 @@ func shouldCheckCollectionLinkDeviceLimit(reqPath string) bool {reqPath == "/public-collection/diff"}-// validateOwnersSubscription checks if the owner has an active subscription.-// Returns (isFreeUser, error) where isFreeUser is true if user is on free plan but has active subscription.func (m *CollectionLinkMiddleware) validateOwnersSubscription(c *gin.Context, cID int64) (bool, error) {userID, err := m.CollectionRepo.GetOwnerID(cID)if err != nil {@@ -217,7 +215,6 @@ func (m *CollectionLinkMiddleware) validateOwnersSubscription(c *gin.Context, cIreturn false, stacktrace.Propagate(err, "failed to validate owners subscription")}isFreeUser = true- // Free user - check if they have active subscription (not expired)if err = m.BillingCtrl.HasActiveSelfOrFamilySubscription(userID, false); err != nil {return false, stacktrace.Propagate(err, "failed to validate owners subscription")}diff --git a/server/pkg/repo/emergency/repository.go b/server/pkg/repo/emergency/repository.goindex 108b1ad557..fa08b65e98 100644--- a/server/pkg/repo/emergency/repository.go+++ b/server/pkg/repo/emergency/repository.go@@ -61,8 +61,6 @@ WHERE emergency_contact.user_id=$1 AND emergency_contact.emergency_contact_id=$2return rowAffected > 0, nil}-// GetActiveContactForUser returns all the contacts for a user that are in state accepted or invited-// and also returns all the contacts that have added the user as emergency contactfunc (r *Repository) GetActiveContactForUser(ctx context.Context, userID int64) ([]*ContactRow, error) {rows, err := r.DB.QueryContext(ctx,`SELECT user_id, emergency_contact_id, state, notice_period_in_hrs, encrypted_key@@ -120,8 +118,6 @@ func (r *Repository) UpdateState(ctx context.Context,return count > 0, stacktrace.Propagate(err2, "")}-// UpdateRecoveryNotice updates the notice period for an emergency contact-// Only allows update if the contact state is INVITED or ACCEPTEDfunc (r *Repository) UpdateRecoveryNotice(ctx context.Context,userID int64,emergencyContactID int64,diff --git a/server/pkg/repo/memory_share.go b/server/pkg/repo/memory_share.goindex 4f568af376..89201a0da9 100644--- a/server/pkg/repo/memory_share.go+++ b/server/pkg/repo/memory_share.go@@ -237,7 +237,6 @@ func (r *MemoryShareRepository) GetByUserID(ctx context.Context, userID int64) (return shares, nil}-// Delete soft-deletes a memory share owned by the given user.func (r *MemoryShareRepository) Delete(ctx context.Context, shareID int64, userID int64) error {result, err := r.DB.ExecContext(ctx, `UPDATE memory_shares SET is_deleted = true, updated_at = $1diff --git a/server/pkg/repo/public/file_link.go b/server/pkg/repo/public/file_link.goindex 1945a871b6..a55c6401b4 100644--- a/server/pkg/repo/public/file_link.go+++ b/server/pkg/repo/public/file_link.go@@ -125,8 +125,7 @@ func (pcr *FileLinkRepository) UpdateLinkSecretIfEmpty(return stacktrace.Propagate(err, "failed to update link secret metadata")}-// GetActiveFileUrlToken will return ente.CollectionLinkRow for given collection ID-// Note: The token could be expired or deviceLimit is already reached+// "Active" only means not disabled; the link may be expired or over its limit.func (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,is_disabled, pw_hash, pw_nonce, mem_limit, ops_limit, enable_download,@@ -284,7 +283,6 @@ func (pcr *FileLinkRepository) RecordAccessHistory(ctx context.Context, shareIDreturn stacktrace.Propagate(err, "failed to record access history")}-// AccessedInPast returns true if the given ip, ua agent combination has accessed the url in the pastfunc (pcr *FileLinkRepository) AccessedInPast(ctx context.Context, shareID string, ip string, ua string) (bool, error) {row := pcr.DB.QueryRowContext(ctx, `select id from public_file_tokens_access_history where id =$1 and ip = $2 and user_agent = $3`,shareID, ip, ua)diff --git a/server/pkg/repo/remotestore/repository.go b/server/pkg/repo/remotestore/repository.goindex 8098e904e2..7ead8dc593 100644--- a/server/pkg/repo/remotestore/repository.go+++ b/server/pkg/repo/remotestore/repository.go@@ -25,7 +25,6 @@ func (r *Repository) InsertOrUpdate(ctx context.Context, userID int64, key strin)if err != nil {- // Check for unique violation (PostgreSQL error code 23505)var pgErr *pq.Errorif errors.As(err, &pgErr) && pgErr.Code == "23505" {if pgErr.Constraint == "remote_store_custom_domain_unique_idx" {@@ -81,7 +80,6 @@ func (r *Repository) GetDomain(ctx context.Context, userID int64) (*string, erro}-// GetEffectiveDomain returns the resolved custom domain for the user (family pointers resolved).func (r *Repository) GetEffectiveDomain(ctx context.Context, userID int64) (*string, error) {domain, err := r.GetDomain(ctx, userID)if err != nil || domain == nil || *domain == "" {diff --git a/server/pkg/repo/storagebonus/referral_tracking.go b/server/pkg/repo/storagebonus/referral_tracking.goindex 4997a767ac..cc06b958ee 100644--- a/server/pkg/repo/storagebonus/referral_tracking.go+++ b/server/pkg/repo/storagebonus/referral_tracking.go@@ -11,8 +11,6 @@ import ("github.com/sirupsen/logrus")-// TrackReferralAndInviteeBonus inserts an entry in the referral_tracking table for given invitee,invitor and planType and insert a storage surplus for the invitee-// in a single txnfunc (r *Repository) TrackReferralAndInviteeBonus(ctx context.Context, invitee, codeOwnerId int64, planType storagebonus.PlanType) error {if invitee == codeOwnerId {return stacktrace.Propagate(ente.ErrBadRequest, "invitee %d and invitor %d are same", invitee, codeOwnerId)@@ -46,9 +44,6 @@ func (r *Repository) TrackReferralAndInviteeBonus(ctx context.Context, invitee,return nil}-// TrackUpgradeAndInvitorBonus invitee upgrade to paid plan from non-paid plan by modifying invitee_on_paid_plan from false to true.-// and insert a storage surplus for the invitor with InvitorBonusOnInviteeUpgrade in-// a single transaction. Verify that the update is happening from non-paid plan to paid plan for the given invitee and invitorfunc (r *Repository) TrackUpgradeAndInvitorBonus(ctx context.Context, invitee, invitor int64, planType storagebonus.PlanType) error {if invitee == invitor {return stacktrace.Propagate(ente.ErrBadRequest, "invitee %d and invitor %d are same", invitee, invitor)diff --git a/server/pkg/repo/two_factor_recovery/repository.go b/server/pkg/repo/two_factor_recovery/repository.goindex cbb5167b02..500d9d4021 100644--- a/server/pkg/repo/two_factor_recovery/repository.go+++ b/server/pkg/repo/two_factor_recovery/repository.go@@ -23,7 +23,6 @@ func (r *Repository) GetStatus(userID int64) (*ente.TwoFactorRecoveryStatus, errerr := row.Scan(&isAdminResetEnabled, &resetKey)if err != nil {if err == sql.ErrNoRows {- // by default, adminreturn &ente.TwoFactorRecoveryStatus{AllowAdminReset: true,IsPasskeyRecoveryEnabled: false,diff --git a/server/pkg/repo/twofactor.go b/server/pkg/repo/twofactor.goindex de6ec5433e..7731d9de37 100644--- a/server/pkg/repo/twofactor.go+++ b/server/pkg/repo/twofactor.go@@ -124,8 +124,6 @@ func (repo *TwoFactorRepository) GetWrongAttempts(sessionID string) (int, error)return wrongAttempt, nil}-// RecordWrongAttempt increases the wrong_attempt count for the given two factor session.-// This is used to track and prevent brute-force attacks on two-factor verificationfunc (repo *TwoFactorRepository) RecordWrongAttempt(sessionID string) error {_, err := repo.DB.Exec(`UPDATE two_factor_sessions SET wrong_attempt = wrong_attempt + 1WHERE session_id = $1`, sessionID)diff --git a/server/pkg/repo/userauth.go b/server/pkg/repo/userauth.goindex 4e11266d32..0d4930dee3 100644--- a/server/pkg/repo/userauth.go+++ b/server/pkg/repo/userauth.go@@ -28,7 +28,6 @@ func (repo *UserAuthRepository) AddOTT(emailHash string, app ente.App, ott strinreturn stacktrace.Propagate(err, "")}-// RemoveOTT removes the specified OTT and returns whether it was consumed.func (repo *UserAuthRepository) RemoveOTT(emailHash string, ott string, app ente.App) (bool, error) {result, err := repo.DB.Exec(`DELETE FROM otts WHERE email_hash = $1 AND ott = $2 AND app = $3`, emailHash, ott, app)if err != nil {@@ -139,7 +138,6 @@ func (repo *UserAuthRepository) AddToken(userID int64, app ente.App, token strinreturn stacktrace.Propagate(err, "")}-// GetUserIDWithToken returns the userID associated with a given token and whether the token is expiredfunc (repo *UserAuthRepository) GetUserIDWithToken(token string, app ente.App) (int64, bool, error) {row := repo.DB.QueryRow(`SELECTdiff --git a/server/pkg/utils/recover/wrap.go b/server/pkg/utils/recover/wrap.goindex da750e5216..4897d5ee49 100644--- a/server/pkg/utils/recover/wrap.go+++ b/server/pkg/utils/recover/wrap.go@@ -15,7 +15,6 @@ func Int64ToInt64RecoverWrapper() (err error) {defer func() {if x := recover(); x != nil {- // we need to use named params if we want to return panic as errerr = stacktrace.Propagate(fmt.Errorf("%+v", x), "panic during GoInt64ToInt64Data")}}()