Skip to content

armgit / ente

Public Imported from GitHub
0

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

Prune server controller comments

Manav Rathi685b256dd787
diff --git a/server/pkg/controller/appstore.go b/server/pkg/controller/appstore.go
index c5b6dba85d..5a647761c0 100644
--- a/server/pkg/controller/appstore.go
+++ b/server/pkg/controller/appstore.go
@@ -27,7 +27,6 @@ import (
"github.com/ente/museum/pkg/repo/remotestore"
)
-// AppStoreController provides abstractions for handling billing on AppStore
type AppStoreController struct {
AppStoreClient appstore.Client
BillingRepo *repo.BillingRepository
@@ -37,11 +36,9 @@ type AppStoreController struct {
BillingPlansPerCountry ente.BillingPlansPerCountry
CommonBillCtrl *commonbilling.Controller
DiscordController *discord.DiscordController
- // appStoreSharedPassword is the password to be used to access AppStore APIs
appStoreSharedPassword string
}
-// Return a new instance of AppStoreController
func NewAppStoreController(
plans ente.BillingPlansPerCountry,
billingRepo *repo.BillingRepository,
@@ -105,7 +102,6 @@ func (c *AppStoreController) validateSandboxRequest(ctx context.Context, environ
return stacktrace.Propagate(ente.NewInternalError("sandbox request from external user"), "")
}
-// HandleNotification handles an AppStore notification
func (c *AppStoreController) HandleNotification(ctx *gin.Context, notification appstore.SubscriptionNotification) error {
logger := logrus.WithFields(logrus.Fields{
"req_id": requestid.Get(ctx),
@@ -118,7 +114,6 @@ func (c *AppStoreController) HandleNotification(ctx *gin.Context, notification a
if latestReceiptInfo.TransactionID == latestReceiptInfo.OriginalTransactionID && !slices.Contains(SubsUpdateNotificationTypes, string(notification.NotificationType)) {
var logMsg = fmt.Sprintf("Ignoring notification of type %s", notification.NotificationType)
if notification.NotificationType != appstore.NotificationTypeInitialBuy {
- // log unexpected notification types
logger.Error(logMsg)
} else {
logger.Info(logMsg)
@@ -149,7 +144,7 @@ func (c *AppStoreController) HandleNotification(ctx *gin.Context, notification a
break
}
}
- if newPlan.Storage < subscription.Storage { // Downgrade
+ if newPlan.Storage < subscription.Storage {
canDowngrade, canDowngradeErr := c.CommonBillCtrl.CanDowngradeToGivenStorage(newPlan.Storage, subscription.UserID)
if canDowngradeErr != nil {
return stacktrace.Propagate(canDowngradeErr, "")
@@ -196,7 +191,6 @@ func (c *AppStoreController) HandleNotification(ctx *gin.Context, notification a
return stacktrace.Propagate(err, "")
}
-// GetVerifiedSubscription verifies and returns the verified subscription
func (c *AppStoreController) GetVerifiedSubscription(userID int64, productID string, verificationData string) (ente.Subscription, error) {
var s ente.Subscription
s.UserID = userID
@@ -227,7 +221,6 @@ func (c *AppStoreController) GetVerifiedSubscription(userID int64, productID str
return s, nil
}
-// VerifyAppStoreSubscription verifies an AppStore subscription
func (c *AppStoreController) verifyAppStoreSubscription(verificationData string) (*appstore.IAPResponse, error) {
iapRequest := appstore.IAPRequest{
ReceiptData: verificationData,
diff --git a/server/pkg/controller/billing.go b/server/pkg/controller/billing.go
index a4d861d8f9..3361b87e9d 100644
--- a/server/pkg/controller/billing.go
+++ b/server/pkg/controller/billing.go
@@ -25,7 +25,6 @@ import (
"github.com/ente/museum/pkg/repo"
)
-// BillingController provides abstractions for handling billing related queries
type BillingController struct {
BillingPlansPerAccount ente.BillingPlansPerAccount
BillingRepo *repo.BillingRepository
@@ -40,7 +39,6 @@ type BillingController struct {
CommonBillCtrl *commonbilling.Controller
}
-// Return a new instance of BillingController
func NewBillingController(
plans ente.BillingPlansPerAccount,
appStoreController *AppStoreController,
@@ -69,7 +67,6 @@ func NewBillingController(
}
}
-// GetPlansV2 returns the available subscription plans for the given country and stripe account
func (c *BillingController) GetPlansV2(countryCode string, stripeAccountCountry ente.StripeAccountCountry) []ente.BillingPlan {
plans := c.getAllPlans(countryCode, stripeAccountCountry)
result := make([]ente.BillingPlan, 0)
@@ -90,14 +87,12 @@ func (c *BillingController) GetStripeAccountCountry(userID int64) (ente.StripeAc
return "", stacktrace.Propagate(err, "")
}
if subscription.PaymentProvider != ente.Stripe {
- //if user doesn't have a stripe subscription, return the default stripe account country
return ente.DefaultStripeAccountCountry, nil
} else {
return subscription.Attributes.StripeAccountCountry, nil
}
}
-// GetUserPlans returns the active plans for a user
func (c *BillingController) GetUserPlans(ctx *gin.Context, userID int64) ([]ente.BillingPlan, error) {
stripeAccountCountry, err := c.GetStripeAccountCountry(userID)
if err != nil {
@@ -108,7 +103,6 @@ func (c *BillingController) GetUserPlans(ctx *gin.Context, userID int64) ([]ente
}
-// GetSubscription returns the current subscription for a user if any
func (c *BillingController) GetSubscription(ctx *gin.Context, userID int64) (ente.Subscription, error) {
s, err := c.BillingRepo.GetUserSubscription(userID)
if err != nil {
@@ -126,7 +120,7 @@ func (c *BillingController) GetSubscription(ctx *gin.Context, userID int64) (ent
func (c *BillingController) GetRedirectURL(ctx *gin.Context) (string, error) {
whitelistedRedirectURLs := viper.GetStringSlice("stripe.whitelisted-redirect-urls")
redirectURL := ctx.Query("redirectURL")
- if len(redirectURL) > 0 && redirectURL[len(redirectURL)-1:] == "/" { // Ignore the trailing slash
+ if len(redirectURL) > 0 && redirectURL[len(redirectURL)-1:] == "/" {
redirectURL = redirectURL[:len(redirectURL)-1]
}
for _, ar := range whitelistedRedirectURLs {
@@ -137,7 +131,6 @@ func (c *BillingController) GetRedirectURL(ctx *gin.Context) (string, error) {
return "", stacktrace.Propagate(ente.ErrBadRequest, "not a whitelistedRedirectURL- %s", redirectURL)
}
-// GetActiveSubscription returns user's active subscription or throws a error if no active subscription
func (c *BillingController) GetActiveSubscription(userID int64) (ente.Subscription, error) {
subscription, err := c.BillingRepo.GetUserSubscription(userID)
if errors.Is(err, sql.ErrNoRows) {
@@ -156,7 +149,6 @@ func (c *BillingController) GetActiveSubscription(userID int64) (ente.Subscripti
return subscription, nil
}
-// HasActiveSelfOrFamilySubscription validates if the user or user's family admin has active subscription
func (c *BillingController) HasActiveSelfOrFamilySubscription(userID int64, mustBeOnPaidPlan bool) error {
var subscriptionUserID int64
familyAdminID, err := c.UserRepo.GetFamilyAdminID(userID)
@@ -193,7 +185,6 @@ func (c *BillingController) HasActiveSelfOrFamilySubscription(userID int64, must
return nil
}
-// VerifySubscription verifies and returns the verified subscription
func (c *BillingController) VerifySubscription(
userID int64,
paymentProvider ente.PaymentProvider,
@@ -277,7 +268,6 @@ func (c *BillingController) VerifySubscription(
newSubscription.ID = currentSubscription.ID
if paymentProvider == ente.PlayStore &&
newSubscription.OriginalTransactionID != currentSubscription.OriginalTransactionID {
- // Acknowledge to PlayStore in case of upgrades/downgrades/renewals
err = c.PlayStoreController.AcknowledgeSubscription(newSubscription.ProductID, verificationData)
if err != nil {
log.Error("Error acknowledging subscription ", err)
@@ -366,7 +356,6 @@ func (c *BillingController) HandleAccountDeletion(ctx context.Context, userID in
"stripe_account_country": subscription.Attributes.StripeAccountCountry,
})
billingLogger.Info("subscription fetched")
- // user on free plan, no action required
if subscription.ProductID == ente.FreePlanProductID {
billingLogger.Info("user on free plan")
return true, nil
diff --git a/server/pkg/controller/data_cleanup/controller.go b/server/pkg/controller/data_cleanup/controller.go
index 642a7c6931..828bcb923e 100644
--- a/server/pkg/controller/data_cleanup/controller.go
+++ b/server/pkg/controller/data_cleanup/controller.go
@@ -31,15 +31,11 @@ type SpaceDataRepo interface {
}
const (
- // nextStageDelayInHoursOnError is number of afters after which next attempt should be made to process
- // current stage.
nextStageDelayInHoursOnError = 2
- // maximum number of storage check attempt before moving to the next stage.
maxStorageCheckAttempt = 10
)
-// DeleteDataCron delete trashed files which are in trash since repo.TrashDurationInDays
func (c *DeleteUserCleanupController) DeleteDataCron() {
if c.running {
log.Info("Already running DeleteDataCron, skipping cron")
@@ -114,7 +110,6 @@ func (c *DeleteUserCleanupController) deleteUserData(ctx context.Context, item *
}
-// startClean up will just verify that user
func (c *DeleteUserCleanupController) startCleanup(ctx context.Context, item *entity.DataCleanup) error {
deleted, err := c.isDeleted(ctx, item)
if err != nil {
@@ -123,11 +118,9 @@ func (c *DeleteUserCleanupController) startCleanup(ctx context.Context, item *en
if !deleted {
return nil
}
- // move to next stage for deleting collection
return c.Repo.MoveToNextStage(ctx, item.UserID, entity.Collection, time.Microseconds())
}
-// deleteCollection will schedule all the collections for deletion and queue up Trash stage to run after 30 min
func (c *DeleteUserCleanupController) deleteCollections(ctx context.Context, item *entity.DataCleanup) error {
collectionsMap, err := c.CollectionRepo.GetCollectionIDsOwnedByUser(item.UserID)
if err != nil {
@@ -135,7 +128,6 @@ func (c *DeleteUserCleanupController) deleteCollections(ctx context.Context, ite
}
for collectionID, isAlreadyDeleted := range collectionsMap {
if !isAlreadyDeleted {
- // Delete all files in the collection
err = c.CollectionRepo.ScheduleDelete(collectionID)
if err != nil {
return stacktrace.Propagate(err, "error while deleting collection %d", collectionID)
@@ -148,7 +140,6 @@ func (c *DeleteUserCleanupController) deleteCollections(ctx context.Context, ite
}
func (c *DeleteUserCleanupController) emptyTrash(ctx context.Context, item *entity.DataCleanup) error {
- // Enqueue empty-trash for both apps
err := c.TrashRepo.EmptyTrash(ctx, item.UserID, time.Microseconds(), ente.Photos)
if err != nil {
return stacktrace.Propagate(err, "")
@@ -183,19 +174,16 @@ func (c *DeleteUserCleanupController) storageCheck(ctx context.Context, item *en
return stacktrace.Propagate(err, "")
}
if usage != 0 {
- // check if trash still has entry
timeStamp, err2 := c.TrashRepo.GetTimeStampForLatestNonDeletedEntry(item.UserID)
if err2 != nil {
return stacktrace.Propagate(err2, "failed to fetch timestamp")
}
- // no entry in trash
if timeStamp != nil {
log.WithFields(log.Fields{
"user_id": item.UserID,
"flow": "delete_user_data",
"timeStamp": timeStamp,
}).Info("trash is not empty")
- // Enqueue empty-trash for both apps
err = c.TrashRepo.EmptyTrash(ctx, item.UserID, *timeStamp, ente.Photos)
if err != nil {
return stacktrace.Propagate(err, "")
diff --git a/server/pkg/controller/discord/discord.go b/server/pkg/controller/discord/discord.go
index 782f8cf696..a8511a34a0 100644
--- a/server/pkg/controller/discord/discord.go
+++ b/server/pkg/controller/discord/discord.go
@@ -12,8 +12,6 @@ import (
"github.com/spf13/viper"
)
-// DiscordController is an devops aid. If Discord credentials are configured,
-// then it will send notifications to Discord channels on specified events.
type DiscordController struct {
MonaLisa *discordgo.Session
ChaChing *discordgo.Session
@@ -54,7 +52,6 @@ func createBot(name string, tokenConfigKey string) *discordgo.Session {
return session
}
-// The actual send
func (c *DiscordController) sendMessage(bot *discordgo.Session, channel string, message string) {
if bot == nil {
log.Infof("Skipping sending Discord message: %s", message)
@@ -67,7 +64,6 @@ func (c *DiscordController) sendMessage(bot *discordgo.Session, channel string,
}
}
-// Send a message related to server status or important events/errors.
func (c *DiscordController) Notify(message string) {
c.sendMessage(c.MonaLisa, viper.GetString("discord.bot.mona-lisa.channel"), message)
}
@@ -85,25 +81,18 @@ func (c *DiscordController) NotifyThrottled(message string, window time.Duration
c.Notify(message)
}
-// Send a message related to subscriptions.
func (c *DiscordController) NotifyNewSub(userID int64, paymentProvider string, amount string) {
message := fmt.Sprintf("New subscriber via `%s`, after %s of signing up! πŸ«‚ (%s)",
paymentProvider, c.getTimeSinceSignUp(userID), amount)
c.sendMessage(c.ChaChing, viper.GetString("discord.bot.cha-ching.channel"), message)
}
-// Send a message related to subscriptions.
func (c *DiscordController) NotifyBlackFridayUser(userID int64, amount string) {
message := fmt.Sprintf("BlackFriday subscription purchased after %s of signing up! πŸ«‚ (%s)",
c.getTimeSinceSignUp(userID), amount)
c.sendMessage(c.ChaChing, viper.GetString("discord.bot.cha-ching.channel"), message)
}
-// Convenience wrappers over the primitive notify types.
-//
-// By keeping them separate we later allow them to be routed easily to different
-// Discord channels.
-
func (c *DiscordController) NotifyStartup() {
c.Notify(c.HostName + " has taken off πŸš€")
}
diff --git a/server/pkg/controller/email/email_notification.go b/server/pkg/controller/email/email_notification.go
index 00caaaa8cd..32fdabb9d6 100644
--- a/server/pkg/controller/email/email_notification.go
+++ b/server/pkg/controller/email/email_notification.go
@@ -180,8 +180,6 @@ func (c *EmailNotificationController) OnSubscriptionCancelled(userID int64) {
}
}
-// SayHelloToCustomers sends an email to check in with customers who upgraded 7
-// days ago.
func (c *EmailNotificationController) SayHelloToCustomers() {
log.Info("Running SayHelloToCustomers")
lockStatus := c.LockController.TryLock(CustomerHelloMailLock, time.MicrosecondsAfterHours(24))
diff --git a/server/pkg/controller/embedding/delete.go b/server/pkg/controller/embedding/delete.go
index 283416b33f..0048f05cbc 100644
--- a/server/pkg/controller/embedding/delete.go
+++ b/server/pkg/controller/embedding/delete.go
@@ -9,7 +9,6 @@ import (
"strconv"
)
-// CleanupDeletedEmbeddings clears all embeddings for deleted files from the object store
func (c *Controller) CleanupDeletedEmbeddings() {
log.Info("Cleaning up deleted embeddings")
if c.cleanupCronRunning {
diff --git a/server/pkg/controller/file.go b/server/pkg/controller/file.go
index 3fe68a8e28..9efd598b07 100644
--- a/server/pkg/controller/file.go
+++ b/server/pkg/controller/file.go
@@ -39,7 +39,6 @@ import (
log "github.com/sirupsen/logrus"
)
-// FileController exposes functions to retrieve and access encrypted files
type FileController struct {
FileRepo *repo.FileRepository
ObjectRepo *repo.ObjectRepository
@@ -63,16 +62,12 @@ type FileController struct {
outdatedQueueDisabled bool
}
-// StorageOverflowAboveSubscriptionLimit is the amount (50 MB) by which user can go beyond their storage limit
const StorageOverflowAboveSubscriptionLimit = int64(1024 * 1024 * 50)
-// MaxFileSize is the maximum file size a user can upload
const MaxFileSize = int64(1024 * 1024 * 1024 * 10)
-// InternalUserMaxFileSize is the maximum file size an internal user can upload
const InternalUserMaxFileSize = int64(1024 * 1024 * 1024 * 20)
-// MaxUploadURLsLimit indicates the max number of upload urls which can be request in one go
const MaxUploadURLsLimit = 50
const (
@@ -113,7 +108,6 @@ func (c *FileController) validateFileCreateOrUpdateReq(userID int64, file ente.F
return stacktrace.Propagate(ente.ErrBadRequest, "file and thumbnail object keys are same")
}
isCreateFileReq := file.ID == 0
- // Check for attributes for fileCreation. We don't send key details on update
if isCreateFileReq {
if file.EncryptedKey == "" || file.KeyDecryptionNonce == "" {
return stacktrace.Propagate(ente.ErrBadRequest, "EncryptedKey and KeyDecryptionNonce are required")
@@ -154,7 +148,6 @@ type sizeResult struct {
err error
}
-// Create adds an entry for a file in the respective tables
func (c *FileController) Create(ctx *gin.Context, userID int64, file ente.File, userAgent string, app ente.App) (ente.File, error) {
fileChan := make(chan sizeResult, 1)
thumbChan := make(chan sizeResult, 1)
@@ -170,7 +163,6 @@ func (c *FileController) Create(ctx *gin.Context, userID int64, file ente.File,
if err != nil {
return file, stacktrace.Propagate(err, "")
}
- // Receive results from both operations
fileResult := <-fileChan
thumbResult := <-thumbChan
@@ -217,7 +209,6 @@ func (c *FileController) Create(ctx *gin.Context, userID int64, file ente.File,
ThumbnailSize: thumbnailSize,
}
- // all iz well
var usage int64
file, usage, err = c.FileRepo.Create(file, fileSize, thumbnailSize, fileSize+thumbnailSize, userID, app)
if err != nil {
@@ -261,7 +252,6 @@ func (c *FileController) maybeSendFirstUploadEmail(userID int64, userAgent strin
log.WithField("user_id", userID).Debug("Skipping first upload email because trash is not empty")
}
-// Update verifies permissions and updates the specified file
func (c *FileController) Update(ctx context.Context, userID int64, file ente.File, app ente.App) (ente.UpdateFileResponse, error) {
var response ente.UpdateFileResponse
err := c.validateFileCreateOrUpdateReq(userID, file, app)
@@ -272,7 +262,6 @@ func (c *FileController) Update(ctx context.Context, userID int64, file ente.Fil
if err != nil {
return response, stacktrace.Propagate(err, "")
}
- // verify that user owns the file
if ownerID != userID {
return response, stacktrace.Propagate(ente.ErrPermissionDenied, "")
}
@@ -355,7 +344,6 @@ func (c *FileController) Update(ctx context.Context, userID int64, file ente.Fil
return response, nil
}
-// GetUploadURLs returns a bunch of presigned URLs for uploading files
func (c *FileController) GetUploadURLs(ctx context.Context, userID int64, count int, app ente.App, ignoreLimit bool) ([]ente.UploadURL, error) {
err := c.UsageCtrl.CanUploadFile(ctx, userID, nil, app)
if err != nil {
@@ -382,7 +370,6 @@ func (c *FileController) GetUploadURLs(ctx context.Context, userID int64, count
return 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, "")
@@ -422,24 +409,18 @@ func (c *FileController) GetUploadURLWithMetadata(ctx context.Context, userID in
return url, nil
}
-// GetFileURL verifies permissions and returns a presigned url to the requested file
func (c *FileController) GetFileURL(ctx *gin.Context, userID int64, fileID int64) (string, error) {
return c.getSignedURLForAccessibleObject(ctx, userID, fileID, ente.FILE)
}
-// GetThumbnailURL verifies permissions and returns a presigned url to the requested thumbnail
func (c *FileController) GetThumbnailURL(ctx *gin.Context, userID int64, fileID int64) (string, error) {
return c.getSignedURLForAccessibleObject(ctx, userID, fileID, ente.THUMBNAIL)
}
-// GetFileURLForOwner verifies ownership and returns a presigned URL using a
-// fused ownership-check and object lookup path.
func (c *FileController) GetFileURLForOwner(ctx *gin.Context, ownerID int64, fileID int64) (string, error) {
return c.getSignedURLForOwnedObject(ctx, ownerID, fileID, ente.FILE)
}
-// GetThumbnailURLForOwner verifies ownership and returns a presigned URL using
-// a fused ownership-check and object lookup path.
func (c *FileController) GetThumbnailURLForOwner(ctx *gin.Context, ownerID int64, fileID int64) (string, error) {
return c.getSignedURLForOwnedObject(ctx, ownerID, fileID, ente.THUMBNAIL)
}
@@ -449,7 +430,6 @@ func (c *FileController) CleanUpStaleCollectionFiles(fileID int64) {
"fileID": fileID,
"action": "CleanUpStaleCollectionFiles",
})
- // catch panic
defer func() {
if r := recover(); r != nil {
logger.Error("Recovered from panic", r)
@@ -470,7 +450,6 @@ func (c *FileController) CleanUpStaleCollectionFiles(fileID int64) {
}
-// GetPublicOrCastFileURL verifies permissions and returns a presigned url to the requested file
func (c *FileController) GetPublicOrCastFileURL(ctx *gin.Context, fileID int64, objType ente.ObjectType, collectionID int64) (string, error) {
return c.getSignedURLForCollectionObject(ctx, collectionID, fileID, objType)
}
@@ -582,9 +561,7 @@ func (c *FileController) getSignedURLFromObjectAndDCs(s3Object ente.S3ObjectKey,
return c.getHotDcSignedUrl(s3Object.ObjectKey, objType)
}
-// ignore lint unused inspection
func isCliRequest(ctx *gin.Context) bool {
- // check if user-agent contains go-resty
userAgent := ctx.Request.Header.Get("User-Agent")
return strings.Contains(userAgent, "go-resty")
}
@@ -612,7 +589,6 @@ func (c *FileController) getWasabiSignedUrlForAccessibleObject(ctx *gin.Context,
return c.getSignedURLFromObjectAndDCs(s3Object, dcs, objType)
}
-// Trash deletes file and move them to trash
func (c *FileController) Trash(ctx *gin.Context, userID int64, request ente.TrashRequest) error {
fileIDs := make([]int64, 0)
collectionIDs := make([]int64, 0)
@@ -639,7 +615,6 @@ func (c *FileController) Trash(ctx *gin.Context, userID int64, request ente.Tras
return c.TrashRepository.TrashFiles(fileIDs, userID, request)
}
-// GetSize returns the size of files indicated by fileIDs that are owned by userID
func (c *FileController) GetSize(userID int64, fileIDs []int64) (int64, error) {
size, err := c.FileRepo.GetSize(userID, fileIDs)
if err != nil {
@@ -648,7 +623,6 @@ func (c *FileController) GetSize(userID int64, fileIDs []int64) (int64, error) {
return size, nil
}
-// GetFileInfo returns the file infos given list of files
func (c *FileController) GetFileInfo(ctx *gin.Context, userID int64, fileIDs []int64) (*ente.FilesInfoResponse, error) {
logger := log.WithFields(log.Fields{
"req_id": requestid.Get(ctx),
@@ -697,7 +671,6 @@ func (c *FileController) GetFileInfo(ctx *gin.Context, userID int64, fileIDs []i
return nil, stacktrace.Propagate(ente.NewInternalError("failed to get fileInfo"), "fileIDs not found: %v", missedFileIDs)
}
- // prepare a list of FileInfoResponse
fileInfoList := make([]*ente.FileInfoResponse, 0)
for _, fileID := range fileIDs {
id := fileID
@@ -722,7 +695,6 @@ func (c *FileController) GetFileInfo(ctx *gin.Context, userID int64, fileIDs []i
}, nil
}
-// GetDuplicates returns the list of files of the same size
func (c *FileController) GetDuplicates(userID int64) ([]ente.DuplicateFiles, error) {
dupes, err := c.FileRepo.GetDuplicateFiles(userID)
if err != nil {
@@ -731,7 +703,6 @@ func (c *FileController) GetDuplicates(userID int64) ([]ente.DuplicateFiles, err
return dupes, nil
}
-// UpdateMagicMetadata updates the magic metadata for list of files
func (c *FileController) UpdateMagicMetadata(ctx *gin.Context, req ente.UpdateMultipleMagicMetadataRequest, isPublicMetadata bool) error {
err := c.validateUpdateMetadataRequest(ctx, req, isPublicMetadata)
if err != nil {
@@ -744,7 +715,6 @@ func (c *FileController) UpdateMagicMetadata(ctx *gin.Context, req ente.UpdateMu
return nil
}
-// UpdateThumbnail updates thumbnail of a file
func (c *FileController) UpdateThumbnail(ctx *gin.Context, fileID int64, newThumbnail ente.FileAttributes, app ente.App) error {
userID := auth.GetUserID(ctx.Request.Header)
objectPathPrefix := strconv.FormatInt(userID, 10) + "/"
@@ -755,7 +725,6 @@ func (c *FileController) UpdateThumbnail(ctx *gin.Context, fileID int64, newThum
if err != nil {
return stacktrace.Propagate(err, "")
}
- // verify that user owns the file
if ownerID != userID {
return stacktrace.Propagate(ente.ErrPermissionDenied, "")
}
@@ -789,7 +758,6 @@ func (c *FileController) UpdateThumbnail(ctx *gin.Context, fileID int64, newThum
return nil
}
-// VerifyFileOwnership will return error if given fileIDs are not valid or don't belong to the ownerID
func (c *FileController) VerifyFileOwnership(ctx *gin.Context, ownerID int64, fileIDs []int64) error {
countMap, err := c.FileRepo.GetOwnerToFileCountMap(ctx, fileIDs)
if err != nil {
@@ -889,7 +857,6 @@ func (c *FileController) CleanupDeletedFiles() {
var wg sync.WaitGroup
itemChan := make(chan repo.QueueItem, len(items))
- // Start worker goroutines
for range 8 {
wg.Go(func() {
for item := range itemChan {
@@ -904,12 +871,10 @@ func (c *FileController) CleanupDeletedFiles() {
}
})
}
- // Send items to the channel
for _, item := range items {
itemChan <- item
}
close(itemChan)
- // Wait for all workers to finish
wg.Wait()
}
@@ -1161,7 +1126,6 @@ func (c *FileController) getObjectURL(s3Client *s3.S3, dc string, bucket *string
return ente.UploadURL{ObjectKey: objectKey, URL: url}, nil
}
-// GetMultipartUploadURLs return collections of url to upload the parts of the files
func (c *FileController) GetMultipartUploadURLs(ctx context.Context, userID int64, count int, app ente.App) (ente.MultipartUploadURLs, error) {
if count <= 0 || count > maxMultipartPartCount {
return ente.MultipartUploadURLs{}, stacktrace.Propagate(ente.ErrBadRequest, "multipart upload cannot exceed %d parts", maxMultipartPartCount)
diff --git a/server/pkg/controller/file_meta.go b/server/pkg/controller/file_meta.go
index ef3185e9ef..6c1ecb6eba 100644
--- a/server/pkg/controller/file_meta.go
+++ b/server/pkg/controller/file_meta.go
@@ -6,7 +6,6 @@ import (
"github.com/gin-gonic/gin"
)
-// CreateMetaFile adds an entry for a file in the respective tables
func (c *FileController) CreateMetaFile(ctx *gin.Context, userID int64, file ente.MetaFile, userAgent string, app ente.App) (*ente.File, error) {
collection, collErr := c.CollectionRepo.Get(file.CollectionID)
if collErr != nil {
diff --git a/server/pkg/controller/filedata/controller.go b/server/pkg/controller/filedata/controller.go
index febd422bf3..da330d4aec 100644
--- a/server/pkg/controller/filedata/controller.go
+++ b/server/pkg/controller/filedata/controller.go
@@ -30,7 +30,6 @@ import (
gTime "time"
)
-// _fetchConfig is the configuration for the fetching objects from S3
type _fetchConfig struct {
RetryCount int
InitialTimeout gTime.Duration
@@ -55,9 +54,8 @@ type Controller struct {
CollectionRepo *repo.CollectionRepository
DiscordController *discord.DiscordController
downloadManagerCache map[string]*s3manager.Downloader
- // for downloading objects from s3 for replication
- workerURL string
- tempStorage string
+ workerURL string
+ tempStorage string
}
func New(repo *fileDataRepo.Repository,
@@ -116,8 +114,6 @@ func (c *Controller) InsertOrUpdateMetadata(ctx *gin.Context, req *fileData.PutF
DecryptionHeader: *req.DecryptionHeader,
Client: network.GetClientInfo(ctx),
}
- // Start a goroutine to handle the upload and insert operations
- //go func() {
logger := log.WithField("objectKey", objectKey).WithField("fileID", req.FileID).WithField("type", req.Type)
size, uploadErr := c.uploadObject(obj, objectKey, bucketID)
if uploadErr != nil {
@@ -137,7 +133,6 @@ func (c *Controller) InsertOrUpdateMetadata(ctx *gin.Context, req *fileData.PutF
logger.WithError(dbInsertErr).Error("insert or update failed")
return stacktrace.Propagate(dbInsertErr, "failed to insert or update file data row")
}
- //}()
return nil
}
@@ -201,14 +196,12 @@ func (c *Controller) GetFilesData(ctx *gin.Context, req fileData.GetFilesData) (
}
}
pendingIndexFileIds := array.FindMissingElementsInSecondList(req.FileIDs, dbFileIds)
- // Fetch missing doRows in parallel
s3MetaFetchResults, err := c.getS3FileMetadataParallel(ctx, activeRows)
if err != nil {
return nil, stacktrace.Propagate(err, "")
}
fetchedEmbeddings := make([]fileData.Entity, 0)
- // Populate missing data in doRows from fetched objects
for _, obj := range s3MetaFetchResults {
if obj.err != nil {
errFileIds = append(errFileIds, obj.dbEntry.FileID)
@@ -236,9 +229,9 @@ func (c *Controller) getS3FileMetadataParallel(ctx *gin.Context, dbRows []fileDa
for i := range dbRows {
index := i
dbRow := dbRows[i]
- globalFileFetchSemaphore <- struct{}{} // Acquire from global semaphore
+ globalFileFetchSemaphore <- struct{}{}
wg.Go(func() {
- defer func() { <-globalFileFetchSemaphore }() // Release back to global semaphore
+ defer func() { <-globalFileFetchSemaphore }()
ctxLogger := log.WithFields(log.Fields{
"objectKey": dbRow.S3FileMetadataObjectKey(),
@@ -293,18 +286,16 @@ func (c *Controller) fetchS3FileMetadata(ctx context.Context, row fileData.Row,
return nil, stacktrace.Propagate(ctx.Err(), "")
default:
obj, err := c.downloadObject(fetchCtx, objectKey, dc)
- cancel() // Ensure cancel is called to release resources
+ cancel()
if err == nil {
if i > 0 {
ctxLogger.WithField("dc", dc).Infof("Fetched object after %d attempts", i)
}
return &obj, nil
}
- // Check if the error is due to context timeout or cancellation
if err == nil && fetchCtx.Err() != nil {
ctxLogger.WithField("dc", dc).Error("Fetch timed out or cancelled: ", fetchCtx.Err())
} else {
- // check if the error is due to object not found
if s3Err, ok := err.(awserr.RequestFailure); ok {
if s3Err.Code() == s3.ErrCodeNoSuchKey {
return nil, stacktrace.Propagate(errors.New("object not found"), "")
@@ -359,7 +350,6 @@ func (c *Controller) _validateLastUpdatedAt(ctx *gin.Context, lastUpdatedAt *int
return nil
}
-// _checkPreviewWritePerm is
func (c *Controller) _checkPreviewWritePerm(ctx *gin.Context, fileID int64, actorID int64) error {
err := c.AccessCtrl.VerifyFileOwnership(ctx, &access.VerifyFileOwnershipParams{
ActorUserId: actorID,
diff --git a/server/pkg/controller/filedata/delete.go b/server/pkg/controller/filedata/delete.go
index dd90a99c7a..674da15a34 100644
--- a/server/pkg/controller/filedata/delete.go
+++ b/server/pkg/controller/filedata/delete.go
@@ -14,7 +14,6 @@ import (
"time"
)
-// StartDataDeletion clears associated file data from the object store
func (c *Controller) StartDataDeletion() {
go c.startDeleteWorkers(1)
}
@@ -29,8 +28,6 @@ func (c *Controller) startDeleteWorkers(n int) {
}
}
-// Entry point for the delete worker (goroutine)
-//
// i is an arbitrary index of the current routine.
func (c *Controller) delete(i int) {
// This is just
@@ -99,7 +96,6 @@ func (c *Controller) deleteFileRow(fileDataRow filedata.Row) error {
ctxLogger.WithError(err).Error("Failed to get bucketColumnMap")
return err
}
- // Delete objects and remove buckets
for bucketID, columnName := range bucketColumnMap {
for _, objectKey := range objectKeys {
delErr := c.ObjectCleanupController.DeleteObjectFromDataCenter(objectKey, bucketID)
@@ -122,7 +118,6 @@ func (c *Controller) deleteFileRow(fileDataRow filedata.Row) error {
}
}
- // Delete from Latest bucket
for k := range objectKeys {
err = c.ObjectCleanupController.DeleteObjectFromDataCenter(objectKeys[k], fileDataRow.LatestBucket)
if err != nil {
@@ -164,7 +159,6 @@ func (c *Controller) deleteFileRowV2(fileDataRow filedata.Row) error {
ctxLogger.WithError(err).Error("Failed to get bucketColumnMap")
return err
}
- // Delete objects and remove buckets
for bucketID, columnName := range bucketColumnMap {
delErr := c.ObjectCleanupController.DeleteAllObjectsWithPrefix(delPrefix, bucketID)
if delErr != nil {
@@ -186,7 +180,6 @@ func (c *Controller) deleteFileRowV2(fileDataRow filedata.Row) error {
}
}
- // Delete from Latest bucket
err = c.ObjectCleanupController.DeleteAllObjectsWithPrefix(delPrefix, fileDataRow.LatestBucket)
if err != nil {
ctxLogger.WithError(err).Error("Failed to delete object from datacenter")
diff --git a/server/pkg/controller/filedata/replicate.go b/server/pkg/controller/filedata/replicate.go
index b84c32d64e..a2b47e0a70 100644
--- a/server/pkg/controller/filedata/replicate.go
+++ b/server/pkg/controller/filedata/replicate.go
@@ -16,8 +16,6 @@ import (
"time"
)
-// StartReplication starts the replication process for file data.
-// If
func (c *Controller) StartReplication() error {
workerURL := viper.GetString("replication.worker-url")
if workerURL == "" {
@@ -72,8 +70,6 @@ func (c *Controller) startWorkers(n int) {
}
}
-// Entry point for the replication worker (goroutine)
-//
// i is an arbitrary index of the current routine.
func (c *Controller) replicate(i int) {
for {
diff --git a/server/pkg/controller/filedata/s3.go b/server/pkg/controller/filedata/s3.go
index 226b4f52b3..ac25a1c010 100644
--- a/server/pkg/controller/filedata/s3.go
+++ b/server/pkg/controller/filedata/s3.go
@@ -120,7 +120,6 @@ func (c *Controller) downloadObject(ctx context.Context, objectKey string, dc st
return obj, nil
}
-// uploadObject uploads the embedding object to the object store and returns the object size
func (c *Controller) uploadObject(obj fileData.S3FileMetadata, objectKey string, dc string) (int64, error) {
embeddingObj, _ := json.Marshal(obj)
s3Client := c.S3Config.GetS3Client(dc)
@@ -162,7 +161,6 @@ func (c *Controller) verifySize(bucketID string, objectKey string, expectedSize
if *res.ContentLength != expectedSize {
err = fmt.Errorf("size of the uploaded file (%d) does not match the expected size (%d) in bucket %s",
*res.ContentLength, expectedSize, *bucket)
- //c.notifyDiscord(fmt.Sprint(err))
return stacktrace.Propagate(err, "")
}
return nil
@@ -175,7 +173,6 @@ type ReplicateObjectReq struct {
ObjectSize int64
}
-// copyObject copies the object from srcObjectKey to destObjectKey in the same bucket and returns the object size
func (c *Controller) replicateObject(ctx context.Context, req *ReplicateObjectReq) error {
if err := file.EnsureSufficientSpace(req.ObjectSize); err != nil {
return stacktrace.Propagate(err, "")
@@ -186,7 +183,6 @@ func (c *Controller) replicateObject(ctx context.Context, req *ReplicateObjectRe
}
defer os.Remove(filePath)
defer file.Close()
- //s3Client := c.S3Config.GetS3Client(req.SrcBucketID)
bucket := c.S3Config.GetBucket(req.SrcBucketID)
downloader := c.downloadManagerCache[req.SrcBucketID]
_, err = downloader.DownloadWithContext(ctx, file, &s3.GetObjectInput{
@@ -212,7 +208,6 @@ func (c *Controller) replicateObject(ctx context.Context, req *ReplicateObjectRe
return stacktrace.Propagate(err, "Failed to upload object to bucket %s", req.DestBucketID)
}
log.Infof("Uploaded to bucket %s", result.Location)
- // verify the size of the uploaded object
if err := c.verifySize(req.DestBucketID, req.ObjectKey, req.ObjectSize); err != nil {
return stacktrace.Propagate(err, "")
}
diff --git a/server/pkg/controller/lock/lock.go b/server/pkg/controller/lock/lock.go
index 9baeaacb2d..b6bf609b43 100644
--- a/server/pkg/controller/lock/lock.go
+++ b/server/pkg/controller/lock/lock.go
@@ -8,7 +8,6 @@ import (
log "github.com/sirupsen/logrus"
)
-// LockController exposes functions to obtain locks before entering critical sections
type LockController struct {
TaskLockingRepo *repo.TaskLockRepository
HostName string
@@ -49,7 +48,6 @@ func (c *LockController) ExtendLock(lockID string, lockUntil int64) error {
return nil
}
-// Release a lock that was obtained earlier using TryLock.
func (c *LockController) ReleaseLock(lockID string) {
err := c.TaskLockingRepo.ReleaseLock(lockID)
if err != nil {
diff --git a/server/pkg/controller/mailing_lists.go b/server/pkg/controller/mailing_lists.go
index e027e57a53..b5c15b9922 100644
--- a/server/pkg/controller/mailing_lists.go
+++ b/server/pkg/controller/mailing_lists.go
@@ -15,14 +15,6 @@ import (
"github.com/spf13/viper"
)
-// MailingListsController is used to keeping the external mailing lists in sync
-// with customer email changes.
-//
-// MailingListsController contains methods for keeping external mailing lists in
-// sync when new users sign up, or update their email, or delete their account.
-// Currently, these mailing lists are hosted on Zoho Campaigns.
-//
-// See also: Syncing emails with Zoho Campaigns
type MailingListsController struct {
zohoAccessToken string
zohoListKey string
@@ -33,7 +25,6 @@ type MailingListsController struct {
discordController *discord.DiscordController
}
-// Return a new instance of MailingListsController
func NewMailingListsController(discordController *discord.DiscordController) *MailingListsController {
zohoCredentials := zoho.Credentials{
ClientID: viper.GetString("zoho.client-id"),
@@ -41,20 +32,8 @@ func NewMailingListsController(discordController *discord.DiscordController) *Ma
RefreshToken: viper.GetString("zoho.refresh-token"),
}
- // The Zoho "List Key" identifies a particular list of email IDs that are
- // stored in Zoho. All the actions that we perform (adding, removing and
- // updating emails) are done on this list.
- //
- // https://www.zoho.com/campaigns/help/developers/list-management.html
zohoListKey := viper.GetString("zoho.list-key")
- // List of topics to which emails are sent.
- //
- // Ostensibly, we can get them from their API
- // https://www.zoho.com/campaigns/oldhelp/api/get-topics.html
- //
- // But that doesn't currently work, luckily we can get these IDs by looking
- // at the HTML source of the topic update dashboard page.
zohoTopicIds := viper.GetString("zoho.topic-ids")
// Zoho has a rate limit on the number of access tokens that can created
@@ -69,8 +48,6 @@ func NewMailingListsController(discordController *discord.DiscordController) *Ma
Password: viper.GetString("listmonk.password"),
}
- // An array of integer values indicating the id of listmonk campaign
- // mailing list to which the subscriber needs to added
listmonkListIDs := viper.GetIntSlice("listmonk.list-ids")
return &MailingListsController{
@@ -120,13 +97,8 @@ func (c *MailingListsController) Subscribe(email string) error {
return nil
}
-// Unsubscribe the given email address to our default Zoho Campaigns list
-// or Listmonk Campaigns List
-//
-// See: [Note: Syncing emails with Zoho Campaigns]
func (c *MailingListsController) Unsubscribe(email string) error {
if !(c.shouldSkipZoho()) {
- // https://www.zoho.com/campaigns/help/developers/contact-unsubscribe.html
err := c.doListActionZoho("listunsubscribe", email)
if err != nil {
return stacktrace.Propagate(err, "")
@@ -141,30 +113,18 @@ func (c *MailingListsController) Unsubscribe(email string) error {
return nil
}
-// shouldSkipZoho() checks if the MailingListsController
-// should be skipped due to missing credentials.
func (c *MailingListsController) shouldSkipZoho() bool {
return c.zohoCredentials.RefreshToken == ""
}
-// shouldSkipListmonk() checks if the Listmonk mailing list
-// should be skipped due to missing credentials
-// listmonklistIDs value.
-//
-// ListmonkListIDs is an optional field for subscribing an email address
-// (user gets added to the default list),
-// but is a required field for unsubscribing an email address
func (c *MailingListsController) shouldSkipListmonk() bool {
if c.listmonkCredentials.BaseURL == "" || c.listmonkCredentials.Username == "" ||
c.listmonkCredentials.Password == "" || len(c.listmonkListIDs) == 0 {
- // Skip
return true
}
return false
}
-// Both the listsubscribe and listunsubscribe Zoho Campaigns API endpoints work
-// similarly, so use this function to keep the common code.
func (c *MailingListsController) doListActionZoho(action string, email string) error {
// Query escape the email so that any pluses get converted to %2B.
escapedEmail := url.QueryEscape(email)
@@ -210,7 +170,6 @@ func (c *MailingListsController) doListActionZoho(action string, email string) e
return stacktrace.Propagate(err, "")
}
-// Subscribes an email address to a particular listmonk campaign mailing list
func (c *MailingListsController) listmonkSubscribe(email string) error {
data := map[string]interface{}{
"email": email,
@@ -225,7 +184,6 @@ func (c *MailingListsController) listmonkSubscribe(email string) error {
return err
}
-// Unsubscribes an email address to a particular listmonk campaign mailing list
func (c *MailingListsController) listmonkUnsubscribe(email string) error {
// Listmonk doesn't provide an endpoint for unsubscribing users
// from a particular list directly via their email
diff --git a/server/pkg/controller/object.go b/server/pkg/controller/object.go
index 6108317bbb..597bdf0b4b 100644
--- a/server/pkg/controller/object.go
+++ b/server/pkg/controller/object.go
@@ -43,7 +43,6 @@ const (
// DeleteObjectQueue delay (x days currently).
func (c *ObjectController) RemoveComplianceHolds() {
if c.S3Config.WasabiComplianceDC() == "" {
- // Wasabi compliance is currently disabled in config, nothing to do.
return
}
if c.complianceCronRunning {
diff --git a/server/pkg/controller/object_cleanup.go b/server/pkg/controller/object_cleanup.go
index e0d644878c..59cb11663f 100644
--- a/server/pkg/controller/object_cleanup.go
+++ b/server/pkg/controller/object_cleanup.go
@@ -33,13 +33,10 @@ type ObjectCleanupController struct {
S3Config *s3config.S3Config
}
-// PreSignedRequestValidityDuration is the lifetime of a pre-signed URL
const PreSignedRequestValidityDuration = 7 * 24 * stime.Hour
-// PreSignedPartUploadRequestDuration is the lifetime of a pre-signed multipart URL
const PreSignedPartUploadRequestDuration = 7 * 24 * stime.Hour
-// Return a new instance of ObjectCleanupController
func NewObjectCleanupController(
objectCleanupRepo *repo.ObjectCleanupRepository,
objectRepo *repo.ObjectRepository,
@@ -52,8 +49,6 @@ func NewObjectCleanupController(
}
}
-// StartRemovingUnreportedObjects starts goroutines to cleanup deletes those
-// objects that were possibly uploaded but not reported to the database
func (c *ObjectCleanupController) StartRemovingUnreportedObjects() {
// TODO: object_cleanup: This code is only currently tested for B2
if c.S3Config.GetHotDataCenter() != c.S3Config.GetHotBackblazeDC() {
@@ -73,8 +68,6 @@ func (c *ObjectCleanupController) StartRemovingUnreportedObjects() {
}
}
-// Entry point for the worker goroutine to cleanup unreported objects.
-//
// i is an arbitrary index for the current goroutine.
func (c *ObjectCleanupController) removeUnreportedObjectsWorker(i int) {
for {
@@ -190,8 +183,6 @@ func (c *ObjectCleanupController) AddTempObjectKey(objectKey string, dc string)
return c.addCleanupEntryForObjectKey(objectKey, dc, expiry)
}
-// Add the object to a queue of "temporary" objects that are deleted (if they
-// exist) if this entry is not removed from the queue by expirationTime.
func (c *ObjectCleanupController) addCleanupEntryForObjectKey(objectKey string, dc string, expirationTime int64) error {
err := c.Repo.AddTempObject(ente.TempObject{
ObjectKey: objectKey,
@@ -201,10 +192,6 @@ func (c *ObjectCleanupController) addCleanupEntryForObjectKey(objectKey string,
return stacktrace.Propagate(err, "")
}
-// AddTempObjectMultipartKey creates a new temporary object entry for a
-// multlipart upload.
-//
-// See AddTempObjectKey for more details.
func (c *ObjectCleanupController) AddMultipartTempObjectKey(objectKey string, uploadID string, dc string) error {
expiry := time.Microseconds() + (2 * PreSignedPartUploadRequestDuration.Microseconds())
err := c.Repo.AddTempObject(ente.TempObject{
diff --git a/server/pkg/controller/playstore.go b/server/pkg/controller/playstore.go
index 6240dba88e..c0072b4739 100644
--- a/server/pkg/controller/playstore.go
+++ b/server/pkg/controller/playstore.go
@@ -20,7 +20,6 @@ import (
"google.golang.org/api/androidpublisher/v3"
)
-// PlayStoreController provides abstractions for handling billing on AppStore
type PlayStoreController struct {
PlayStoreClient *playstore.Client
BillingRepo *repo.BillingRepository
@@ -31,10 +30,8 @@ type PlayStoreController struct {
CommonBillCtrl *commonbilling.Controller
}
-// PlayStorePackageName is the package name of the PlayStore item
const PlayStorePackageName = "io.ente.photos"
-// Return a new instance of PlayStoreController
func NewPlayStoreController(
plans ente.BillingPlansPerCountry,
billingRepo *repo.BillingRepository,
@@ -84,7 +81,6 @@ func newPlayStoreClient() (*playstore.Client, error) {
return playStoreClient, nil
}
-// HandleNotification handles a PlayStore notification
func (c *PlayStoreController) HandleNotification(notification playstore.DeveloperNotification) error {
transactionID := notification.SubscriptionNotification.PurchaseToken
productID := notification.SubscriptionNotification.SubscriptionID
@@ -113,7 +109,6 @@ func (c *PlayStoreController) HandleNotification(notification playstore.Develope
}
return stacktrace.Propagate(err, "")
}
- // send deletion email for folks who are either on individual plan or admin of a family plan
if user.FamilyAdminID == nil || *user.FamilyAdminID == subscription.UserID {
storage, surpErr := c.StorageBonusRepo.GetPaidAddonSurplusStorage(context.Background(), subscription.UserID)
if surpErr != nil {
@@ -159,7 +154,7 @@ func (c *PlayStoreController) HandleNotification(notification playstore.Develope
break
}
}
- if newPlan.Storage < subscription.Storage { // Downgrade
+ if newPlan.Storage < subscription.Storage {
canDowngrade, canDowngradeErr := c.CommonBillCtrl.CanDowngradeToGivenStorage(newPlan.Storage, subscription.UserID)
if canDowngradeErr != nil {
return stacktrace.Propagate(canDowngradeErr, "")
@@ -198,7 +193,6 @@ func (c *PlayStoreController) HandleNotification(notification playstore.Develope
return c.BillingRepo.LogPlayStorePush(subscription.UserID, notification, *purchase)
}
-// GetVerifiedSubscription verifies and returns the verified subscription
func (c *PlayStoreController) GetVerifiedSubscription(userID int64, productID string, verificationData string) (ente.Subscription, error) {
var s ente.Subscription
s.UserID = userID
@@ -221,14 +215,12 @@ func (c *PlayStoreController) GetVerifiedSubscription(userID int64, productID st
return s, nil
}
-// AcknowledgeSubscription acknowledges a subscription to PlayStore
func (c *PlayStoreController) AcknowledgeSubscription(subscriptionID string, token string) error {
req := &androidpublisher.SubscriptionPurchasesAcknowledgeRequest{}
context := context.Background()
return c.PlayStoreClient.AcknowledgeSubscription(context, PlayStorePackageName, subscriptionID, token, req)
}
-// CancelSubscription cancels a PlayStore subscription
func (c *PlayStoreController) CancelSubscription(subscriptionID string, verificationData string) error {
context := context.Background()
return c.PlayStoreClient.CancelSubscription(context, PlayStorePackageName, subscriptionID, verificationData)
diff --git a/server/pkg/controller/push.go b/server/pkg/controller/push.go
index 108d34a3e8..4b10a8dffc 100644
--- a/server/pkg/controller/push.go
+++ b/server/pkg/controller/push.go
@@ -25,7 +25,6 @@ import (
"golang.org/x/oauth2/google"
)
-// PushController controls all push related operations
type PushController struct {
PushRepo *repo.PushTokenRepository
TaskLockRepo *repo.TaskLockRepository
@@ -42,10 +41,8 @@ type PushToken struct {
LastNotifiedAt int64
}
-// Interval before which the last push was sent
const pushIntervalInMinutes = 60
-// Max number of devices to notify in a single run.
const concurrentPushesInOneShot = 500
const fcmSendConcurrency = 10
diff --git a/server/pkg/controller/replication3.go b/server/pkg/controller/replication3.go
index bcb890ce10..76d4548d26 100644
--- a/server/pkg/controller/replication3.go
+++ b/server/pkg/controller/replication3.go
@@ -50,14 +50,10 @@ type ReplicationController3 struct {
ObjectRepo *repo.ObjectRepository
ObjectCopiesRepo *repo.ObjectCopiesRepository
DiscordController *discord.DiscordController
- // URL of the Cloudflare worker to use for downloading the source object
workerURL string
- // Base directory for temporary storage
tempStorage string
- // Prometheus Metrics
mUploadSuccess *prometheus.CounterVec
mUploadFailure *prometheus.CounterVec
- // Cached S3 clients etc
b2Client *s3.S3
b2Bucket *string
wasabiDest *UploadDestination
@@ -69,11 +65,9 @@ type UploadDestination struct {
Client *s3.S3
Uploader *s3manager.Uploader
Bucket *string
- // The label to use for reporting metrics for uploads to this destination
Label string
// If true, we should ignore Wasabi 403 errors. See "Reuploads".
HasComplianceHold bool
- // If true, the object is uploaded to the GLACIER class.
IsGlacier bool
}
@@ -84,9 +78,6 @@ type UploadDestination struct {
// asynchronously, as and when it notices new files that have not yet been
// replicated (it does this by querying the object_copies table).
func (c *ReplicationController3) StartReplication() error {
- // As a safety check, ensure that the current hot storage bucket is in b2.
- // This is because the replication v3 code has not yet been tested for other
- // scenarios (it'll likely work though, probably with minor modifications).
hotDC := c.S3Config.GetHotDataCenter()
if hotDC != c.S3Config.GetHotBackblazeDC() {
return fmt.Errorf("v3 replication can currently only run when the primary hot data center is Backblaze. Instead, it was %s", hotDC)
@@ -201,8 +192,6 @@ func (c *ReplicationController3) createDestinations() {
}
}
-// Entry point for the replication worker (goroutine)
-//
// i is an arbitrary index of the current routine.
func (c *ReplicationController3) replicate(i int) {
// This is just
@@ -228,7 +217,6 @@ func (c *ReplicationController3) replicate(i int) {
// A common and expected error is `sql.ErrNoRows`, which occurs if there are no
// objects left to replicate currently.
func (c *ReplicationController3) tryReplicate() error {
- // Fetch an object to replicate
ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
copies, err := c.ObjectCopiesRepo.GetAndLockUnreplicatedObject(ctxWithTimeout)
@@ -351,9 +339,6 @@ func (c *ReplicationController3) tryReplicate() error {
return done(err)
}
-// Download the object for objectKey from B2 hot storage, writing it into file.
-//
-// Return the size of the downloaded file.
func (c *ReplicationController3) downloadFromB2ViaWorker(objectKey string, file *os.File, logger *log.Entry) (int64, error) {
presignedURL, err := c.getPresignedB2URL(objectKey)
if err != nil {
@@ -404,7 +389,6 @@ func (c *ReplicationController3) downloadFromB2ViaWorker(objectKey string, file
return n, nil
}
-// Get a presigned URL to download the object with objectKey from the B2 bucket.
func (c *ReplicationController3) getPresignedB2URL(objectKey string) (string, error) {
r, _ := c.b2Client.GetObjectRequest(&s3.GetObjectInput{
Bucket: c.b2Bucket,
@@ -424,7 +408,6 @@ type UploadInput struct {
Logger *log.Entry
}
-// Upload, verify and then update the DB to mark replication to dest.
func (c *ReplicationController3) replicateFile(in *UploadInput, dest *UploadDestination, dbUpdateCopies func() error) error {
start := time.Now()
logger := in.Logger.WithFields(log.Fields{
@@ -442,7 +425,6 @@ func (c *ReplicationController3) replicateFile(in *UploadInput, dest *UploadDest
if err != nil {
return failure(stacktrace.Propagate(err, "Failed to upload object"))
}
- // log if time taken is more than 2 seconds and speed is less than .5MB/s
if time.Since(start) > slowUploadThreshold {
elapsed := time.Since(start)
uploadSpeedMBps := float64(in.ExpectedSize) / (elapsed.Seconds() * 1024 * 1024)
@@ -498,8 +480,6 @@ func (c *ReplicationController3) replicateFile(in *UploadInput, dest *UploadDest
return nil
}
-// Upload the given file to using uploader to the given bucket.
-//
// # Reuploads
//
// It is possible that the object might already exist on remote. The known
@@ -517,7 +497,6 @@ func (c *ReplicationController3) replicateFile(in *UploadInput, dest *UploadDest
// object verification using the HEAD request will act as a sanity check for
// the object.
func (c *ReplicationController3) uploadFile(in *UploadInput, dest *UploadDestination) error {
- // Rewind the file pointer back to the start for the next upload.
in.File.Seek(0, io.SeekStart)
up := s3manager.UploadInput{
@@ -543,32 +522,6 @@ func (c *ReplicationController3) uploadFile(in *UploadInput, dest *UploadDestina
return nil
}
-// Return true if the given error is because of an HTTP 403.
-//
-// See "Reuploads" for the scenario where these errors can arise.
-//
-// Specifically, this in an example of the HTTP 403 response we get when
-// trying to add an object to a Wasabi bucket that already has a compliance
-// locked object with the same key.
-//
-// HTTP/1.1 403 Forbidden
-// Content-Type: application/xml
-// Date: Tue, 20 Dec 2022 10:23:33 GMT
-// Server: WasabiS3/7.10.1193-2022-11-23-84c72037e8 (head2)
-//
-// <?xml version="1.0" encoding="UTF-8"?>
-// <Error>
-// <Code>AccessDenied</Code>
-// <Message>Access Denied</Message>
-// <RequestId>yyy</RequestId>
-// <HostId>zzz</HostId>
-// </Error>
-//
-// Printing the error type and details produces this:
-//
-// type: *s3err.RequestFailure
-// AccessDenied: Access Denied
-// status code: 403, request id: yyy, host id: zzz
func (c *ReplicationController3) isRequestFailureAccessDenied(err error) bool {
if reqerr, ok := err.(s3.RequestFailure); ok {
if reqerr.Code() == "AccessDenied" {
@@ -578,7 +531,6 @@ func (c *ReplicationController3) isRequestFailureAccessDenied(err error) bool {
return false
}
-// Verify the uploaded file by doing a HEAD check and comparing sizes
func (c *ReplicationController3) verifyUploadedFileSize(in *UploadInput, dest *UploadDestination) error {
res, err := dest.Client.HeadObject(&s3.HeadObjectInput{
Bucket: dest.Bucket,
diff --git a/server/pkg/controller/stripe.go b/server/pkg/controller/stripe.go
index ed1b0e12eb..4827f326ec 100644
--- a/server/pkg/controller/stripe.go
+++ b/server/pkg/controller/stripe.go
@@ -30,7 +30,6 @@ import (
"golang.org/x/text/currency"
)
-// StripeController provides abstractions for handling billing on Stripe
type StripeController struct {
StripeClients ente.StripeClientPerAccount
BillingPlansPerAccount ente.BillingPlansPerAccount
@@ -46,7 +45,6 @@ type StripeController struct {
const BufferPeriodOnPaymentFailureInDays = 7
-// Return a new instance of StripeController
func NewStripeController(plans ente.BillingPlansPerAccount, stripeClients ente.StripeClientPerAccount, billingRepo *repo.BillingRepository, fileRepo *repo.FileRepository, userRepo *repo.UserRepository, storageBonusRepo *storagebonus.Repository, discordController *discord.DiscordController, emailNotificationController *emailCtrl.EmailNotificationController, offerController *offer.OfferController, commonBillCtrl *commonbilling.Controller) *StripeController {
return &StripeController{
StripeClients: stripeClients,
@@ -62,7 +60,6 @@ func NewStripeController(plans ente.BillingPlansPerAccount, stripeClients ente.S
}
}
-// GetCheckoutSession handles the creation of stripe checkout session for subscription purchase
func (c *StripeController) GetCheckoutSession(productID string, userID int64, redirectRootURL string) (string, error) {
if productID == "" {
return "", stacktrace.Propagate(ente.ErrBadRequest, "")
@@ -110,7 +107,6 @@ func (c *StripeController) GetCheckoutSession(productID string, userID int64, re
var stripeClient *client.API
if subscription.PaymentProvider == ente.Stripe {
stripeClient = c.StripeClients[subscription.Attributes.StripeAccountCountry]
- // attach the subscription to existing customerID
params.Customer = stripe.String(subscription.Attributes.CustomerID)
} else {
stripeClient = c.StripeClients[ente.DefaultStripeAccountCountry]
@@ -118,7 +114,6 @@ func (c *StripeController) GetCheckoutSession(productID string, userID int64, re
if err != nil {
return "", stacktrace.Propagate(err, "")
}
- // attach user's emailID to the checkout session and subsequent subscription bought
params.CustomerEmail = stripe.String(user.Email)
}
@@ -129,17 +124,14 @@ func (c *StripeController) GetCheckoutSession(productID string, userID int64, re
return s.ID, nil
}
-// GetVerifiedSubscription verifies and returns the verified subscription
func (c *StripeController) GetVerifiedSubscription(userID int64, sessionID string) (ente.Subscription, error) {
var stripeSubscription stripe.Subscription
var err error
if sessionID != "" {
log.Info("Received session ID: " + sessionID)
- // Get verified subscription request was received from success redirect page
stripeSubscription, err = c.getStripeSubscriptionFromSession(userID, sessionID)
} else {
log.Info("Did not receive a session ID")
- // Get verified subscription request for a subscription update
stripeSubscription, err = c.getUserStripeSubscription(userID)
}
if err != nil {
@@ -210,8 +202,6 @@ func (c *StripeController) findHandlerForEvent(event stripe.Event) func(event st
}
}
-// Payment is successful and the subscription is created.
-// You should provision the subscription.
func (c *StripeController) handleCheckoutSessionCompleted(event stripe.Event, country ente.StripeAccountCountry) (ente.StripeEventLog, error) {
var session stripe.CheckoutSession
json.Unmarshal(event.Data.Raw, &session)
@@ -324,7 +314,6 @@ func (c *StripeController) handleCustomerSubscriptionUpdated(event stripe.Event,
return ente.StripeEventLog{UserID: userID, StripeSubscription: stripeSubscription, Event: event}, nil
}
-// Continue to provision the subscription as payments continue to be made.
func (c *StripeController) handleInvoicePaid(event stripe.Event, country ente.StripeAccountCountry) (ente.StripeEventLog, error) {
var invoice stripe.Invoice
json.Unmarshal(event.Data.Raw, &invoice)
@@ -449,7 +438,7 @@ func (c *StripeController) UpdateSubscription(stripeID string, userID int64) (en
if subscription.PaymentProvider != ente.Stripe || subscription.ProductID == stripeID || subscription.Attributes.StripeAccountCountry != newStripeAccountCountry {
return ente.SubscriptionUpdateResponse{}, stacktrace.Propagate(ente.ErrBadRequest, "")
}
- if newPlan.Storage < subscription.Storage { // Downgrade
+ if newPlan.Storage < subscription.Storage {
canDowngrade, canDowngradeErr := c.CommonBillCtrl.CanDowngradeToGivenStorage(newPlan.Storage, userID)
if canDowngradeErr != nil {
return ente.SubscriptionUpdateResponse{}, stacktrace.Propagate(canDowngradeErr, "")
@@ -659,7 +648,7 @@ func (c *StripeController) getPriceIDFromSession(sessionID string) (string, erro
params := &stripe.CheckoutSessionListLineItemsParams{}
params.AddExpand("data.price")
items := stripeClient.CheckoutSessions.ListLineItems(sessionID, params)
- for items.Next() { // Return the first PriceID that has been fetched
+ for items.Next() {
return items.LineItem().Price.ID, nil
}
return "", stacktrace.Propagate(ente.ErrNotFound, "")
@@ -825,8 +814,6 @@ func getPaymentIntentErrorPaymentMethodType(paymentIntent stripe.PaymentIntent)
return paymentIntent.LastPaymentError.PaymentMethodType
}
-// handleStripeError processes Stripe errors, sends Discord alerts for invalid_request_error,
-// and returns user-friendly errors to prevent 5xx responses
func (c *StripeController) handleStripeError(err error, userID int64, context string) error {
if err == nil {
return nil
@@ -834,13 +821,10 @@ func (c *StripeController) handleStripeError(err error, userID int64, context st
stripeError, ok := err.(*stripe.Error)
if !ok {
- // Not a Stripe error, propagate as-is
return stacktrace.Propagate(err, "")
}
- // Check if it's an invalid_request_error
if stripeError.Type == stripe.ErrorTypeInvalidRequest {
- // Send Discord alert with details
alertMsg := fmt.Sprintf(
"⚠️ Stripe Invalid Request Error\n"+
"**Context:** %s\n"+
@@ -858,13 +842,11 @@ func (c *StripeController) handleStripeError(err error, userID int64, context st
)
c.DiscordController.Notify(alertMsg)
- // Return user-friendly error based on error code
var userMsg string
switch stripeError.Code {
case stripe.ErrorCodeResourceMissing:
userMsg = "The requested resource no longer exists. Please create a new subscription or contact support."
default:
- // For other invalid_request_error codes, use the Stripe message if available
if stripeError.Msg != "" {
userMsg = fmt.Sprintf("Unable to process request: %s", stripeError.Msg)
} else {
@@ -875,6 +857,5 @@ func (c *StripeController) handleStripeError(err error, userID int64, context st
return stacktrace.Propagate(ente.NewBadRequestWithMessage(userMsg), "")
}
- // For other Stripe errors, propagate as-is
return stacktrace.Propagate(err, "")
}
diff --git a/server/pkg/controller/trash.go b/server/pkg/controller/trash.go
index fa0bdd6493..118ec38075 100644
--- a/server/pkg/controller/trash.go
+++ b/server/pkg/controller/trash.go
@@ -14,7 +14,6 @@ import (
log "github.com/sirupsen/logrus"
)
-// TrashController has the business logic related to trash feature
type TrashController struct {
TrashRepo *repo.TrashRepository
FileRepo *repo.FileRepository
@@ -25,12 +24,9 @@ type TrashController struct {
dropFileMetadataRunning bool
collectionTrashRunning bool
emptyTrashRunning bool
- // deleteAgedTrashRunning indicates whether the cron to delete trashed files which are in trash
- // since repo.TrashDurationInDays is running
- deleteAgedTrashRunning bool
+ deleteAgedTrashRunning bool
}
-// GetDiff returns the changes in user's trash since a timestamp, along with hasMore bool flag.
func (t *TrashController) GetDiff(userID int64, sinceTime int64, stripMetadata bool, app ente.App) ([]ente.Trash, bool, error) {
trashFilesDiff, hasMore, err := t.getDiff(userID, sinceTime, repo.TrashDiffLimit, app)
if err != nil {
@@ -121,7 +117,6 @@ func (t *TrashController) CleanupTrashedCollections() {
t.collectionTrashRunning = false
}()
- // process delete collection request for DELETE V3
itemsV3, err2 := t.QueueRepo.GetItemsReadyForDeletion(repo.TrashCollectionQueueV3, 100)
if err2 != nil {
log.Error("Could not fetch from collection trash queue", err2)
@@ -142,7 +137,6 @@ func (t *TrashController) ProcessEmptyTrashRequests() {
defer func() {
t.emptyTrashRunning = false
}()
- // Process photos queue
items, err := t.QueueRepo.GetItemsReadyForDeletion(repo.TrashEmptyQueue, 100)
if err != nil {
log.Error("Could not fetch from emptyTrashQueue queue", err)
@@ -152,7 +146,6 @@ func (t *TrashController) ProcessEmptyTrashRequests() {
}
}
- // Process locker queue
itemsLocker, err2 := t.QueueRepo.GetItemsReadyForDeletion(repo.TrashEmptyLockerQueue, 100)
if err2 != nil {
log.Error("Could not fetch from emptyTrashLockerQueue queue", err2)
@@ -163,7 +156,6 @@ func (t *TrashController) ProcessEmptyTrashRequests() {
}
}
-// DeleteAgedTrashedFiles delete trashed files which are in trash since repo.TrashDurationInDays
func (t *TrashController) DeleteAgedTrashedFiles() {
if t.deleteAgedTrashRunning {
log.Info("Already deleting older trashed files, skipping cron")
diff --git a/server/pkg/controller/trash_file_metadata.go b/server/pkg/controller/trash_file_metadata.go
index ce7e0e9158..c74c781f2d 100644
--- a/server/pkg/controller/trash_file_metadata.go
+++ b/server/pkg/controller/trash_file_metadata.go
@@ -10,7 +10,6 @@ import (
log "github.com/sirupsen/logrus"
)
-// DropFileMetadataCron removes the metadata for deleted files
func (t *TrashController) DropFileMetadataCron() {
ctx := context.Background()
lockName := "dropTrashedFileMetadata"
diff --git a/server/pkg/controller/usage.go b/server/pkg/controller/usage.go
index 93d09da804..63f399655d 100644
--- a/server/pkg/controller/usage.go
+++ b/server/pkg/controller/usage.go
@@ -13,7 +13,6 @@ import (
"github.com/ente/stacktrace"
)
-// UsageController exposes functions which can be used to check around storage
type UsageController struct {
mu sync.Mutex
BillingCtrl *BillingController
@@ -26,11 +25,10 @@ type UsageController struct {
UploadResultCache map[int64]bool
}
-// Locker limits by subscription tier
const lockerFreeFileLimit = 100
const lockerPaidFileLimit = 1000
-const lockerFreeStorageLimit = 1 * 1024 * 1024 * 1024 // 1 GiB
-const lockerPaidStorageLimit = 10 * 1024 * 1024 * 1024 // 10 GiB
+const lockerFreeStorageLimit = 1 * 1024 * 1024 * 1024
+const lockerPaidStorageLimit = 10 * 1024 * 1024 * 1024
const hundredMBInBytes = 100 * 1024 * 1024
@@ -56,7 +54,6 @@ func GetLockerLimitsForTier(isPaid bool) LockerLimits {
// 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 {
- // check if size is nil or less than 100 MB
if app != ente.Locker && (size == nil || *size < hundredMBInBytes) {
c.mu.Lock()
canUpload, ok := c.UploadResultCache[userID]
@@ -127,7 +124,6 @@ func (c *UsageController) canUploadFile(ctx context.Context, userID int64, size
} else {
subStorage = sub.Storage
}
- // Plan expiry check is done at this point
var lockerUsage *repo.LockerUsage
var lUsageErr error
if app == ente.Locker {
@@ -136,7 +132,6 @@ func (c *UsageController) canUploadFile(ctx context.Context, userID int64, size
return stacktrace.Propagate(lUsageErr, "failed to fetch locker usage")
}
- // Determine if user has paid subscription for tiered limits
isPaidUser := false
if err := c.BillingCtrl.HasActiveSelfOrFamilySubscription(subscriptionAdminID, true); err == nil {
isPaidUser = true
@@ -144,12 +139,10 @@ func (c *UsageController) canUploadFile(ctx context.Context, userID int64, size
limits := GetLockerLimitsForTier(isPaidUser)
- // Check file count limit
if lockerUsage.TotalFileCount >= limits.FileLimit {
return stacktrace.Propagate(&ente.ErrFileLimitReached, "")
}
- // Check storage limit
projectedLockerUsage := lockerUsage.TotalUsage
if size != nil {
projectedLockerUsage += *size
@@ -168,13 +161,11 @@ func (c *UsageController) canUploadFile(ctx context.Context, userID int64, size
newUsage := usage
if size != nil {
- // Add the size of the file to be uploaded to the current usage and buffer in sub.Storage
newUsage += *size
subStorage += StorageOverflowAboveSubscriptionLimit
}
if newUsage > subStorage {
if bonus == nil {
- // Check if the subAdmin has any storage bonus
bonus, err = c.UserCacheCtrl.GetActiveStorageBonus(ctx, subscriptionAdminID)
if err != nil {
return stacktrace.Propagate(err, "failed to get storage bonus")
diff --git a/server/pkg/controller/user/inactive_user_orchestrator.go b/server/pkg/controller/user/inactive_user_orchestrator.go
index 2709922f44..5de608a918 100644
--- a/server/pkg/controller/user/inactive_user_orchestrator.go
+++ b/server/pkg/controller/user/inactive_user_orchestrator.go
@@ -181,8 +181,6 @@ func buildInactiveUserRunSummary(stats inactiveUserRunStats, runAt int64) string
return fmt.Sprintf("%s: %s", summary, strings.Join(parts, " | "))
}
-// InactiveUserOrchestrator sends inactivity warning emails and final account
-// deletion notifications for users who stay inactive across all apps.
type InactiveUserOrchestrator struct {
UserRepo *repo.UserRepository
NotificationHistoryRepo *repo.NotificationHistoryRepository
diff --git a/server/pkg/controller/user/jwt.go b/server/pkg/controller/user/jwt.go
index 8a7df40c73..fa3dc67a40 100644
--- a/server/pkg/controller/user/jwt.go
+++ b/server/pkg/controller/user/jwt.go
@@ -12,7 +12,6 @@ import (
"github.com/golang-jwt/jwt/v4"
)
-// jwt token validity = 1 day
const ValidForDays = 1
var errJWTExpired = &ente.ApiError{
@@ -35,10 +34,7 @@ func (c *UserController) GetJWTToken(userID int64, scope enteJWT.ClaimScope) (st
}
func (c *UserController) GetJWTTokenForClaim(claim *enteJWT.WebCommonJWTClaim) (string, error) {
- // Create a new token object, specifying signing method and the claims
- // you would like it to contain.
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claim)
- // Sign and get the complete encoded token as a string using the secret
tokenString, err := token.SignedString(c.JwtSecret)
if err != nil {
diff --git a/server/pkg/controller/user/passkey.go b/server/pkg/controller/user/passkey.go
index f6486384d1..e89c1e4cff 100644
--- a/server/pkg/controller/user/passkey.go
+++ b/server/pkg/controller/user/passkey.go
@@ -7,7 +7,6 @@ import (
"github.com/gin-gonic/gin"
)
-// GetTwoFactorRecoveryStatus returns a user's passkey reset status
func (c *UserController) GetTwoFactorRecoveryStatus(ctx *gin.Context) (*ente.TwoFactorRecoveryStatus, error) {
userID := auth.GetUserID(ctx.Request.Header)
return c.TwoFactorRecoveryRepo.GetStatus(userID)
diff --git a/server/pkg/controller/user/srp.go b/server/pkg/controller/user/srp.go
index 203275f6a8..ad7c8409cc 100644
--- a/server/pkg/controller/user/srp.go
+++ b/server/pkg/controller/user/srp.go
@@ -65,7 +65,6 @@ func (c *UserController) CompleteSRPSetup(context *gin.Context, req ente.Complet
}, nil
}
-// UpdateSrpAndKeyAttributes updates the SRP and keys attributes if the SRP setup is successfully done
func (c *UserController) UpdateSrpAndKeyAttributes(context *gin.Context,
userID int64,
req ente.UpdateSRPAndKeysRequest,
diff --git a/server/pkg/controller/user/twofactor.go b/server/pkg/controller/user/twofactor.go
index f37e987e9d..28162fd062 100644
--- a/server/pkg/controller/user/twofactor.go
+++ b/server/pkg/controller/user/twofactor.go
@@ -20,7 +20,6 @@ import (
log "github.com/sirupsen/logrus"
)
-// SetupTwoFactor generates a two factor secret and sends it to user to setup his authenticator app with
func (c *UserController) SetupTwoFactor(userID int64) (ente.TwoFactorSecret, error) {
user, err := c.UserRepo.Get(userID)
if err != nil {
@@ -57,7 +56,6 @@ func (c *UserController) SetupTwoFactor(userID int64) (ente.TwoFactorSecret, err
return ente.TwoFactorSecret{SecretCode: key.Secret(), QRCode: base64.StdEncoding.EncodeToString(buf.Bytes())}, nil
}
-// EnableTwoFactor handles the two factor activation request after user has setup his two factor by validing a totp request
func (c *UserController) EnableTwoFactor(userID int64, request ente.TwoFactorEnableRequest) error {
encryptedSecrets, hashedSecrets, err := c.TwoFactorRepo.GetTempTwoFactorSecret(userID)
if err != nil {
@@ -99,7 +97,6 @@ func (c *UserController) EnableTwoFactor(userID int64, request ente.TwoFactorEna
return stacktrace.Propagate(err, "")
}
-// VerifyTwoFactor handles the two factor validation request
func (c *UserController) VerifyTwoFactor(context *gin.Context, sessionID string, otp string) (ente.TwoFactorAuthorizationResponse, error) {
userID, err := c.TwoFactorRepo.GetUserIDWithTwoFactorSession(sessionID)
if err != nil {
@@ -164,14 +161,11 @@ func (c *UserController) VerifyTwoFactor(context *gin.Context, sessionID string,
return response, nil
}
-// DisableTwoFactor disables the two factor authentication for a user
func (c *UserController) DisableTwoFactor(userID int64) error {
err := c.TwoFactorRepo.UpdateTwoFactorStatus(userID, false)
return stacktrace.Propagate(err, "")
}
-// RecoverTwoFactor handles the two factor recovery request by sending the
-// recoveryKeyEncryptedTwoFactorSecret for the user to decrypt it and make twoFactor removal api call
func (c *UserController) RecoverTwoFactor(sessionID string) (*ente.TwoFactorRecoveryResponse, error) {
userID, err := c.TwoFactorRepo.GetUserIDWithTwoFactorSession(sessionID)
if err != nil {
@@ -184,8 +178,6 @@ func (c *UserController) RecoverTwoFactor(sessionID string) (*ente.TwoFactorReco
return &response, nil
}
-// RemoveTOTPTwoFactor handles two factor deactivation request if user lost his device
-// by authenticating him using his twoFactorsessionToken and twoFactor secret
func (c *UserController) RemoveTOTPTwoFactor(context *gin.Context, sessionID string, secret string) (*ente.TwoFactorAuthorizationResponse, error) {
userID, err := c.TwoFactorRepo.GetUserIDWithTwoFactorSession(sessionID)
if err != nil {
diff --git a/server/pkg/controller/user/user.go b/server/pkg/controller/user/user.go
index b31a7f8090..626d3798ec 100644
--- a/server/pkg/controller/user/user.go
+++ b/server/pkg/controller/user/user.go
@@ -40,7 +40,6 @@ type SpaceAccountDeletionAccessResetter interface {
ResetAccountDeletionAccess(ctx context.Context, userID int64) error
}
-// UserController exposes request handlers for all user related requests
type UserController struct {
UserRepo *repo.UserRepository
TwoFactorRecoveryRepo *two_factor_recovery.Repository
@@ -67,7 +66,7 @@ type UserController struct {
HashingKey []byte
SecretEncryptionKey []byte
JwtSecret []byte
- Cache *cache.Cache // refers to the auth token cache
+ Cache *cache.Cache
HardCodedOTT HardCodedOTT
UserCache *cache2.UserCache
UserCacheController *usercache.Controller
@@ -77,29 +76,18 @@ type UserController struct {
}
const (
- // OTTValidityDurationInMicroSeconds is the duration for which an OTT is valid
- // (60 minutes)
OTTValidityDurationInMicroSeconds = 60 * 60 * 1000000
- // OTTWrongAttemptLimit is the max number of wrong attempt to verify OTT (to prevent bruteforce guessing)
- // When client hits this limit, they will need to trigger new OTT.
OTTWrongAttemptLimit = 20
- // OTTActiveCodeLimit is the max number of active OTT a user can have in
- // a time window of OTTValidityDurationInMicroSeconds duration
OTTActiveCodeLimit = 10
- // TwoFactorValidityDurationInMicroSeconds is the duration for which an OTT is valid
- // (10 minutes)
TwoFactorValidityDurationInMicroSeconds = 10 * 60 * 1000000
- // TokenLength is the length of the token issued to a verified user
TokenLength = 32
- // TwoFactorSessionIDLength is the length of the twoFactorSessionID issued to a verified user
TwoFactorSessionIDLength = 32
- // PassKeySessionIDLength is the length of the passKey sessionID issued to a verified user
PassKeySessionIDLength = 32
CryptoPwhashMemLimitInteractive = 67108864
@@ -107,8 +95,6 @@ const (
TOTPIssuerORG = "ente"
- // Template and subject for the mail that we send when the user deletes
- // their account.
AccountDeletedEmailTemplate = "account_deleted.html"
AccountDeletedWithActiveSubscriptionEmailTemplate = "account_deleted_active_sub.html"
AccountDeletedEmailSubject = "Your Ente account has been deleted"
@@ -181,15 +167,13 @@ func NewUserController(
}
}
-// GetAttributes returns the key attributes for a user
func (c *UserController) GetAttributes(userID int64) (ente.KeyAttributes, error) {
return c.UserRepo.GetKeyAttributes(userID)
}
-// SetAttributes sets the attributes for a user. The request will fail if key attributes are already set
func (c *UserController) SetAttributes(userID int64, request ente.SetUserAttributesRequest) error {
_, err := c.UserRepo.GetKeyAttributes(userID)
- if err == nil { // If there are key attributes already set
+ if err == nil {
return stacktrace.Propagate(ente.ErrPermissionDenied, "key attributes are already set")
}
if request.KeyAttributes.MemLimit <= 0 || request.KeyAttributes.OpsLimit <= 0 {
@@ -205,7 +189,6 @@ func (c *UserController) SetAttributes(userID int64, request ente.SetUserAttribu
return nil
}
-// UpdateEmailMFA updates the email MFA for a user.
func (c *UserController) UpdateEmailMFA(context *gin.Context, userID int64, isEnabled bool) error {
if !isEnabled {
isSrpSetupDone, err := c.UserAuthRepo.IsSRPSetupDone(context, userID)
@@ -220,7 +203,6 @@ func (c *UserController) UpdateEmailMFA(context *gin.Context, userID int64, isEn
return c.UserAuthRepo.UpdateEmailMFA(context, userID, isEnabled)
}
-// SetRecoveryKey sets the recovery key attributes for a user, if not already set
func (c *UserController) SetRecoveryKey(userID int64, request ente.SetRecoveryKeyRequest) error {
keyAttr, keyErr := c.UserRepo.GetKeyAttributes(userID)
if keyErr != nil {
@@ -236,7 +218,6 @@ func (c *UserController) SetRecoveryKey(userID int64, request ente.SetRecoveryKe
return nil
}
-// GetPublicKey returns the public key of a user
func (c *UserController) GetPublicKey(requesterUserID int64, email string) (string, error) {
userID, err := c.UserLookup.LookupUserID(requesterUserID, email)
if err != nil {
@@ -249,7 +230,6 @@ func (c *UserController) GetPublicKey(requesterUserID int64, email string) (stri
return key, nil
}
-// GetTwoFactorStatus returns a user's two factor status
func (c *UserController) GetTwoFactorStatus(userID int64) (bool, error) {
isTwoFactorEnabled, err := c.UserRepo.IsTwoFactorEnabled(userID)
if err != nil {
diff --git a/server/pkg/controller/user/user_details.go b/server/pkg/controller/user/user_details.go
index 00c3110fea..8d63582a7d 100644
--- a/server/pkg/controller/user/user_details.go
+++ b/server/pkg/controller/user/user_details.go
@@ -106,9 +106,6 @@ func (c *UserController) GetDetailsV2(ctx *gin.Context, userID int64, fetchMemor
})
}
- // g.Wait waits for all goroutines to complete
- // and returns the first non-nil error returned
- // by one of the goroutines.
if err := g.Wait(); err != nil {
return details.UserDetailsResponse{}, stacktrace.Propagate(err, "")
}
diff --git a/server/pkg/controller/user/userauth.go b/server/pkg/controller/user/userauth.go
index b9e2597b26..794e5a4275 100644
--- a/server/pkg/controller/user/userauth.go
+++ b/server/pkg/controller/user/userauth.go
@@ -90,7 +90,6 @@ func hardcodedOTTForEmail(hardCodedOTT HardCodedOTT, email string) string {
return ""
}
-// SendEmailOTT generates and sends an OTT to the provided email address
func (c *UserController) SendEmailOTT(context *gin.Context, email string, purpose string, mobile bool) error {
if c.OTTSendLimiter.IsGloballyBlocked() {
return stacktrace.Propagate(ente.ErrTooManyBadRequest, "too many OTT requests")
@@ -107,7 +106,6 @@ func (c *UserController) SendEmailOTT(context *gin.Context, email string, purpos
if err != nil {
return stacktrace.Propagate(err, "")
}
- // check if user has already requested for more than 10 codes in last 10mins
app := auth.GetApp(context)
otts, err := c.UserAuthRepo.GetValidOTTs(emailHash, app)
if err != nil {
@@ -163,11 +161,9 @@ func (c *UserController) SendEmailOTT(context *gin.Context, email string, purpos
func (c *UserController) isEmailAlreadyUsed(email string) error {
_, err := c.UserRepo.GetUserIDWithEmailUnrestricted(email)
if err == nil {
- // email already owned by a user
return stacktrace.Propagate(ente.ErrPermissionDenied, "email already belongs to a user")
}
if !errors.Is(err, sql.ErrNoRows) {
- // unknown error, rethrow
return stacktrace.Propagate(err, "")
}
return nil
@@ -312,8 +308,6 @@ func (c *UserController) verifyEmailOtt(context *gin.Context, email string, ott
return nil
}
-// VerifyEmail validates that the OTT provided in the request is valid for the
-// provided email address and if yes returns the users credentials
func (c *UserController) VerifyEmail(context *gin.Context, request ente.EmailVerificationRequest) (ente.EmailAuthorizationResponse, error) {
email := emailUtil.NormalizeEmail(request.Email)
err := c.verifyEmailOtt(context, email, request.OTT)
@@ -323,8 +317,6 @@ func (c *UserController) VerifyEmail(context *gin.Context, request ente.EmailVer
return c.onVerificationSuccess(context, email, request.Source)
}
-// ChangeEmail validates that the OTT provided in the request is valid for the
-// provided email address and if yes updates the user's existing email address
func (c *UserController) ChangeEmail(ctx *gin.Context, request ente.EmailVerificationRequest) error {
email := emailUtil.NormalizeEmail(request.Email)
err := c.verifyEmailOtt(ctx, email, request.OTT)
@@ -335,17 +327,14 @@ func (c *UserController) ChangeEmail(ctx *gin.Context, request ente.EmailVerific
return c.UpdateEmail(ctx, auth.GetUserID(ctx.Request.Header), email)
}
-// UpdateEmail updates the email address of the user with the provided userID
func (c *UserController) UpdateEmail(ctx *gin.Context, userID int64, email string) error {
email = emailUtil.NormalizeEmail(email)
_, err := c.UserRepo.GetUserIDWithEmailUnrestricted(email)
if err == nil {
- // email already owned by a user
return stacktrace.Propagate(ente.ErrPermissionDenied, "")
}
if !errors.Is(err, sql.ErrNoRows) {
- // unknown error, rethrow
return stacktrace.Propagate(err, "")
}
user, err := c.UserRepo.Get(userID)
@@ -418,7 +407,6 @@ func (c *UserController) touchContactsAfterEmailUpdate(ctx *gin.Context, userID
}
}
-// Logout removes the token from the cache and database.
// known issue: the token may be still cached in other instances till the expiry time (10min), JWTs might remain too
func (c *UserController) Logout(ctx *gin.Context) error {
token := auth.GetToken(ctx)
@@ -426,7 +414,6 @@ func (c *UserController) Logout(ctx *gin.Context) error {
return c.TerminateSession(userID, token)
}
-// GetActiveSessions returns the list of active tokens for userID
func (c *UserController) GetActiveSessions(context *gin.Context, userID int64) ([]ente.Session, error) {
tokens, err := c.UserAuthRepo.GetActiveSessions(userID, auth.GetApp(context))
if err != nil {
@@ -562,7 +549,6 @@ func (c *UserController) AddTokenAndNotify(ctx *gin.Context, userID int64, app e
return nil
}
-// RemoveTokensForApps marks the given app tokens as deleted and evicts them from the auth cache.
func (c *UserController) RemoveTokensForApps(userID int64, apps []ente.App) error {
if len(apps) == 0 {
return nil
@@ -590,7 +576,6 @@ func (c *UserController) RemoveAllTokens(userID int64) error {
return nil
}
-// TerminateSession removes the token for a user from cache and database
func (c *UserController) TerminateSession(userID int64, token string) error {
apps, err := c.UserAuthRepo.GetAppsForUser(userID)
if err != nil {
@@ -642,8 +627,6 @@ func emailOTT(app ente.App, to string, ott string, purpose string, mobile bool)
return nil
}
-// onVerificationSuccess is called when the user has successfully verified their email address.
-// source indicates where the user came from. It can be nil.
func (c *UserController) onVerificationSuccess(context *gin.Context, email string, source *string) (ente.EmailAuthorizationResponse, error) {
isTwoFactorEnabled := false
app := auth.GetApp(context)
diff --git a/server/pkg/repo/authenticator/entity.go b/server/pkg/repo/authenticator/entity.go
index 501fa96733..b7a27f4318 100644
--- a/server/pkg/repo/authenticator/entity.go
+++ b/server/pkg/repo/authenticator/entity.go
@@ -12,7 +12,6 @@ import (
"github.com/sirupsen/logrus"
)
-// Create inserts a new entry
func (r *Repository) Create(ctx context.Context, userID int64, entry model.CreateEntityRequest) (uuid.UUID, error) {
id := uuid.New()
err := r.DB.QueryRow(`INSERT into authenticator_entity(
@@ -20,10 +19,10 @@ func (r *Repository) Create(ctx context.Context, userID int64, entry model.Creat
user_id,
encrypted_data,
header) VALUES ($1,$2,$3,$4) RETURNING id`,
- id, //$1 id
- userID, // $2 user_id
- entry.EncryptedData, // $3 encrypted_data
- entry.Header). // $4 header
+ id,
+ userID,
+ entry.EncryptedData,
+ entry.Header).
Scan(&id)
if err != nil {
return id, stacktrace.Propagate(err, "Failed to createTotpEntry")
@@ -38,8 +37,8 @@ func (r *Repository) Get(ctx context.Context, userID int64, id uuid.UUID) (model
FROM authenticator_entity
WHERE id = $1 AND
user_id = $2`,
- id, // $1
- userID, // %2 // $3
+ id,
+ userID,
)
err := row.Scan(&res.ID, &res.UserID, &res.EncryptedData, &res.Header, &res.IsDeleted, &res.CreatedAt, &res.UpdatedAt)
if err != nil {
@@ -88,7 +87,6 @@ func (r *Repository) Update(ctx context.Context, userID int64, req model.UpdateE
return nil
}
-// GetAuthCodeCount returns the count of the authenticator entries for the given user
func (r *Repository) GetAuthCodeCount(ctx context.Context, userID int64) (int64, error) {
var count int64
err := r.DB.QueryRowContext(ctx, `SELECT count(*) FROM authenticator_entity WHERE user_id = $1 and is_deleted = FALSE`, userID).Scan(&count)
@@ -98,8 +96,6 @@ func (r *Repository) GetAuthCodeCount(ctx context.Context, userID int64) (int64,
return count, nil
}
-// GetDiff returns the &{[]ente.TotpEntity} which have been added or
-// modified after the given sinceTime
func (r *Repository) GetDiff(ctx context.Context, userID int64, sinceTime int64, limit int16) ([]model.Entity, error) {
rows, err := r.DB.QueryContext(ctx, `SELECT
id, user_id, encrypted_data, header, is_deleted, created_at, updated_at
@@ -108,9 +104,9 @@ func (r *Repository) GetDiff(ctx context.Context, userID int64, sinceTime int64,
and updated_at > $2
ORDER BY updated_at
LIMIT $3`,
- userID, // $1
- sinceTime, // %2
- limit, // $3
+ userID,
+ sinceTime,
+ limit,
)
if err != nil {
return nil, stacktrace.Propagate(err, "GetDiff query failed")
diff --git a/server/pkg/repo/authenticator/key.go b/server/pkg/repo/authenticator/key.go
index 2370c7842a..51a4b459ae 100644
--- a/server/pkg/repo/authenticator/key.go
+++ b/server/pkg/repo/authenticator/key.go
@@ -10,14 +10,13 @@ import (
"github.com/ente/stacktrace"
)
-// CreateTotpEntry inserts a new &{totp.CreateTotpEntry} entry
func (r *Repository) CreateKey(ctx context.Context, userID int64, entry model.CreateKeyRequest) error {
_, err := r.DB.ExecContext(ctx, `INSERT into authenticator_key(
user_id,
encrypted_key,
header) VALUES ($1,$2,$3)`,
- userID, // $1 user_id
- entry.EncryptedKey, // $2 encrypted_data
+ userID,
+ entry.EncryptedKey,
entry.Header)
if err != nil {
diff --git a/server/pkg/repo/authenticator/repository.go b/server/pkg/repo/authenticator/repository.go
index ca2149a128..4946d292f8 100644
--- a/server/pkg/repo/authenticator/repository.go
+++ b/server/pkg/repo/authenticator/repository.go
@@ -4,8 +4,6 @@ import (
"database/sql"
)
-// Repository defines the methods for inserting, updating and retrieving
-// authenticator related keys and entities from the underlying repository
type Repository struct {
DB *sql.DB
}
diff --git a/server/pkg/repo/billing.go b/server/pkg/repo/billing.go
index d73ba40cfe..801c47b481 100644
--- a/server/pkg/repo/billing.go
+++ b/server/pkg/repo/billing.go
@@ -13,13 +13,10 @@ import (
"google.golang.org/api/androidpublisher/v3"
)
-// BillingRepository defines the methods for inserting, updating and retrieving
-// billing related entities from the underlying repository
type BillingRepository struct {
DB *sql.DB
}
-// AddSubscription adds a subscription against a userID
func (repo *BillingRepository) AddSubscription(s ente.Subscription) (int64, error) {
var subscriptionID int64
err := repo.DB.QueryRow(`INSERT INTO subscriptions(user_id, storage, original_transaction_id, expiry_time, product_id, payment_provider, attributes)
@@ -30,19 +27,16 @@ func (repo *BillingRepository) AddSubscription(s ente.Subscription) (int64, erro
return subscriptionID, stacktrace.Propagate(err, "")
}
-// UpdateSubscriptionExpiryTime updates the expiryTime of a subscription
func (repo *BillingRepository) UpdateSubscriptionExpiryTime(subscriptionID int64, expiryTime int64) error {
_, err := repo.DB.Exec(`UPDATE subscriptions SET expiry_time = $1 WHERE subscription_id = $2`, expiryTime, subscriptionID)
return stacktrace.Propagate(err, "")
}
-// UpdateSubscriptionCancellationStatus updates whether the user will cancel his subscription on period end
func (repo *BillingRepository) UpdateSubscriptionCancellationStatus(userID int64, status bool) error {
_, err := repo.DB.Exec(`UPDATE subscriptions SET attributes = jsonb_set(attributes, '{isCancelled}', $1::jsonb) WHERE user_id = $2`, status, userID)
return stacktrace.Propagate(err, "")
}
-// GetUserSubscription returns the last created subscription for a userID
func (repo *BillingRepository) GetUserSubscription(userID int64) (ente.Subscription, error) {
var s ente.Subscription
row := repo.DB.QueryRow(`SELECT subscription_id, user_id, product_id, storage, original_transaction_id, expiry_time, payment_provider, attributes FROM subscriptions WHERE user_id = $1`, userID)
@@ -50,7 +44,6 @@ func (repo *BillingRepository) GetUserSubscription(userID int64) (ente.Subscript
return s, stacktrace.Propagate(err, "")
}
-// GetSubscriptionForTransaction returns the subscription for a transactionID within a paymentProvider
func (repo *BillingRepository) GetSubscriptionForTransaction(transactionID string, paymentProvider ente.PaymentProvider) (ente.Subscription, error) {
var s ente.Subscription
row := repo.DB.QueryRow(`SELECT subscription_id, user_id, product_id, storage, original_transaction_id, expiry_time, payment_provider, attributes FROM subscriptions WHERE original_transaction_id = $1 AND payment_provider = $2`, transactionID, paymentProvider)
@@ -66,7 +59,6 @@ func (repo *BillingRepository) UpdateTransactionIDOnDeletion(userID int64) error
return stacktrace.Propagate(err, "")
}
-// ReplaceSubscription replaces a subscription with a new one
func (repo *BillingRepository) ReplaceSubscription(subscriptionID int64, s ente.Subscription) error {
_, err := repo.DB.Exec(`UPDATE subscriptions
SET storage = $2, original_transaction_id = $3, expiry_time = $4, product_id = $5, payment_provider = $6, attributes = $7, upgraded_at = $8
@@ -75,7 +67,6 @@ func (repo *BillingRepository) ReplaceSubscription(subscriptionID int64, s ente.
return stacktrace.Propagate(err, "")
}
-// UpdateSubscription updates a subscription
func (repo *BillingRepository) UpdateSubscription(
subscriptionID int64,
storage int64,
@@ -91,7 +82,6 @@ func (repo *BillingRepository) UpdateSubscription(
return stacktrace.Propagate(err, "")
}
-// LogPlayStorePush logs a notification from PlayStore
func (repo *BillingRepository) LogPlayStorePush(userID int64, notification playstore.DeveloperNotification, verificationResponse androidpublisher.SubscriptionPurchase) error {
notificationJSON, _ := json.Marshal(notification)
responseJSON, _ := json.Marshal(verificationResponse)
@@ -100,7 +90,6 @@ func (repo *BillingRepository) LogPlayStorePush(userID int64, notification plays
return stacktrace.Propagate(err, "")
}
-// LogAppStorePush logs a notification from AppStore
func (repo *BillingRepository) LogAppStorePush(userID int64, notification appstore.SubscriptionNotification, verificationResponse appstore.IAPResponse) error {
notificationJSON, _ := json.Marshal(notification)
responseJSON, _ := json.Marshal(verificationResponse)
@@ -146,7 +135,6 @@ func (repo *BillingRepository) IsUserOnPaidPlan(userID int64) (bool, error) {
return isPaidPlan, nil
}
-// LogStripePush logs a notification from Stripe
func (repo *BillingRepository) LogStripePush(eventLog ente.StripeEventLog) error {
notificationJSON, _ := json.Marshal(eventLog.Event)
responseJSON, _ := json.Marshal(eventLog.StripeSubscription)
@@ -155,7 +143,6 @@ func (repo *BillingRepository) LogStripePush(eventLog ente.StripeEventLog) error
return stacktrace.Propagate(err, "")
}
-// LogAdminTriggeredSubscriptionUpdate logs a subscription modification by an admin
func (repo *BillingRepository) LogAdminTriggeredSubscriptionUpdate(r ente.UpdateSubscriptionRequest) error {
requestJSON, _ := json.Marshal(r)
_, err := repo.DB.Exec(`INSERT INTO subscription_logs(user_id, payment_provider, notification, verification_response) VALUES($1, $2, $3, '{}'::json)`,
diff --git a/server/pkg/repo/cast/repo.go b/server/pkg/repo/cast/repo.go
index 6542cb0a8b..3319ae8512 100644
--- a/server/pkg/repo/cast/repo.go
+++ b/server/pkg/repo/cast/repo.go
@@ -50,7 +50,6 @@ func (r *Repository) GetAllDevices(ctx context.Context, userID int64) ([]cast.Ca
return devices, nil
}
-// InsertCastData inserts the cast payload and returns the paired device ID.
func (r *Repository) InsertCastData(ctx context.Context, castUserID int64, code string, collectionID int64, castToken string, encryptedPayload string) (uuid.UUID, error) {
code = strings.ToUpper(code)
var deviceID uuid.UUID
@@ -119,7 +118,6 @@ func (r *Repository) UpdateLastUsedAtForToken(ctx context.Context, token string)
return nil
}
-// DeleteUnclaimedCodes that are not associated with a collection and are older than the given time
func (r *Repository) DeleteUnclaimedCodes(ctx context.Context, expiryTime int64) error {
result, err := r.DB.ExecContext(ctx, "DELETE FROM casting WHERE last_used_at < $1 and is_deleted=false and collection_id is null", expiryTime)
if err != nil {
@@ -131,7 +129,6 @@ func (r *Repository) DeleteUnclaimedCodes(ctx context.Context, expiryTime int64)
return nil
}
-// DeleteOldSessions where last used at is older than the given time
func (r *Repository) DeleteOldSessions(ctx context.Context, expiryTime int64) error {
result, err := r.DB.ExecContext(ctx, "DELETE FROM casting WHERE last_used_at < $1", expiryTime)
if err != nil {
@@ -143,19 +140,16 @@ func (r *Repository) DeleteOldSessions(ctx context.Context, expiryTime int64) er
return nil
}
-// RevokeTokenForUser code for given userID
func (r *Repository) RevokeTokenForUser(ctx context.Context, userId int64) error {
_, err := r.DB.ExecContext(ctx, "UPDATE casting SET is_deleted=true where cast_user=$1", userId)
return stacktrace.Propagate(err, "")
}
-// RevokeTokenForCollection code for given collectionID
func (r *Repository) RevokeTokenForCollection(ctx context.Context, collectionID int64) error {
_, err := r.DB.ExecContext(ctx, "UPDATE casting SET is_deleted=true where collection_id=$1", collectionID)
return stacktrace.Propagate(err, "")
}
-// RevokeForGivenUserAndCollection ..
func (r *Repository) RevokeForGivenUserAndCollection(ctx context.Context, collectionID int64, userID int64) error {
_, err := r.DB.ExecContext(ctx, "UPDATE casting SET is_deleted=true where collection_id=$1 and cast_user=$2", collectionID, userID)
return stacktrace.Propagate(err, "")
diff --git a/server/pkg/repo/collection_files.go b/server/pkg/repo/collection_files.go
index 9df1892d71..b928d3a64a 100644
--- a/server/pkg/repo/collection_files.go
+++ b/server/pkg/repo/collection_files.go
@@ -11,8 +11,6 @@ import (
"github.com/lib/pq"
)
-// GetCollectionFileIDs return list of fileIDs are currently present in the given collection
-// and fileIDs are owned by the collection owner
func (repo *CollectionRepository) GetCollectionFileIDs(collectionID int64, collectionOwnerID int64) ([]int64, error) {
// Collaboration Todo: Filter out files which are not owned by the collection owner
rows, err := repo.DB.Query(
@@ -55,7 +53,6 @@ func (repo *CollectionRepository) GetCollectionFileState(ctx context.Context, co
}
func (repo *CollectionRepository) DoAllFilesExistInGivenCollections(fileIDs []int64, cIDs []int64) error {
- // Query to get all distinct file_ids that exist in the collections
rows, err := repo.DB.Query(`
SELECT DISTINCT file_id
FROM collection_files
@@ -69,25 +66,22 @@ func (repo *CollectionRepository) DoAllFilesExistInGivenCollections(fileIDs []in
}
defer rows.Close()
- // Create a map of input fileIDs for easy lookup
fileIDMap := make(map[int64]bool)
for _, id := range fileIDs {
- fileIDMap[id] = false // false means not found yet
+ fileIDMap[id] = false
}
- // Mark files that were found
for rows.Next() {
var fileID int64
if err := rows.Scan(&fileID); err != nil {
return stacktrace.Propagate(err, "")
}
- fileIDMap[fileID] = true // mark as found
+ fileIDMap[fileID] = true
}
if err = rows.Err(); err != nil {
return stacktrace.Propagate(err, "")
}
- // Collect missing files
var missingFiles []int64
for id, found := range fileIDMap {
if !found {
@@ -100,7 +94,6 @@ func (repo *CollectionRepository) DoAllFilesExistInGivenCollections(fileIDs []in
return nil
}
-// VerifyAllFileIDsExistsInCollection returns error if the fileIDs don't exist in the collection
func (repo *CollectionRepository) VerifyAllFileIDsExistsInCollection(ctx context.Context, cID int64, fileIDs []int64) error {
if len(fileIDs) == 0 {
return nil
@@ -122,7 +115,6 @@ func (repo *CollectionRepository) VerifyAllFileIDsExistsInCollection(ctx context
if err := rows.Err(); err != nil {
return stacktrace.Propagate(err, "")
}
- // find fileIds that are not present in the collection
for _, fileID := range fileIDs {
if _, ok := fileIdMap[fileID]; !ok {
return stacktrace.Propagate(fmt.Errorf("fileID %d not found in collection %d", fileID, cID), "")
@@ -182,7 +174,6 @@ func (repo *CollectionRepository) FilterActiveFileIDsInCollection(ctx context.Co
return active, nil
}
-// GetCollectionsFilesCount returns the number of non-deleted files which are present in the given collection
func (repo *CollectionRepository) GetCollectionsFilesCount(collectionID int64) (int64, error) {
row := repo.DB.QueryRow(`SELECT count(*) FROM collection_files WHERE collection_id=$1 AND is_deleted = false`, collectionID)
var count int64 = 0
diff --git a/server/pkg/repo/datacleanup/repository.go b/server/pkg/repo/datacleanup/repository.go
index 62f22710ef..0334773372 100644
--- a/server/pkg/repo/datacleanup/repository.go
+++ b/server/pkg/repo/datacleanup/repository.go
@@ -11,7 +11,6 @@ import (
"github.com/ente/stacktrace"
)
-// Repository wraps out interaction related to data_cleanup database table
type Repository struct {
DB *sql.DB
}
@@ -125,7 +124,6 @@ func (r *Repository) GetItemsPendingCompletion(ctx context.Context, limit int) (
return result, nil
}
-// MoveToNextStage update stage with corresponding schedule
func (r *Repository) MoveToNextStage(ctx context.Context, userID int64, stage entity.Stage, stageScheduleTime int64) error {
_, err := r.DB.ExecContext(ctx, `UPDATE data_cleanup
SET stage = $1, stage_schedule_time = $2, stage_attempt_count = 0, email_hash = NULL
@@ -133,7 +131,6 @@ func (r *Repository) MoveToNextStage(ctx context.Context, userID int64, stage en
return stacktrace.Propagate(err, "failed to insert/update")
}
-// ScheduleNextAttemptAfterNHours bumps the attempt count by one and schedule next attempt after n hr(s)
func (r *Repository) ScheduleNextAttemptAfterNHours(ctx context.Context, userID int64, n int32) error {
_, err := r.DB.ExecContext(ctx, `UPDATE data_cleanup SET stage_attempt_count = stage_attempt_count +1, stage_schedule_time = $1
WHERE user_id = $2`, time.MicrosecondsAfterHours(n), userID)
@@ -153,7 +150,6 @@ func (r *Repository) DeleteTableData(ctx context.Context, userID int64) error {
if err != nil {
return stacktrace.Propagate(err, "failed to delete entity key data")
}
- // delete entity_data
_, err = r.DB.ExecContext(ctx, `DELETE FROM entity_data WHERE user_id = $1`, userID)
if err != nil {
return stacktrace.Propagate(err, "failed to delete entity data")
@@ -178,28 +174,23 @@ func (r *Repository) DeleteTableData(ctx context.Context, userID int64) error {
if err != nil {
return stacktrace.Propagate(err, "failed to delete contact data")
}
- // deleting casting data
_, err = r.DB.ExecContext(ctx, `DELETE FROM casting WHERE cast_user = $1`, userID)
if err != nil {
return stacktrace.Propagate(err, "failed to delete casting data")
}
- // delete notification_history data
_, err = r.DB.ExecContext(ctx, `DELETE FROM notification_history WHERE user_id = $1`, userID)
if err != nil {
return stacktrace.Propagate(err, "failed to delete notification history data")
}
- // delete families data
_, err = r.DB.ExecContext(ctx, `DELETE FROM families WHERE admin_id = $1`, userID)
if err != nil {
return stacktrace.Propagate(err, "failed to delete family data")
}
- // delete passkeys (this also clears passkey_credentials via foreign key constraint)
_, err = r.DB.ExecContext(ctx, `DELETE FROM passkeys WHERE user_id = $1`, userID)
if err != nil {
return stacktrace.Propagate(err, "failed to delete passkeys data")
}
- // delete passkey_login_sessions
_, err = r.DB.ExecContext(ctx, `DELETE FROM passkey_login_sessions WHERE user_id = $1`, userID)
if err != nil {
return stacktrace.Propagate(err, "failed to delete passkey login sessions data")
@@ -209,27 +200,22 @@ func (r *Repository) DeleteTableData(ctx context.Context, userID int64) error {
return stacktrace.Propagate(err, "failed to delete remote store data")
}
- // delete srp_auth data
_, err = r.DB.ExecContext(ctx, `DELETE FROM srp_auth WHERE user_id = $1`, userID)
if err != nil {
return stacktrace.Propagate(err, "failed to delete srp auth data")
}
- // delete temp_srp_setup data
_, err = r.DB.ExecContext(ctx, `DELETE FROM temp_srp_setup WHERE user_id = $1`, userID)
if err != nil {
return stacktrace.Propagate(err, "failed to delete temp srp setup data")
}
- // delete two_factor data
_, err = r.DB.ExecContext(ctx, `DELETE FROM two_factor WHERE user_id = $1`, userID)
if err != nil {
return stacktrace.Propagate(err, "failed to delete two factor data")
}
- // delete tokens data
_, err = r.DB.ExecContext(ctx, `DELETE FROM tokens WHERE user_id = $1`, userID)
if err != nil {
return stacktrace.Propagate(err, "failed to delete tokens data")
}
- // delete webauthn_sessions data
_, err = r.DB.ExecContext(ctx, `DELETE FROM webauthn_sessions WHERE user_id = $1`, userID)
if err != nil {
return stacktrace.Propagate(err, "failed to delete web auth sessions data")
diff --git a/server/pkg/repo/embedding/repository.go b/server/pkg/repo/embedding/repository.go
index 5da669aa16..f384ab0cd7 100644
--- a/server/pkg/repo/embedding/repository.go
+++ b/server/pkg/repo/embedding/repository.go
@@ -7,8 +7,6 @@ import (
"github.com/lib/pq"
)
-// Repository defines the methods for inserting, updating and retrieving
-// ML embedding
type Repository struct {
DB *sql.DB
}
@@ -21,7 +19,6 @@ func (r *Repository) Delete(fileID int64) error {
return nil
}
-// GetDatacenters returns unique list of datacenters where derived embeddings are stored
func (r *Repository) GetDatacenters(ctx context.Context, fileID int64) ([]string, error) {
rows, err := r.DB.QueryContext(ctx, `SELECT datacenters FROM embeddings WHERE file_id = $1`, fileID)
if err != nil {
@@ -45,7 +42,6 @@ func (r *Repository) GetDatacenters(ctx context.Context, fileID int64) ([]string
return datacenters, nil
}
-// RemoveDatacenter removes the given datacenter from the list of datacenters
func (r *Repository) RemoveDatacenter(ctx context.Context, fileID int64, dc string) error {
_, err := r.DB.ExecContext(ctx, `UPDATE embeddings SET datacenters = array_remove(datacenters, $1) WHERE file_id = $2`, dc, fileID)
if err != nil {
diff --git a/server/pkg/repo/emergency/repository.go b/server/pkg/repo/emergency/repository.go
index 8391685230..711c7e6852 100644
--- a/server/pkg/repo/emergency/repository.go
+++ b/server/pkg/repo/emergency/repository.go
@@ -8,7 +8,6 @@ import (
"github.com/lib/pq"
)
-// Repository defines the methods for managing emergency contacts and recovery process.
type Repository struct {
DB *sql.DB
}
@@ -48,7 +47,7 @@ func (r *Repository) AddEmergencyContact(ctx context.Context, userID int64, emer
INSERT INTO emergency_contact(user_id, emergency_contact_id, state, encrypted_key, notice_period_in_hrs) VALUES ($1,$2,$3,$4,$5)
ON CONFLICT (user_id, emergency_contact_id) DO UPDATE SET state=$3, encrypted_key=$4, notice_period_in_hrs=$5
WHERE emergency_contact.user_id=$1 AND emergency_contact.emergency_contact_id=$2 AND emergency_contact.state = ANY($6)`,
- userID, // $1 user_id
+ userID,
emergencyContactID,
ente.UserInvitedContact,
encKey,
@@ -87,7 +86,6 @@ func (r *Repository) GetActiveContactForUser(ctx context.Context, userID int64)
return contacts, nil
}
-// GetActiveEmergencyContact for a given userID and emergencyContactID in active state
func (r *Repository) GetActiveEmergencyContact(ctx context.Context, userID int64, emergencyContactID int64) (*ContactRow, error) {
row := r.DB.QueryRowContext(ctx, `SELECT user_id, emergency_contact_id, state, notice_period_in_hrs, encrypted_key
FROM emergency_contact WHERE user_id=$1 and emergency_contact_id=$2 and state = $3`,
@@ -100,7 +98,6 @@ func (r *Repository) GetActiveEmergencyContact(ctx context.Context, userID int64
return &c, nil
}
-// UpdateState will return true if the state was updated, false if the state was not updated
func (r *Repository) UpdateState(ctx context.Context,
userID int64,
emergencyContactID int64,
diff --git a/server/pkg/repo/family.go b/server/pkg/repo/family.go
index 3dec623ff5..e4435b03d5 100644
--- a/server/pkg/repo/family.go
+++ b/server/pkg/repo/family.go
@@ -11,7 +11,6 @@ import (
"github.com/lib/pq"
)
-// FamilyRepository is an implementation of the FamilyRepo
type FamilyRepository struct {
DB *sql.DB
}
@@ -21,7 +20,6 @@ var (
ActiveOrInvitedFamilyMemberStatus = []ente.MemberStatus{ente.INVITED, ente.ACCEPTED, ente.SELF}
)
-// CreateFamily add the current user as the admin member.
func (repo *FamilyRepository) CreateFamily(ctx context.Context, adminID int64) error {
tx, err := repo.DB.BeginTx(ctx, nil)
if err != nil {
@@ -79,8 +77,6 @@ func (repo *FamilyRepository) CloseFamily(ctx context.Context, adminID int64) er
return stacktrace.Propagate(tx.Commit(), "failed to commit txn closing family")
}
-// AddMemberInvite inserts a family invitation entry for this given pair of admin & member and return the active inviteToken
-// which can be used to accept the invite
func (repo *FamilyRepository) AddMemberInvite(ctx context.Context, adminID int64, memberID int64, inviteToken string, storageLimit *int64) (string, error) {
if adminID == memberID {
return "", stacktrace.Propagate(errors.New("memberID and adminID can not be same"), "")
@@ -102,13 +98,11 @@ func (repo *FamilyRepository) AddMemberInvite(ctx context.Context, adminID int64
return activeInviteToken, stacktrace.Propagate(err, "")
}
-// GetInvite returns information about family invitation for given token
func (repo *FamilyRepository) GetInvite(token string) (ente.FamilyMember, error) {
row := repo.DB.QueryRow(`SELECT id, admin_id, member_id, status, storage_limit from families WHERE token = $1`, token)
return repo.convertRowToFamilyMember(row)
}
-// GetMemberById returns information about a particular member in a family
func (repo *FamilyRepository) GetMemberById(ctx context.Context, id uuid.UUID) (ente.FamilyMember, error) {
row := repo.DB.QueryRowContext(ctx, `SELECT id, admin_id, member_id, status, storage_limit from families WHERE id = $1`, id)
return repo.convertRowToFamilyMember(row)
@@ -124,7 +118,6 @@ func (repo *FamilyRepository) convertRowToFamilyMember(row *sql.Row) (ente.Famil
return member, nil
}
-// GetMembersWithStatus returns all the members in a family managed by given inviter
func (repo *FamilyRepository) GetMembersWithStatus(adminID int64, statuses []ente.MemberStatus) ([]ente.FamilyMember, error) {
rows, err := repo.DB.Query(`SELECT id, admin_id, member_id, status, storage_limit from families
WHERE admin_id = $1 and status = ANY($2)`, adminID, pq.Array(statuses))
@@ -135,7 +128,6 @@ func (repo *FamilyRepository) GetMembersWithStatus(adminID int64, statuses []ent
return convertRowsToFamilyMember(rows)
}
-// AcceptInvite change the invitation status in the family db for the given invite token
func (repo *FamilyRepository) AcceptInvite(ctx context.Context, adminID int64, memberID int64, token string) error {
tx, err := repo.DB.BeginTx(ctx, nil)
if err != nil {
@@ -163,7 +155,6 @@ func (repo *FamilyRepository) AcceptInvite(ctx context.Context, adminID int64, m
return stacktrace.Propagate(tx.Commit(), "failed to commit txn for accepting family invite")
}
-// RemoveMember removes an existing member from the family plan
func (repo *FamilyRepository) RemoveMember(ctx context.Context, adminID int64, memberID int64, removeReason ente.MemberStatus) error {
tx, err := repo.DB.BeginTx(ctx, nil)
if err != nil {
@@ -187,7 +178,6 @@ func (repo *FamilyRepository) RemoveMember(ctx context.Context, adminID int64, m
return stacktrace.Propagate(tx.Commit(), "failed to commit")
}
-// UpdateStorage is used to set Pre-existing Members Storage Limit.
func (repo *FamilyRepository) ModifyMemberStorage(ctx context.Context, adminID int64, id uuid.UUID, storageLimit *int64) error {
_, err := repo.DB.Exec(`UPDATE families SET storage_limit=$1 where id=$2`, storageLimit, id)
if err != nil {
@@ -197,7 +187,6 @@ func (repo *FamilyRepository) ModifyMemberStorage(ctx context.Context, adminID i
return stacktrace.Propagate(err, "Failed to Modify Members Storage Limit")
}
-// RevokeInvite revokes the invitation invite
func (repo *FamilyRepository) RevokeInvite(ctx context.Context, adminID int64, memberID int64) error {
tx, err := repo.DB.BeginTx(ctx, nil)
if err != nil {
@@ -211,7 +200,6 @@ func (repo *FamilyRepository) RevokeInvite(ctx context.Context, adminID int64, m
return stacktrace.Propagate(tx.Commit(), "failed to commit")
}
-// DeclineAnyPendingInvite is used for removing any pending invite for the user when their account is deleted
func (repo *FamilyRepository) DeclineAnyPendingInvite(ctx context.Context, memberID int64) error {
_, err := repo.DB.ExecContext(ctx, `UPDATE families set status=$1 WHERE member_id = $2 AND status = $3`, ente.DECLINED, memberID, ente.INVITED)
if err != nil {
diff --git a/server/pkg/repo/file_size.go b/server/pkg/repo/file_size.go
index 54771ae386..b41ddc7622 100644
--- a/server/pkg/repo/file_size.go
+++ b/server/pkg/repo/file_size.go
@@ -10,7 +10,6 @@ import (
log "github.com/sirupsen/logrus"
)
-// GetFilesInfo returns map of fileIDs to ente.FileInfo for a given userID.
func (repo *FileRepository) GetFilesInfo(ctx context.Context, fileIDs []int64, userID int64) (map[int64]*ente.FileInfo, error) {
rows, err := repo.DB.QueryContext(ctx, `SELECT file_id, info from files where file_id = ANY($1) and owner_id = $2`, pq.Array(fileIDs), userID)
if err != nil {
@@ -29,9 +28,7 @@ func (repo *FileRepository) GetFilesInfo(ctx context.Context, fileIDs []int64, u
return result, nil
}
-// UpdateSizeInfo updates the size info for a given map of fileIDs to ente.FileInfo.
func (repo *FileRepository) UpdateSizeInfo(ctx context.Context, sizeInfo map[int64]*ente.FileInfo) error {
- // Update the size info for each file using a batched transaction.
tx, err := repo.DB.BeginTx(ctx, nil)
if err != nil {
return stacktrace.Propagate(err, "")
@@ -49,7 +46,6 @@ func (repo *FileRepository) UpdateSizeInfo(ctx context.Context, sizeInfo map[int
return nil
}
-// GetFileInfoFromObjectKeys returns the file info for a given list of fileIDs.
func (repo *FileRepository) GetFileInfoFromObjectKeys(ctx context.Context, fileIDs []int64) (map[int64]*ente.FileInfo, error) {
rows, err := repo.DB.QueryContext(ctx, `SELECT file_id, size, o_type FROM object_keys WHERE file_id = ANY($1)`, pq.Array(fileIDs))
if err != nil {
diff --git a/server/pkg/repo/filedata/repository.go b/server/pkg/repo/filedata/repository.go
index 6c7eddee95..d70773c4a4 100644
--- a/server/pkg/repo/filedata/repository.go
+++ b/server/pkg/repo/filedata/repository.go
@@ -14,7 +14,6 @@ import (
"github.com/lib/pq"
)
-// Repository defines the methods for inserting, updating, and retrieving file data.
type Repository struct {
DB *sql.DB
ObjectCleanupRepo *repo.ObjectCleanupRepository
diff --git a/server/pkg/repo/memory_share.go b/server/pkg/repo/memory_share.go
index f020505ee9..4f568af376 100644
--- a/server/pkg/repo/memory_share.go
+++ b/server/pkg/repo/memory_share.go
@@ -12,13 +12,11 @@ import (
"github.com/spf13/viper"
)
-// MemoryShareRepository persists memory share rows and their files.
type MemoryShareRepository struct {
DB *sql.DB
memoryHost string
}
-// NewMemoryShareRepository builds a repository using the configured public memories host.
func NewMemoryShareRepository(db *sql.DB) *MemoryShareRepository {
memoryHost := viper.GetString("apps.public-memories")
if memoryHost == "" {
@@ -30,12 +28,10 @@ func NewMemoryShareRepository(db *sql.DB) *MemoryShareRepository {
}
}
-// GetMemoryShareURL constructs the public URL for a share token.
func (r *MemoryShareRepository) GetMemoryShareURL(accessToken string) string {
return fmt.Sprintf("%s/%s", r.memoryHost, accessToken)
}
-// Create inserts a memory share and returns the saved row.
func (r *MemoryShareRepository) Create(ctx context.Context, share ente.MemoryShare) (ente.MemoryShare, error) {
now := time.Microseconds()
err := r.DB.QueryRowContext(ctx, `
@@ -106,7 +102,6 @@ func (r *MemoryShareRepository) CreateWithFiles(ctx context.Context, share ente.
return share, nil
}
-// AddFiles appends files to an existing memory share.
func (r *MemoryShareRepository) AddFiles(ctx context.Context, shareID int64, files []ente.MemoryShareFile) error {
tx, err := r.DB.BeginTx(ctx, nil)
if err != nil {
@@ -132,7 +127,6 @@ func (r *MemoryShareRepository) AddFiles(ctx context.Context, shareID int64, fil
return nil
}
-// GetByID fetches a memory share by primary key.
func (r *MemoryShareRepository) GetByID(ctx context.Context, id int64) (*ente.MemoryShare, error) {
share := &ente.MemoryShare{}
err := r.DB.QueryRowContext(ctx, `
@@ -152,7 +146,6 @@ func (r *MemoryShareRepository) GetByID(ctx context.Context, id int64) (*ente.Me
return share, nil
}
-// GetByAccessToken fetches a memory share using its public token.
func (r *MemoryShareRepository) GetByAccessToken(ctx context.Context, token string) (*ente.MemoryShare, error) {
share := &ente.MemoryShare{}
err := r.DB.QueryRowContext(ctx, `
@@ -172,7 +165,6 @@ func (r *MemoryShareRepository) GetByAccessToken(ctx context.Context, token stri
return share, nil
}
-// GetFiles returns all file rows for a memory share.
func (r *MemoryShareRepository) GetFiles(ctx context.Context, shareID int64) ([]ente.MemoryShareFile, error) {
rows, err := r.DB.QueryContext(ctx, `
SELECT id, memory_share_id, file_id, file_owner_id, position, file_enc_key, file_key_decryption_nonce, created_at
@@ -196,7 +188,6 @@ func (r *MemoryShareRepository) GetFiles(ctx context.Context, shareID int64) ([]
return files, nil
}
-// GetFileIDs returns just the file IDs for a memory share.
func (r *MemoryShareRepository) GetFileIDs(ctx context.Context, shareID int64) ([]int64, error) {
rows, err := r.DB.QueryContext(ctx, `
SELECT file_id
@@ -219,7 +210,6 @@ func (r *MemoryShareRepository) GetFileIDs(ctx context.Context, shareID int64) (
return fileIDs, nil
}
-// GetByUserID returns all non-deleted shares created by a user.
func (r *MemoryShareRepository) GetByUserID(ctx context.Context, userID int64) ([]ente.MemoryShare, error) {
activeCreatedAfter := ente.ActiveMemoryShareCreatedAfter()
rows, err := r.DB.QueryContext(ctx, `
@@ -266,7 +256,6 @@ func (r *MemoryShareRepository) Delete(ctx context.Context, shareID int64, userI
return nil
}
-// GetFileOwnerMap returns a fileID->ownerID map for a share.
func (r *MemoryShareRepository) GetFileOwnerMap(ctx context.Context, shareID int64) (map[int64]int64, error) {
rows, err := r.DB.QueryContext(ctx, `
SELECT file_id, file_owner_id FROM memory_share_files WHERE memory_share_id = $1`, shareID)
@@ -286,7 +275,6 @@ func (r *MemoryShareRepository) GetFileOwnerMap(ctx context.Context, shareID int
return ownerMap, nil
}
-// GetFileByID fetches a specific file entry for a share.
func (r *MemoryShareRepository) GetFileByID(ctx context.Context, shareID int64, fileID int64) (*ente.MemoryShareFile, error) {
file := &ente.MemoryShareFile{}
err := r.DB.QueryRowContext(ctx, `
@@ -306,7 +294,6 @@ func (r *MemoryShareRepository) GetFileByID(ctx context.Context, shareID int64,
return file, nil
}
-// FileExistsInShare reports whether a file belongs to a share and returns the ownerID.
func (r *MemoryShareRepository) FileExistsInShare(ctx context.Context, shareID int64, fileID int64) (bool, int64, error) {
var ownerID int64
err := r.DB.QueryRowContext(ctx, `
@@ -321,7 +308,6 @@ func (r *MemoryShareRepository) FileExistsInShare(ctx context.Context, shareID i
return true, ownerID, nil
}
-// GetFilesWithKeys returns file entries and re-encrypted keys for the requested file IDs.
func (r *MemoryShareRepository) GetFilesWithKeys(ctx context.Context, shareID int64, fileIDs []int64) ([]ente.MemoryShareFile, error) {
rows, err := r.DB.QueryContext(ctx, `
SELECT id, memory_share_id, file_id, file_owner_id, position, file_enc_key, file_key_decryption_nonce, created_at
diff --git a/server/pkg/repo/notificationhistory.go b/server/pkg/repo/notificationhistory.go
index 107cf0a8fd..dbef941f20 100644
--- a/server/pkg/repo/notificationhistory.go
+++ b/server/pkg/repo/notificationhistory.go
@@ -53,8 +53,6 @@ func (repo *NotificationHistoryRepository) SetLastNotificationTimeToNowWithGroup
return stacktrace.Propagate(err, "")
}
-// GetLastNotificationTimes returns the latest sent_time per templateID for the
-// provided user.
func (repo *NotificationHistoryRepository) GetLastNotificationTimes(userID int64, templateIDs []string) (map[string]int64, error) {
result := make(map[string]int64)
if len(templateIDs) == 0 {
diff --git a/server/pkg/repo/object_cleanup.go b/server/pkg/repo/object_cleanup.go
index df37471356..e73329fb40 100644
--- a/server/pkg/repo/object_cleanup.go
+++ b/server/pkg/repo/object_cleanup.go
@@ -22,7 +22,6 @@ type ObjectCleanupRepository struct {
DB *sql.DB
}
-// AddTempObject persists a given object identifier and it's expirationTime
func (repo *ObjectCleanupRepository) AddTempObject(tempObject ente.TempObject, expirationTime int64) error {
var err error
if tempObject.IsMultipart {
@@ -35,13 +34,11 @@ func (repo *ObjectCleanupRepository) AddTempObject(tempObject ente.TempObject, e
return stacktrace.Propagate(err, "")
}
-// RemoveTempObjectKey removes a TempObject identified by its key and datacenter
func (repo *ObjectCleanupRepository) RemoveTempObjectKey(ctx context.Context, tx *sql.Tx, objectKey string, dc string) error {
_, err := tx.ExecContext(ctx, `DELETE FROM temp_objects WHERE object_key = $1`, objectKey)
return stacktrace.Propagate(err, "")
}
-// RemoveTempObjectFromDC will also return how many rows were affected
func (repo *ObjectCleanupRepository) RemoveTempObjectFromDC(ctx context.Context, tx *sql.Tx, objectKey string, dc string) error {
res, err := tx.ExecContext(ctx, `DELETE FROM temp_objects WHERE object_key = $1 and bucket_id = $2`, objectKey, dc)
if err != nil {
@@ -70,7 +67,6 @@ func (repo *ObjectCleanupRepository) DoesTempObjectExist(ctx context.Context, ob
return exists, nil
}
-// GetExpiredObjects returns the list of object keys that have expired
func (repo *ObjectCleanupRepository) GetAndLockExpiredObjects() (*sql.Tx, []ente.TempObject, error) {
tx, err := repo.DB.Begin()
if err != nil {
@@ -130,7 +126,6 @@ func (repo *ObjectCleanupRepository) GetAndLockExpiredObjects() (*sql.Tx, []ente
return tx, tempObjects, nil
}
-// SetExpiryForTempObject sets the expiration_time for TempObject
func (repo *ObjectCleanupRepository) SetExpiryForTempObject(tx *sql.Tx, tempObject ente.TempObject, expirationTime int64) error {
if tempObject.IsMultipart {
_, err := tx.Exec(`
@@ -145,7 +140,6 @@ func (repo *ObjectCleanupRepository) SetExpiryForTempObject(tx *sql.Tx, tempObje
}
}
-// RemoveTempObject removes a given TempObject
func (repo *ObjectCleanupRepository) RemoveTempObject(tx *sql.Tx, tempObject ente.TempObject) error {
if tempObject.IsMultipart {
_, err := tx.Exec(`
diff --git a/server/pkg/repo/passkey/passkey.go b/server/pkg/repo/passkey/passkey.go
index c976f079fe..3d743527f7 100644
--- a/server/pkg/repo/passkey/passkey.go
+++ b/server/pkg/repo/passkey/passkey.go
@@ -23,9 +23,7 @@ import (
)
const (
- // MaxSessionTokenFetchLimit specifies the maximum number of requests a client can make to retrieve token data for a given session ID.
- MaxSessionTokenFetchLimit = 2
- // TokenFetchAllowedDurationInMin is the duration in minutes for which the token fetch is allowed after the session is verified.
+ MaxSessionTokenFetchLimit = 2
TokenFetchAllowedDurationInMin = 2
)
@@ -259,7 +257,6 @@ func (r *Repository) CreateBeginRegistrationData(user *ente.User) (options *prot
return
}
- // save session data
marshalledSessionData, err := r.marshalSessionDataToWebAuthnSession(session, rpID)
if err != nil {
err = stacktrace.Propagate(err, "")
@@ -288,7 +285,6 @@ func (r *Repository) GetUserIDWithPasskeyTwoFactorSession(sessionID string) (use
return
}
-// IsSessionAlreadyClaimed checks if the both token_data and verified_at are not null for a given session ID
func (r *Repository) IsSessionAlreadyClaimed(sessionID string) (bool, error) {
var verifiedAt sql.NullInt64
err := r.DB.QueryRow(`SELECT verified_at FROM passkey_login_sessions WHERE session_id = $1`, sessionID).Scan(&verifiedAt)
@@ -301,7 +297,6 @@ func (r *Repository) IsSessionAlreadyClaimed(sessionID string) (bool, error) {
return verifiedAt.Valid, nil
}
-// StoreTokenData takes a sessionID, and tokenData, and updates the tokenData in the database
func (r *Repository) StoreTokenData(sessionID string, tokenData ente.TwoFactorAuthorizationResponse) error {
tokenDataJson, err := json.Marshal(tokenData)
if err != nil {
@@ -311,19 +306,6 @@ func (r *Repository) StoreTokenData(sessionID string, tokenData ente.TwoFactorAu
return stacktrace.Propagate(err, "")
}
-// GetTokenData retrieves the token data associated with a given session ID.
-// The function will return the token data if the following conditions are met:
-// - The token data is not null.
-// - The session was verified less than 5 minutes ago.
-// - The token fetch count is less than 2.
-// If these conditions are met, the function will also increment the token fetch count by 1.
-//
-// Parameters:
-// - sessionID: The ID of the session for which to retrieve the token data.
-//
-// Returns:
-// - A pointer to a TwoFactorAuthorizationResponse object containing the token data, if the conditions are met.
-// - An error, if an error occurred while retrieving the token data or if the conditions are not met.
func (r *Repository) GetTokenData(sessionID string) (*ente.TwoFactorAuthorizationResponse, error) {
var tokenDataJson []byte
var verifiedAt sql.NullInt64
@@ -361,7 +343,6 @@ func (r *Repository) GetTokenData(sessionID string) (*ente.TwoFactorAuthorizatio
if err != nil {
return nil, stacktrace.Propagate(err, "")
}
- // update the token_fetch_count
_, err = r.DB.Exec(`UPDATE passkey_login_sessions SET token_fetch_cnt = token_fetch_cnt + 1 WHERE session_id = $1`, sessionID)
if err != nil {
return nil, stacktrace.Propagate(err, "")
@@ -402,7 +383,6 @@ func (r *Repository) CreateBeginAuthenticationData(user *ente.User) (options *pr
return
}
- // save session data
marshalledSessionData, err := r.marshalSessionDataToWebAuthnSession(session, rpID)
if err != nil {
err = stacktrace.Propagate(err, "")
@@ -598,23 +578,19 @@ func (r *Repository) saveSessionData(id uuid.UUID, session *ente.WebAuthnSession
}
func (r *Repository) marshalCredentialToPasskeyCredential(cred *webauthn.Credential, passkeyID uuid.UUID, rpID string) (*ente.PasskeyCredential, error) {
- // Convert the PublicKey to base64
publicKeyB64 := base64.StdEncoding.EncodeToString(cred.PublicKey)
- // Convert the Transports slice to a comma-separated string
var transports []string
for _, t := range cred.Transport {
transports = append(transports, string(t))
}
authenticatorTransports := strings.Join(transports, ",")
- // Marshal the Flags to JSON
credentialFlags, err := json.Marshal(cred.Flags)
if err != nil {
return nil, err
}
- // Marshal the Authenticator to JSON and encode AAGUID to base64
authenticatorMap := map[string]interface{}{
"AAGUID": base64.StdEncoding.EncodeToString(cred.Authenticator.AAGUID),
"SignCount": cred.Authenticator.SignCount,
@@ -626,10 +602,8 @@ func (r *Repository) marshalCredentialToPasskeyCredential(cred *webauthn.Credent
return nil, err
}
- // convert cred.ID into base64
credID := base64.StdEncoding.EncodeToString(cred.ID)
- // Create the PasskeyCredential
passkeyCred := &ente.PasskeyCredential{
CredentialID: credID,
PasskeyID: passkeyID,
diff --git a/server/pkg/repo/public/collection_link.go b/server/pkg/repo/public/collection_link.go
index da1ef8dd6a..70283c0b6e 100644
--- a/server/pkg/repo/public/collection_link.go
+++ b/server/pkg/repo/public/collection_link.go
@@ -13,15 +13,12 @@ import (
"github.com/lib/pq"
)
-// CollectionLinkRepo defines the methods for inserting, updating and
-// retrieving entities related to public collections
type CollectionLinkRepo struct {
DB *sql.DB
albumHost string
lockerHost string
}
-// NewCollectionLinkRepository ..
func NewCollectionLinkRepository(db *sql.DB, albumHost string) *CollectionLinkRepo {
if albumHost == "" {
albumHost = "https://albums.ente.com"
@@ -132,7 +129,6 @@ func (pcr *CollectionLinkRepo) GetActiveCollectionLinkRow(ctx context.Context, c
public_collection_tokens WHERE collection_id = $1 and is_disabled = FALSE`,
collectionID)
- //defer rows.Close()
ret := ente.CollectionLinkRow{}
var minRole sql.NullString
err := row.Scan(&ret.ID, &ret.CollectionID, &ret.Token, &ret.ValidTill, &ret.DeviceLimit,
@@ -148,7 +144,6 @@ func (pcr *CollectionLinkRepo) GetActiveCollectionLinkRow(ctx context.Context, c
return ret, nil
}
-// UpdatePublicCollectionToken will update the row for corresponding public collection token
func (pcr *CollectionLinkRepo) UpdatePublicCollectionToken(ctx context.Context, pct ente.CollectionLinkRow) error {
var minRole interface{}
if pct.MinRole != nil {
@@ -228,7 +223,6 @@ func (pcr *CollectionLinkRepo) GetActivePublicTokenForUser(ctx context.Context,
return result, nil
}
-// CleanupAccessHistory public_collection_access_history where public_collection_tokens is disabled and the last updated time is older than 30 days
func (pcr *CollectionLinkRepo) CleanupAccessHistory(ctx context.Context) error {
_, err := pcr.DB.ExecContext(ctx, `DELETE FROM public_collection_access_history WHERE share_id IN (SELECT id FROM public_collection_tokens WHERE is_disabled = TRUE AND updated_at < (now_utc_micro_seconds() - (24::BIGINT * 30 * 60 * 60 * 1000 * 1000)))`)
if err != nil {
diff --git a/server/pkg/repo/public/file_link.go b/server/pkg/repo/public/file_link.go
index abba1aa907..1945a871b6 100644
--- a/server/pkg/repo/public/file_link.go
+++ b/server/pkg/repo/public/file_link.go
@@ -13,15 +13,12 @@ import (
"github.com/ente/stacktrace"
)
-// FileLinkRepository defines the methods for inserting, updating and
-// retrieving entities related to public file
type FileLinkRepository struct {
DB *sql.DB
photoHost string
lockerHost string
}
-// NewFileLinkRepo ..
func NewFileLinkRepo(db *sql.DB) *FileLinkRepository {
albumHost := viper.GetString("apps.public-albums")
if albumHost == "" {
@@ -95,7 +92,6 @@ func (pcr *FileLinkRepository) Insert(
return id, nil
}
-// UpdateLinkSecretIfEmpty updates link key metadata if it hasn't been set already.
func (pcr *FileLinkRepository) UpdateLinkSecretIfEmpty(
ctx context.Context,
linkID string,
@@ -189,7 +185,6 @@ func (pcr *FileLinkRepository) DisableLinkForFiles(ctx context.Context, fileIDs
return nil
}
-// DisableLinksForUser will disable all public file links for the given user
func (pcr *FileLinkRepository) DisableLinksForUser(ctx context.Context, userID int64) error {
_, err := pcr.DB.ExecContext(ctx, `UPDATE public_file_tokens SET is_disabled = TRUE WHERE owner_id = $1`, userID)
if err != nil {
@@ -263,7 +258,6 @@ func (pcr *FileLinkRepository) GetFileUrlRowByFileID(ctx context.Context, fileID
return &result, nil
}
-// UpdateLink will update the row for corresponding public file token
func (pcr *FileLinkRepository) UpdateLink(ctx context.Context, pct ente.FileLinkRow) error {
_, err := pcr.DB.ExecContext(ctx, `UPDATE public_file_tokens SET valid_till = $1, device_limit = $2,
pw_hash = $3, pw_nonce = $4, mem_limit = $5, ops_limit = $6, enable_download = $7
@@ -302,7 +296,6 @@ func (pcr *FileLinkRepository) AccessedInPast(ctx context.Context, shareID strin
return true, stacktrace.Propagate(err, "failed to record access history")
}
-// CleanupAccessHistory public_file_tokens_access_history where public_collection_tokens is disabled and the last updated time is older than 30 days
func (pcr *FileLinkRepository) CleanupAccessHistory(ctx context.Context) error {
_, err := pcr.DB.ExecContext(ctx, `DELETE FROM public_file_tokens_access_history WHERE id IN (SELECT id FROM public_file_tokens WHERE is_disabled = TRUE AND updated_at < (now_utc_micro_seconds() - (24::BIGINT * 30 * 60 * 60 * 1000 * 1000)))`)
if err != nil {
diff --git a/server/pkg/repo/queue.go b/server/pkg/repo/queue.go
index 978f4bdcf1..936ea0be5a 100644
--- a/server/pkg/repo/queue.go
+++ b/server/pkg/repo/queue.go
@@ -12,7 +12,6 @@ import (
"github.com/ente/stacktrace"
)
-// QueueRepository defines methods to insert, delete items from queue
type QueueRepository struct {
DB *sql.DB
}
@@ -51,7 +50,6 @@ type QueueItem struct {
Item string
}
-// InsertItem adds entry in the queue with given queueName and item. If entry already exists, it's no-op
func (repo *QueueRepository) InsertItem(ctx context.Context, queueName string, item string) error {
_, err := repo.DB.ExecContext(ctx, `INSERT INTO queue(queue_name, item) VALUES($1, $2)
ON CONFLICT (queue_name, item) DO NOTHING`, queueName, item)
@@ -92,7 +90,6 @@ func (repo *QueueRepository) RequeueItem(ctx context.Context, queueName string,
return nil
}
-// AddItems adds a list of item against a specified queue
func (repo *QueueRepository) AddItems(ctx context.Context, tx *sql.Tx, queueName string, items []string) error {
if len(items) == 0 {
return nil
@@ -126,7 +123,6 @@ func (repo *QueueRepository) DeleteItem(queueName string, item string) error {
return stacktrace.Propagate(err, "")
}
-// GetItemsReadyForDeletion method, for a given queue name, returns a list of QueueItem which are ready for deletion
func (repo *QueueRepository) GetItemsReadyForDeletion(queueName string, count int) ([]QueueItem, error) {
delayInMin, ok := itemDeletionDelayInMinMap[queueName]
if !ok {
diff --git a/server/pkg/repo/remotestore/repository.go b/server/pkg/repo/remotestore/repository.go
index d9e83578e5..8098e904e2 100644
--- a/server/pkg/repo/remotestore/repository.go
+++ b/server/pkg/repo/remotestore/repository.go
@@ -11,8 +11,6 @@ import (
"github.com/ente/stacktrace"
)
-// Repository defines the methods for inserting, updating and retrieving
-// remote store key and values
type Repository struct {
DB *sql.DB
}
@@ -21,9 +19,9 @@ func (r *Repository) InsertOrUpdate(ctx context.Context, userID int64, key strin
_, err := r.DB.ExecContext(ctx, `INSERT INTO remote_store(user_id, key_name, key_value) VALUES ($1,$2,$3)
ON CONFLICT (user_id, key_name) DO UPDATE SET key_value = $3;
`,
- userID, //$1 user_id
- key, // $2 key_name
- value, // $3 key_value
+ userID,
+ key,
+ value,
)
if err != nil {
@@ -42,18 +40,17 @@ func (r *Repository) InsertOrUpdate(ctx context.Context, userID int64, key strin
func (r *Repository) RemoveKey(ctx context.Context, userID int64, key string) error {
_, err := r.DB.ExecContext(ctx, `DELETE FROM remote_store
WHERE user_id = $1 AND key_name = $2`,
- userID, // $1
- key, // $2
+ userID,
+ key,
)
return stacktrace.Propagate(err, "failed to remove key")
}
func (r *Repository) DomainOwner(ctx context.Context, domain string) (*int64, error) {
- // Check if the domain is already taken by another user
rows := r.DB.QueryRowContext(ctx, `SELECT user_id FROM remote_store
WHERE key_name = $1 AND key_value = $2`,
- ente.CustomDomain, // $1
- domain, // $2
+ ente.CustomDomain,
+ domain,
)
var userID int64
err := rows.Scan(&userID)
@@ -67,11 +64,10 @@ func (r *Repository) DomainOwner(ctx context.Context, domain string) (*int64, er
}
func (r *Repository) GetDomain(ctx context.Context, userID int64) (*string, error) {
- // Fetch the custom domain for the user
rows := r.DB.QueryRowContext(ctx, `SELECT key_value FROM remote_store
WHERE user_id = $1 AND key_name = $2`,
- userID, // $1
- ente.CustomDomain, // $2
+ userID,
+ ente.CustomDomain,
)
var domain string
err := rows.Scan(&domain)
@@ -98,13 +94,12 @@ func (r *Repository) GetEffectiveDomain(ctx context.Context, userID int64) (*str
return &resolved, nil
}
-// GetValue fetches and return the value for given user_id and key
func (r *Repository) GetValue(ctx context.Context, userID int64, key string) (string, error) {
rows := r.DB.QueryRowContext(ctx, `SELECT key_value FROM remote_store
WHERE user_id = $1
and key_name = $2`,
- userID, // $1
- key, // %2
+ userID,
+ key,
)
var keyValue string
err := rows.Scan(&keyValue)
@@ -114,11 +109,10 @@ func (r *Repository) GetValue(ctx context.Context, userID int64, key string) (st
return keyValue, nil
}
-// GetAllValues fetches and return all the key value pairs for given user_id
func (r *Repository) GetAllValues(ctx context.Context, userID int64) (map[string]string, error) {
rows, err := r.DB.QueryContext(ctx, `SELECT key_name, key_value FROM remote_store
WHERE user_id = $1`,
- userID, // $1
+ userID,
)
if err != nil {
return nil, stacktrace.Propagate(err, "reading value failed")
diff --git a/server/pkg/repo/social/anon_users.go b/server/pkg/repo/social/anon_users.go
index 00bdc96566..3f5451946d 100644
--- a/server/pkg/repo/social/anon_users.go
+++ b/server/pkg/repo/social/anon_users.go
@@ -9,7 +9,6 @@ import (
"github.com/lib/pq"
)
-// AnonUsersRepository manages anonymous user profiles tied to public collections.
type AnonUsersRepository struct {
DB *sql.DB
}
@@ -80,7 +79,6 @@ func (r *AnonUsersRepository) ListByCollection(ctx context.Context, collectionID
return result, nil
}
-// LatestUpdateByCollection returns the most recent updated_at timestamp per collection.
func (r *AnonUsersRepository) LatestUpdateByCollection(ctx context.Context, collectionIDs []int64) (map[int64]int64, error) {
results := make(map[int64]int64)
if len(collectionIDs) == 0 {
diff --git a/server/pkg/repo/social/comments.go b/server/pkg/repo/social/comments.go
index 4f9c4fd3e2..34e6007cda 100644
--- a/server/pkg/repo/social/comments.go
+++ b/server/pkg/repo/social/comments.go
@@ -10,7 +10,6 @@ import (
"github.com/lib/pq"
)
-// CommentsRepository manages comment records.
type CommentsRepository struct {
DB *sql.DB
}
@@ -78,7 +77,6 @@ func (repo *CommentsRepository) SoftDelete(ctx context.Context, id string) error
return nil
}
-// SoftDeleteByCollectionAndUser removes all comments created by a user inside a collection.
func (repo *CommentsRepository) SoftDeleteByCollectionAndUser(ctx context.Context, collectionID int64, userID int64) error {
_, err := repo.DB.ExecContext(ctx, `
UPDATE comments
@@ -240,7 +238,6 @@ func (repo *CommentsRepository) CountActiveByCollection(ctx context.Context, col
return counts, nil
}
-// LatestUpdateByCollection returns the most recent updated_at timestamp for each collection.
func (repo *CommentsRepository) LatestUpdateByCollection(ctx context.Context, collectionIDs []int64) (map[int64]int64, error) {
results := make(map[int64]int64)
if len(collectionIDs) == 0 {
diff --git a/server/pkg/repo/social/reactions.go b/server/pkg/repo/social/reactions.go
index 013fcf2a0c..93666ab4d0 100644
--- a/server/pkg/repo/social/reactions.go
+++ b/server/pkg/repo/social/reactions.go
@@ -11,7 +11,6 @@ import (
"github.com/lib/pq"
)
-// ReactionsRepository manages reaction records.
type ReactionsRepository struct {
DB *sql.DB
}
@@ -70,7 +69,6 @@ func (repo *ReactionsRepository) SoftDeleteByID(ctx context.Context, id string,
return nil
}
-// SoftDeleteByCollectionAndUser removes all reactions created by a user inside a collection.
func (repo *ReactionsRepository) SoftDeleteByCollectionAndUser(ctx context.Context, collectionID int64, userID int64) error {
_, err := repo.DB.ExecContext(ctx, `
UPDATE reactions
@@ -238,7 +236,6 @@ func (repo *ReactionsRepository) CountActiveByCollection(ctx context.Context, co
return counts, nil
}
-// LatestUpdateByCollection returns the most recent updated_at timestamp for each collection.
func (repo *ReactionsRepository) LatestUpdateByCollection(ctx context.Context, collectionIDs []int64) (map[int64]int64, error) {
results := make(map[int64]int64)
if len(collectionIDs) == 0 {
diff --git a/server/pkg/repo/srp.go b/server/pkg/repo/srp.go
index 454d739b31..bf1dce089d 100644
--- a/server/pkg/repo/srp.go
+++ b/server/pkg/repo/srp.go
@@ -11,7 +11,6 @@ import (
log "github.com/sirupsen/logrus"
)
-// AddSRPSession inserts a SRPSession and returns the session id
func (repo *UserAuthRepository) AddSRPSession(srpUserID uuid.UUID, serverKey string, srpA string) (uuid.UUID, error) {
id := uuid.New()
_, err := repo.DB.Exec(`
@@ -56,7 +55,6 @@ func (repo *UserAuthRepository) GetSRPAuthEntityBySRPUserID(ctx context.Context,
}
-// IsSRPSetupDone returns true if the user has already set SRP attributes
func (repo *UserAuthRepository) IsSRPSetupDone(ctx context.Context, userID int64) (bool, error) {
_, err := repo.GetSRPAuthEntity(ctx, userID)
if err != nil {
@@ -68,7 +66,6 @@ func (repo *UserAuthRepository) IsSRPSetupDone(ctx context.Context, userID int64
return true, nil
}
-// UpdateEmailMFA updates the email MFA status of a user
func (repo *UserAuthRepository) UpdateEmailMFA(ctx context.Context, userID int64, isEnabled bool) error {
_, err := repo.DB.ExecContext(ctx, `UPDATE users SET email_mfa = $1 WHERE user_id = $2`, isEnabled, userID)
if err != nil {
@@ -87,7 +84,6 @@ func (repo *UserAuthRepository) IsEmailMFAEnabled(ctx context.Context, userID in
return &isEnabled, nil
}
-// InsertTempSRPSetup inserts an entry into the temp_srp_setup table. It also returns the ID of the inserted row
func (repo *UserAuthRepository) InsertTempSRPSetup(ctx context.Context, req ente.SetupSRPRequest, userID int64, sessionID *uuid.UUID) (*uuid.UUID, error) {
id := uuid.New()
_, err := repo.DB.ExecContext(ctx, `
@@ -160,7 +156,6 @@ func (repo *UserAuthRepository) InsertOrUpdateSRPAuthAndKeyAttr(ctx context.Cont
return tx.Commit()
}
-// GetSrpSessionEntity ...
func (repo *UserAuthRepository) GetSrpSessionEntity(ctx context.Context, sessionID uuid.UUID) (*ente.SRPSessionEntity, error) {
result := ente.SRPSessionEntity{}
row := repo.DB.QueryRowContext(ctx, `SELECT id, srp_user_id, server_key, srp_a, has_verified, attempt_count, COALESCE(is_fake, false) FROM srp_sessions WHERE id = $1`, sessionID)
@@ -171,21 +166,17 @@ func (repo *UserAuthRepository) GetSrpSessionEntity(ctx context.Context, session
return &result, nil
}
-// IncrementSrpSessionAttemptCount increments the verification attempt count of a session
func (repo *UserAuthRepository) IncrementSrpSessionAttemptCount(ctx context.Context, sessionID uuid.UUID) error {
_, err := repo.DB.ExecContext(ctx, `UPDATE srp_sessions SET attempt_count = attempt_count + 1 WHERE id = $1`, sessionID)
return stacktrace.Propagate(err, "")
}
-// SetSrpSessionVerified ..
func (repo *UserAuthRepository) SetSrpSessionVerified(ctx context.Context, sessionID uuid.UUID) error {
_, err := repo.DB.ExecContext(ctx, `UPDATE srp_sessions SET has_verified = true WHERE id = $1`, sessionID)
return stacktrace.Propagate(err, "")
}
-// CleanupOldFakeSessions removes fake sessions older than the specified duration
func (repo *UserAuthRepository) CleanupOldFakeSessions(ctx context.Context) (int64, error) {
- // Delete fake sessions older than specified microseconds
result, err := repo.DB.ExecContext(ctx, `
DELETE FROM srp_sessions
WHERE is_fake = true
@@ -200,7 +191,6 @@ func (repo *UserAuthRepository) CleanupOldFakeSessions(ctx context.Context) (int
return rowsAffected, nil
}
-// GetSRPAttributes returns the srp attributes of a user
func (repo *UserAuthRepository) GetSRPAttributes(userID int64) (*ente.GetSRPAttributesResponse, error) {
row := repo.DB.QueryRow(`SELECT srp_user_id, salt, mem_limit, ops_limit, kek_salt, email_mfa FROM srp_auth left join key_attributes on srp_auth.user_id = key_attributes.user_id
left join users on users.user_id = srp_auth.user_id WHERE srp_auth.user_id = $1`, userID)
diff --git a/server/pkg/repo/storagebonus/bf_addon.go b/server/pkg/repo/storagebonus/bf_addon.go
index 50fe5965ac..b4de2bb08b 100644
--- a/server/pkg/repo/storagebonus/bf_addon.go
+++ b/server/pkg/repo/storagebonus/bf_addon.go
@@ -31,7 +31,7 @@ func (r *Repository) RemoveAddOnBonus(ctx context.Context, bonusType storagebonu
if err != nil {
return 0, fmt.Errorf("failed to begin transaction: %w", err)
}
- defer tx.Rollback() // Will be no-op if transaction is committed
+ defer tx.Rollback()
res, err := tx.ExecContext(ctx, "DELETE FROM storage_bonus WHERE bonus_id = $1", bonusID)
if err != nil {
return 0, fmt.Errorf("failed to execute delete query: %w", err)
@@ -51,7 +51,7 @@ func (r *Repository) RemoveAddOnBonus(ctx context.Context, bonusType storagebonu
return 0, fmt.Errorf("failed to commit transaction: %w", err)
}
- return 1, nil // We know exactly one row was affected at this point
+ return 1, nil
}
func (r *Repository) UpdateAddOnBonus(ctx context.Context, bonusType storagebonus.BonusType, userID int64, validTill int64, storage int64) error {
diff --git a/server/pkg/repo/storagebonus/bonus.go b/server/pkg/repo/storagebonus/bonus.go
index 64f1608b30..540c4cd15b 100644
--- a/server/pkg/repo/storagebonus/bonus.go
+++ b/server/pkg/repo/storagebonus/bonus.go
@@ -8,7 +8,6 @@ import (
"github.com/ente/stacktrace"
)
-// GetStorageBonuses returns the storage surplus for the given userID
func (r *Repository) GetStorageBonuses(ctx context.Context, userID int64) ([]storagebonus.StorageBonus, error) {
var storageSurplus = make([]storagebonus.StorageBonus, 0)
rows, err := r.DB.QueryContext(ctx, "SELECT user_id,storage,type, created_at, updated_at, valid_till, is_revoked, revoke_reason FROM storage_bonus WHERE user_id = $1", userID)
@@ -45,8 +44,6 @@ func (r *Repository) GetActiveStorageBonuses(ctx context.Context, userID int64)
return &storagebonus.ActiveStorageBonus{StorageBonuses: bonuses}, nil
}
-// ActiveStorageSurplusOfType returns the total storage surplus for a given userID. Surplus is considered as active when
-// it is not revoked and not expired aka validTill is 0 or greater than now_utc_micro_seconds()
func (r *Repository) ActiveStorageSurplusOfType(ctx context.Context, userID int64, bonusTypes []storagebonus.BonusType) (*int64, error) {
var total *int64
rows, err := r.DB.QueryContext(ctx, "SELECT coalesce(sum(storage),0) FROM storage_bonus "+
@@ -64,13 +61,10 @@ func (r *Repository) ActiveStorageSurplusOfType(ctx context.Context, userID int6
return total, nil
}
-// GetPaidAddonSurplusStorage returns the total storage surplus for a given userID. Surplus is considered as active when
-// it is not revoked and not expired aka validTill is 0 or greater than now_utc_micro_seconds()
func (r *Repository) GetPaidAddonSurplusStorage(ctx context.Context, userID int64) (*int64, error) {
return r.ActiveStorageSurplusOfType(ctx, userID, storagebonus.PaidAddOnTypes)
}
-// GetAllUsersSurplusBonus returns two maps userID to referralBonus & addonBonus
func (r *Repository) GetAllUsersSurplusBonus(ctx context.Context) (refBonus map[int64]int64, addonBonus map[int64]int64, err error) {
var userID, bonus int64
var bonusType storagebonus.BonusType
diff --git a/server/pkg/repo/storagebonus/bonus_test.go b/server/pkg/repo/storagebonus/bonus_test.go
deleted file mode 100644
index 87978dd8ee..0000000000
--- a/server/pkg/repo/storagebonus/bonus_test.go
+++ /dev/null
@@ -1,25 +0,0 @@
-package storagebonus
-
-import (
- "testing"
-)
-
-// Write test for adding entry in storage_surplus table
-func TestAddStorageSurplus(t *testing.T) {
- //repo := NewRepository(db) // Test
- //err := repo.AddStorageBonus(context.Background(), 10, 1024, storagebonus.SignUp)
- //assert.NoError(t, err)
- //storageSurplus, err := repo.GetStorageBonuses(context.Background(), 10)
- //assert.NoError(t, err)
- //
- //assert.Equal(t, 1, len(storageSurplus), "length mismatch")
- //assert.Truef(t, cmp.Equal(storageSurplus[0], storagebonus.StorageBonus{
- // UserID: 10,
- // Storage: 1024,
- // Type: storagebonus.SignUp,
- // ValidTill: 0,
- // RevokeReason: nil,
- // IsRevoked: false,
- //}, cmpopts.IgnoreFields(storagebonus.StorageBonus{}, "CreatedAt", "UpdatedAt")), "match failed")
-
-}
diff --git a/server/pkg/repo/storagebonus/referral_codes.go b/server/pkg/repo/storagebonus/referral_codes.go
index 7e55558e3a..0874ba373f 100644
--- a/server/pkg/repo/storagebonus/referral_codes.go
+++ b/server/pkg/repo/storagebonus/referral_codes.go
@@ -15,16 +15,12 @@ const (
MaxReferralCodeChangeAllowed = 3
)
-// Add context as first parameter in all methods in this file
-
-// GetCode returns the storagebonus code for the given userID
func (r *Repository) GetCode(ctx context.Context, userID int64) (*string, error) {
var code *string
err := r.DB.QueryRowContext(ctx, "SELECT code FROM referral_codes WHERE user_id = $1 and is_active = TRUE", userID).Scan(&code)
return code, stacktrace.Propagate(err, "failed to get storagebonus code for user %d", userID)
}
-// InsertCode for the given userID
func (r *Repository) InsertCode(ctx context.Context, userID int64, code string) error {
_, err := r.DB.ExecContext(ctx, "INSERT INTO referral_codes (user_id, code) VALUES ($1, $2)", userID, code)
if err != nil {
@@ -36,11 +32,7 @@ func (r *Repository) InsertCode(ctx context.Context, userID int64, code string)
return nil
}
-// AddNewCode and mark the old one as inactive for a given userID.
-// Note: This method is not being used in the initial MVP as we don't allow user to change the storagebonus
-// code
func (r *Repository) AddNewCode(ctx context.Context, userID int64, code string, isAdminEdit bool) error {
- // check current referral code count
var count int
err := r.DB.QueryRowContext(ctx, "SELECT COALESCE(COUNT(*),0) FROM referral_codes WHERE user_id = $1", userID).Scan(&count)
if err != nil {
@@ -53,7 +45,6 @@ func (r *Repository) AddNewCode(ctx context.Context, userID int64, code string,
HttpStatusCode: http.StatusTooManyRequests,
}, "max referral code change limit reached for user %d", userID)
}
- // check if code already exists
var existCount int
err = r.DB.QueryRowContext(ctx, "SELECT COALESCE(COUNT(*),0) FROM referral_codes WHERE code = $1", code).Scan(&existCount)
if err != nil {
diff --git a/server/pkg/repo/storagebonus/referral_codes_test.go b/server/pkg/repo/storagebonus/referral_codes_test.go
index 8a51fad4ed..c4bfe0b669 100644
--- a/server/pkg/repo/storagebonus/referral_codes_test.go
+++ b/server/pkg/repo/storagebonus/referral_codes_test.go
@@ -1,7 +1,5 @@
package storagebonus
-// Unittest cases for storagebonus code repository
-
import (
"database/sql"
"errors"
@@ -27,40 +25,32 @@ func newStorageBonusTestRepository(t *testing.T) *Repository {
return NewRepository(db)
}
-// TestGetReferralCode tests the GetCode method
func TestGetReferralCode(t *testing.T) {
ctx := t.Context()
repo := newStorageBonusTestRepository(t)
- // Test for a user that doesn't have a storagebonus code
userID := int64(1)
code, err := repo.GetCode(ctx, userID)
assert.Nil(t, code)
assert.ErrorIs(t, err, sql.ErrNoRows)
- // Insert a storagebonus code
newCode := "AABBCC"
err = repo.InsertCode(ctx, userID, newCode)
assert.Nil(t, err)
- // Test for when storagebonus code already exists
err = repo.InsertCode(ctx, userID, newCode)
assert.Error(t, err)
err = errors.Unwrap(err)
- // verify that error is of type pq.Error
assert.Equal(t, entity.CodeAlreadyExistsErr, err)
- // Test for a user that has a storagebonus code
code, err = repo.GetCode(ctx, userID)
assert.Nil(t, err)
assert.NotNil(t, code)
assert.Equal(t, newCode, *code)
}
-// TestInsertReferralCode tests the InsertCode method
func TestInsertReferralCode(t *testing.T) {
ctx := t.Context()
repo := newStorageBonusTestRepository(t)
- // Insert a referral code
userID := int64(2)
code := "AAEEDD"
err := repo.InsertCode(ctx, userID, code)
@@ -71,7 +61,6 @@ func TestInsertReferralCode(t *testing.T) {
assert.Equal(t, code, *codeNew)
}
-// TestAddNewReferralCode tests the AddNewCode method
func TestAddNewReferralCode(t *testing.T) {
ctx := t.Context()
repo := newStorageBonusTestRepository(t)
diff --git a/server/pkg/repo/storagebonus/referral_tracking.go b/server/pkg/repo/storagebonus/referral_tracking.go
index 1f2eed254c..4997a767ac 100644
--- a/server/pkg/repo/storagebonus/referral_tracking.go
+++ b/server/pkg/repo/storagebonus/referral_tracking.go
@@ -21,8 +21,6 @@ func (r *Repository) TrackReferralAndInviteeBonus(ctx context.Context, invitee,
if err != nil {
return stacktrace.Propagate(err, "failed to begin txn for invitee bonus tracking")
}
- // Note: Rollback is deferred here because we want to roll back the txn if any of the following queries fail.
- // If we defer the rollback after the commit, it will be a no-op.
defer func(tx *sql.Tx) {
err := tx.Rollback()
if err != nil && err.Error() != "sql: transaction has already been committed or rolled back" {
@@ -36,7 +34,6 @@ func (r *Repository) TrackReferralAndInviteeBonus(ctx context.Context, invitee,
bonusType := storagebonus.SignUp
bonusID := fmt.Sprintf("%s-%d", bonusType, invitee)
bonusValue := planType.SignUpInviteeBonus()
- // Add storage surplus for the invitee who used the referral code
_, err = tx.ExecContext(ctx, "INSERT INTO storage_bonus (bonus_id,type, user_id, storage) VALUES ($1, $2, $3, $4)", bonusID, bonusType, invitee, bonusValue)
if err != nil {
return stacktrace.Propagate(err, "failed to add storage surplus for user %d", invitee)
@@ -77,7 +74,6 @@ func (r *Repository) TrackUpgradeAndInvitorBonus(ctx context.Context, invitee, i
if affected == 0 {
return stacktrace.Propagate(err, "failed to update tracking entry for invitee %d, invitor %d", invitee, invitor)
}
- // Add storage surplus for the invitor who referred the invitee
bonusType := storagebonus.Referral
bonusID := fmt.Sprintf("%s-upgrade-%d", bonusType, invitee)
bonusValue := planType.InvitorBonusOnInviteeUpgrade()
@@ -94,7 +90,6 @@ func (r *Repository) TrackUpgradeAndInvitorBonus(ctx context.Context, invitee, i
return nil
}
-// GetUserReferralStats for the given userID for each planType
func (r *Repository) GetUserReferralStats(ctx context.Context, userID int64) ([]storagebonus.UserReferralPlanStat, error) {
rows, err := r.DB.QueryContext(ctx, "SELECT plan_type, COUNT(*), SUM(CASE WHEN invitee_on_paid_plan THEN 1 ELSE 0 END) FROM referral_tracking WHERE invitor_id = $1 GROUP BY plan_type", userID)
if err != nil {
@@ -113,7 +108,6 @@ func (r *Repository) GetUserReferralStats(ctx context.Context, userID int64) ([]
return counts, nil
}
-// HasAppliedReferral checks if the given user has applied the storagebonus code in the past
func (r *Repository) HasAppliedReferral(ctx context.Context, invitee int64) (bool, error) {
var count int
err := r.DB.QueryRowContext(ctx, "SELECT COUNT(*) FROM referral_tracking WHERE invitee_id = $1", invitee).Scan(&count)
@@ -123,7 +117,6 @@ func (r *Repository) HasAppliedReferral(ctx context.Context, invitee int64) (boo
return count > 0, nil
}
-// GetReferredForUpgradeBonus where is_invitee_on_paid_plan is false and the invitee's is not free plan.
func (r *Repository) GetReferredForUpgradeBonus(ctx context.Context) ([]storagebonus.Tracking, error) {
rows, err := r.DB.QueryContext(ctx, "SELECT invitee_id, invitor_id, plan_type FROM referral_tracking WHERE invitee_on_paid_plan = FALSE AND invitee_id IN (SELECT user_id FROM subscriptions WHERE product_id != $1 and expiry_time > now_utc_micro_seconds())", ente.FreePlanProductID)
if err != nil {
@@ -147,7 +140,6 @@ func (r *Repository) GetReferredForUpgradeBonus(ctx context.Context) ([]storageb
return result, nil
}
-// GetReferredForDowngradePenalty where is_invitee_on_paid_plan is true and the invitee's is free plan.
func (r *Repository) GetReferredForDowngradePenalty(ctx context.Context) ([]storagebonus.Tracking, error) {
rows, err := r.DB.QueryContext(ctx, "SELECT invitee_id, invitor_id, plan_type FROM referral_tracking WHERE invitee_on_paid_plan = TRUE AND invitee_id IN (SELECT user_id FROM subscriptions WHERE expiry_time < now_utc_micro_seconds())")
if err != nil {
diff --git a/server/pkg/repo/tasklock.go b/server/pkg/repo/tasklock.go
index 6616f15799..521b86aad5 100644
--- a/server/pkg/repo/tasklock.go
+++ b/server/pkg/repo/tasklock.go
@@ -8,7 +8,6 @@ import (
"github.com/sirupsen/logrus"
)
-// TaskLockRepository defines the methods for acquire and release locks
type TaskLockRepository struct {
DB *sql.DB
}
diff --git a/server/pkg/repo/two_factor_recovery/repository.go b/server/pkg/repo/two_factor_recovery/repository.go
index a302256e98..cbb5167b02 100644
--- a/server/pkg/repo/two_factor_recovery/repository.go
+++ b/server/pkg/repo/two_factor_recovery/repository.go
@@ -16,7 +16,6 @@ type Repository struct {
SecretEncryptionKey []byte
}
-// GetStatus returns `ente.TwoFactorRecoveryStatus` for a user
func (r *Repository) GetStatus(userID int64) (*ente.TwoFactorRecoveryStatus, error) {
var isAdminResetEnabled bool
var resetKey []byte
@@ -58,18 +57,14 @@ func (r *Repository) GetPasskeyRecoveryData(ctx context.Context, userID int64) (
return &result, nil
}
-// ValidatePasskeyRecoverySecret checks if the passkey skip secret is valid for a user
func (r *Repository) ValidatePasskeyRecoverySecret(userID int64, secret string) (bool, error) {
- // get server_passkey_secret_data and server_passkey_secret_nonce for given user id
var severSecreteData, serverSecretNonce []byte
row := r.Db.QueryRow(`SELECT server_passkey_secret_data, server_passkey_secret_nonce FROM two_factor_recovery WHERE user_id = $1`, userID)
err := row.Scan(&severSecreteData, &serverSecretNonce)
if err != nil {
return false, stacktrace.Propagate(err, "")
}
- // decrypt server_passkey_secret_data
serverSkipSecretKey, decErr := crypto.Decrypt(severSecreteData, r.SecretEncryptionKey, serverSecretNonce)
- // serverSkipSecretKey, decErr := crypto.Decrypt(severSecreteData,serverSecretNonce, r.SecretEncryptionKey )
if decErr != nil {
return false, stacktrace.Propagate(decErr, "failed to decrypt passkey reset key")
}
diff --git a/server/pkg/repo/twofactor.go b/server/pkg/repo/twofactor.go
index 324a8d0170..de6ec5433e 100644
--- a/server/pkg/repo/twofactor.go
+++ b/server/pkg/repo/twofactor.go
@@ -14,7 +14,6 @@ type TwoFactorRepository struct {
SecretEncryptionKey []byte
}
-// GetTwoFactorSecret gets the user's two factor secret
func (repo *TwoFactorRepository) GetTwoFactorSecret(userID int64) (string, error) {
var encryptedTwoFASecret, nonce []byte
row := repo.DB.QueryRow(`SELECT encrypted_two_factor_secret, two_factor_secret_decryption_nonce FROM two_factor WHERE user_id = $1`, userID)
@@ -29,27 +28,23 @@ func (repo *TwoFactorRepository) GetTwoFactorSecret(userID int64) (string, error
return twoFASecret, nil
}
-// UpdateTwoFactorStatus the activates/deactivates user's two factor
func (repo *TwoFactorRepository) UpdateTwoFactorStatus(userID int64, status bool) error {
_, err := repo.DB.Exec(`UPDATE users SET is_two_factor_enabled = $1 WHERE user_id = $2`, status, userID)
return stacktrace.Propagate(err, "")
}
-// AddTwoFactorSession added a new two factor session a user
func (repo *TwoFactorRepository) AddTwoFactorSession(userID int64, sessionID string, expirationTime int64) error {
_, err := repo.DB.Exec(`INSERT INTO two_factor_sessions(user_id, session_id, creation_time, expiration_time) VALUES($1, $2, $3, $4)`,
userID, sessionID, time.Microseconds(), expirationTime)
return stacktrace.Propagate(err, "")
}
-// RemoveExpiredTwoFactorSessions removes all two factor sessions that have expired
func (repo *TwoFactorRepository) RemoveExpiredTwoFactorSessions() error {
_, err := repo.DB.Exec(`DELETE FROM two_factor_sessions WHERE expiration_time <= $1`,
time.Microseconds())
return stacktrace.Propagate(err, "")
}
-// GetUserIDWithTwoFactorSession returns the userID associated with a given session
func (repo *TwoFactorRepository) GetUserIDWithTwoFactorSession(sessionID string) (int64, error) {
row := repo.DB.QueryRow(`SELECT user_id FROM two_factor_sessions WHERE session_id = $1 AND expiration_time > $2`, sessionID, time.Microseconds())
var id int64
@@ -60,7 +55,6 @@ func (repo *TwoFactorRepository) GetUserIDWithTwoFactorSession(sessionID string)
return id, nil
}
-// GetRecoveryKeyEncryptedTwoFactorSecret gets the user two factor encrypted with recovery key
func (repo *TwoFactorRepository) GetRecoveryKeyEncryptedTwoFactorSecret(userID int64) (ente.TwoFactorRecoveryResponse, error) {
var response ente.TwoFactorRecoveryResponse
row := repo.DB.QueryRow(`SELECT recovery_encrypted_two_factor_secret, recovery_two_factor_secret_decryption_nonce FROM two_factor WHERE user_id = $1`, userID)
@@ -71,7 +65,6 @@ func (repo *TwoFactorRepository) GetRecoveryKeyEncryptedTwoFactorSecret(userID i
return response, nil
}
-// VerifyTwoFactorSecret verifies the if a two secret factor secret belongs to a user
func (repo *TwoFactorRepository) VerifyTwoFactorSecret(userID int64, secretHash string) (bool, error) {
var exists bool
row := repo.DB.QueryRow(`SELECT EXISTS( SELECT 1 FROM two_factor WHERE user_id = $1 AND two_factor_secret_hash = $2)`, userID, secretHash)
@@ -82,7 +75,6 @@ func (repo *TwoFactorRepository) VerifyTwoFactorSecret(userID int64, secretHash
return exists, nil
}
-// SetTempTwoFactorSecret sets the two factor secret for a user when he tries to setup a new two-factor app
func (repo *TwoFactorRepository) SetTempTwoFactorSecret(userID int64, secret ente.EncryptionResult, secretHash string, expirationTime int64) error {
_, err := repo.DB.Exec(`INSERT INTO temp_two_factor(user_id, encrypted_two_factor_secret, two_factor_secret_decryption_nonce, two_factor_secret_hash, creation_time, expiration_time)
VALUES($1, $2, $3, $4, $5, $6)`,
@@ -90,7 +82,6 @@ func (repo *TwoFactorRepository) SetTempTwoFactorSecret(userID int64, secret ent
return stacktrace.Propagate(err, "")
}
-// GetTempTwoFactorSecret gets the user's two factor secret for validing and enabling a new two-factor configuration
func (repo *TwoFactorRepository) GetTempTwoFactorSecret(userID int64) ([]ente.EncryptionResult, []string, error) {
rows, err := repo.DB.Query(`SELECT encrypted_two_factor_secret, two_factor_secret_decryption_nonce, two_factor_secret_hash FROM temp_two_factor WHERE user_id = $1 AND expiration_time > $2`, userID, time.Microseconds())
if err != nil {
@@ -112,20 +103,17 @@ func (repo *TwoFactorRepository) GetTempTwoFactorSecret(userID int64) ([]ente.En
return encryptedSecrets, hashedSecrets, nil
}
-// RemoveTempTwoFactorSecret removes the specified secret with hash value `secretHash`
func (repo *TwoFactorRepository) RemoveTempTwoFactorSecret(secretHash string) error {
_, err := repo.DB.Exec(`DELETE FROM temp_two_factor WHERE two_factor_secret_hash = $1`, secretHash)
return stacktrace.Propagate(err, "")
}
-// RemoveExpiredTempTwoFactorSecrets removes all two temp factor secrets that have expired
func (repo *TwoFactorRepository) RemoveExpiredTempTwoFactorSecrets() error {
_, err := repo.DB.Exec(`DELETE FROM temp_two_factor WHERE expiration_time <= $1`,
time.Microseconds())
return stacktrace.Propagate(err, "")
}
-// GetWrongAttempts returns the wrong attempt count for the given two factor session
func (repo *TwoFactorRepository) GetWrongAttempts(sessionID string) (int, error) {
row := repo.DB.QueryRow(`SELECT wrong_attempt FROM two_factor_sessions WHERE session_id = $1`,
sessionID)
@@ -165,7 +153,6 @@ func (repo *TwoFactorRepository) TryRecordUsedOTPCode(userID int64, codeHash str
return rowsAffected > 0, nil
}
-// RemoveExpiredUsedOTPCodes removes OTP codes older than the specified duration
func (repo *TwoFactorRepository) RemoveExpiredUsedOTPCodes(expirationMicroseconds int64) error {
cutoffTime := time.Microseconds() - expirationMicroseconds
_, err := repo.DB.Exec(`DELETE FROM two_factor_used_codes WHERE used_at < $1`, cutoffTime)
diff --git a/server/pkg/repo/usage.go b/server/pkg/repo/usage.go
index 5cdb487493..377e7afd15 100644
--- a/server/pkg/repo/usage.go
+++ b/server/pkg/repo/usage.go
@@ -9,7 +9,6 @@ import (
"github.com/lib/pq"
)
-// UsageRepository defines the methods tracking and fetching usage related date
type UsageRepository struct {
DB *sql.DB
UserRepo *UserRepository
@@ -32,7 +31,6 @@ type StorageWarningCandidate struct {
IsFamilyPlan bool
}
-// GetUsage gets the Storage usage of a user
func (repo *UsageRepository) GetUsage(userID int64) (int64, error) {
row := repo.DB.QueryRow(`SELECT storage_consumed FROM usage WHERE user_id = $1`,
userID)
@@ -44,16 +42,14 @@ func (repo *UsageRepository) GetUsage(userID int64) (int64, error) {
return usage, stacktrace.Propagate(err, "")
}
-// Create inserts a new entry for the given user. If entry already exists, it doesn't nothing
func (repo *UsageRepository) Create(userID int64) error {
_, err := repo.DB.Exec(`INSERT INTO usage(user_id, storage_consumed) VALUES ($1,$2) ON CONFLICT DO NOTHING;`,
- userID, //$1 user_id
- 0, // $2 initial value for storage consumed
+ userID,
+ 0,
)
return stacktrace.Propagate(err, "failed to insert/update")
}
-// GetCombinedUsage gets the sum of Storage usage of the list of userIDS
func (repo *UsageRepository) GetCombinedUsage(ctx context.Context, userIDs []int64) (int64, error) {
row := repo.DB.QueryRowContext(ctx, `SELECT coalesce(sum(storage_consumed),0) FROM usage WHERE user_id = ANY($1)`,
pq.Array(userIDs))
@@ -112,7 +108,6 @@ func (repo *UsageRepository) GetLockerUsage(ctx context.Context, userIDs []int64
return usage, nil
}
- // Initialize map with all requested users
userMap := make(map[int64]*UserLockerUsage)
for _, userID := range userIDs {
userMap[userID] = &UserLockerUsage{
@@ -122,7 +117,6 @@ func (repo *UsageRepository) GetLockerUsage(ctx context.Context, userIDs []int64
}
}
- // Query 1: Get file counts (non-deleted only)
countQuery := `
SELECT
c.owner_id,
@@ -136,7 +130,6 @@ func (repo *UsageRepository) GetLockerUsage(ctx context.Context, userIDs []int64
GROUP BY c.owner_id;
`
- // Query 2: Get total sizes (all files)
sizeQuery := `
SELECT
unique_files.owner_id,
@@ -153,7 +146,6 @@ func (repo *UsageRepository) GetLockerUsage(ctx context.Context, userIDs []int64
GROUP BY unique_files.owner_id;
`
- // Get counts
rows, err := repo.DB.QueryContext(ctx, countQuery, pq.Array(userIDs))
if err != nil {
return nil, stacktrace.Propagate(err, "")
@@ -171,7 +163,6 @@ func (repo *UsageRepository) GetLockerUsage(ctx context.Context, userIDs []int64
}
rows.Close()
- // Get sizes
rows, err = repo.DB.QueryContext(ctx, sizeQuery, pq.Array(userIDs))
if err != nil {
return nil, stacktrace.Propagate(err, "")
@@ -188,7 +179,6 @@ func (repo *UsageRepository) GetLockerUsage(ctx context.Context, userIDs []int64
}
}
- // Build result - now includes ALL requested users
for _, userID := range userIDs {
user := userMap[userID]
usage.Users = append(usage.Users, *user)
@@ -203,7 +193,6 @@ func (repo *UsageRepository) GetLockerUsage(ctx context.Context, userIDs []int64
return usage, nil
}
-// StorageForFamilyAdmin calculates the total storage consumed by the family for a given adminID
func (repo *UsageRepository) StorageForFamilyAdmin(adminID int64) (int64, error) {
query := `
SELECT COALESCE(SUM(storage_consumed), 0)
diff --git a/server/pkg/repo/userauth.go b/server/pkg/repo/userauth.go
index a2f5aa7967..cee523cbfa 100644
--- a/server/pkg/repo/userauth.go
+++ b/server/pkg/repo/userauth.go
@@ -11,13 +11,10 @@ import (
"github.com/lib/pq"
)
-// UserAuthRepository defines the methods for inserting, updating and retrieving
-// one time tokens (currently) used for email verification.
type UserAuthRepository struct {
DB *sql.DB
}
-// AddOTT saves the provided one time token for the specified user
func (repo *UserAuthRepository) AddOTT(emailHash string, app ente.App, ott string, expirationTime int64) error {
_, err := repo.DB.Exec(`INSERT INTO otts(email_hash, ott, creation_time, expiration_time, app)
VALUES($1, $2, $3, $4, $5)
@@ -39,14 +36,12 @@ func (repo *UserAuthRepository) RemoveOTT(emailHash string, ott string, app ente
return rowsAffected > 0, nil
}
-// RemoveExpiredOTTs removes all OTTs that have expired
func (repo *UserAuthRepository) RemoveExpiredOTTs() error {
_, err := repo.DB.Exec(`DELETE FROM otts WHERE expiration_time <= $1`,
time.Microseconds())
return stacktrace.Propagate(err, "")
}
-// GetTokenCreationTime return the creation_time for the given token
func (repo *UserAuthRepository) GetTokenCreationTime(token string) (int64, error) {
row := repo.DB.QueryRow(`SELECT creation_time from tokens where token = $1`, token)
var result int64
@@ -92,7 +87,6 @@ func (repo *UserAuthRepository) GetAppsForUser(userID int64) ([]ente.App, error)
return apps, nil
}
-// GetValidOTTs returns the list of OTTs that haven't expired for a given user
func (repo *UserAuthRepository) GetValidOTTs(emailHash string, app ente.App) ([]string, error) {
rows, err := repo.DB.Query(`SELECT ott FROM otts WHERE email_hash = $1 AND app = $2 AND expiration_time > $3`,
emailHash, app, time.Microseconds())
@@ -134,7 +128,6 @@ func (repo *UserAuthRepository) RecordWrongAttemptForActiveOtt(emailHash string,
return nil
}
-// AddToken saves the provided long lived token for the specified user
func (repo *UserAuthRepository) AddToken(userID int64, app ente.App, token string, ip string, userAgent string) error {
_, err := repo.DB.Exec(`INSERT INTO tokens(user_id, app, token, creation_time, ip, user_agent) VALUES($1, $2, $3, $4, $5, $6)`,
userID, app, token, time.Microseconds(), ip, userAgent)
@@ -162,21 +155,18 @@ func (repo *UserAuthRepository) GetUserIDWithToken(token string, app ente.App) (
return id, isExpired, nil
}
-// RemoveToken marks the specified token (to be used when a user logs out) as deleted
func (repo *UserAuthRepository) RemoveToken(userID int64, token string) error {
_, err := repo.DB.Exec(`UPDATE tokens SET is_deleted = true WHERE user_id = $1 AND token = $2`,
userID, token)
return stacktrace.Propagate(err, "")
}
-// UpdateLastUsedAt updates the last used at timestamp for the particular token
func (repo *UserAuthRepository) UpdateLastUsedAt(userID int64, token string, ip string, userAgent string) error {
_, err := repo.DB.Exec(`UPDATE tokens SET ip = $1, user_agent = $2, last_used_at = $3 WHERE user_id = $4 AND token = $5`,
ip, userAgent, time.Microseconds(), userID, token)
return stacktrace.Propagate(err, "")
}
-// RemoveAllOtherTokens marks the all tokens apart from the specified one for a user as deleted
func (repo *UserAuthRepository) RemoveAllOtherTokens(userID int64, token string) error {
_, err := repo.DB.Exec(`UPDATE tokens SET is_deleted = true WHERE user_id = $1 AND token <> $2`,
userID, token)
@@ -188,7 +178,6 @@ func (repo *UserAuthRepository) RemoveDeletedTokens(expiryTime int64) error {
return stacktrace.Propagate(err, "")
}
-// RemoveTokensForApps marks all tokens for the given apps as deleted for the user.
func (repo *UserAuthRepository) RemoveTokensForApps(userID int64, apps []ente.App) error {
if len(apps) == 0 {
return nil
@@ -202,13 +191,11 @@ func (repo *UserAuthRepository) RemoveTokensForApps(userID int64, apps []ente.Ap
return stacktrace.Propagate(err, "")
}
-// RemoveAllTokens marks the all tokens for a user as deleted
func (repo *UserAuthRepository) RemoveAllTokens(userID int64) error {
_, err := repo.DB.Exec(`UPDATE tokens SET is_deleted = true WHERE user_id = $1`, userID)
return stacktrace.Propagate(err, "")
}
-// GetActiveSessions returns the list of tokens that are valid for a given user
func (repo *UserAuthRepository) GetActiveSessions(userID int64, app ente.App) ([]ente.Session, error) {
rows, err := repo.DB.Query(`SELECT token, creation_time, ip, user_agent, last_used_at FROM tokens WHERE user_id = $1 AND app = $2 AND is_deleted = false`, userID, app)
if err != nil {
@@ -241,7 +228,6 @@ func (repo *UserAuthRepository) GetActiveSessions(userID int64, app ente.App) ([
return sessions, nil
}
-// GetMinUserID returns the first user that was created in the system
func (repo *UserAuthRepository) GetMinUserID() (int64, error) {
row := repo.DB.QueryRow(`select min(user_id) from users;`)
var id int64
diff --git a/server/pkg/repo/userentity/data.go b/server/pkg/repo/userentity/data.go
index 876ffe2c6d..7cd64b7334 100644
--- a/server/pkg/repo/userentity/data.go
+++ b/server/pkg/repo/userentity/data.go
@@ -11,7 +11,6 @@ import (
"github.com/sirupsen/logrus"
)
-// Create inserts a new entry
func (r *Repository) Create(ctx context.Context, userID int64, entry model.EntityDataRequest) (string, error) {
var id string
if entry.ID != nil {
@@ -32,11 +31,11 @@ func (r *Repository) Create(ctx context.Context, userID int64, entry model.Entit
type,
encrypted_data,
header) VALUES ($1,$2,$3,$4,$5) RETURNING id`,
- id, //$1 id
- userID, // $2 user_id
- entry.Type, // $3 type
- entry.EncryptedData, // $4 encrypted_data
- entry.Header). // $5 header
+ id,
+ userID,
+ entry.Type,
+ entry.EncryptedData,
+ entry.Header).
Scan(&id)
if err != nil {
return id, stacktrace.Propagate(err, "failed to create enity data")
@@ -81,8 +80,8 @@ func (r *Repository) Get(ctx context.Context, userID int64, id string) (*model.E
FROM entity_data
WHERE id = $1 AND
user_id = $2`,
- id, // $1
- userID, // %2 // $3
+ id,
+ userID,
)
err := row.Scan(&res.ID, &res.UserID, &res.Type, &res.EncryptedData, &res.Header, &res.IsDeleted, &res.CreatedAt, &res.UpdatedAt)
if err != nil {
@@ -128,8 +127,6 @@ func (r *Repository) Update(ctx context.Context, userID int64, req model.UpdateE
return nil
}
-// GetDiff returns the &{[]model.EntityData} which have been added or
-// modified after the given sinceTime
func (r *Repository) GetDiff(ctx context.Context, userID int64, eType model.EntityType, sinceTime int64, limit int16) ([]model.EntityData, error) {
rows, err := r.DB.QueryContext(ctx, `SELECT
id, user_id, type, encrypted_data, header, is_deleted, created_at, updated_at
@@ -139,9 +136,9 @@ func (r *Repository) GetDiff(ctx context.Context, userID int64, eType model.Enti
ORDER BY updated_at
LIMIT $4`,
userID,
- eType, // $2
- sinceTime, // $3
- limit, // $4
+ eType,
+ sinceTime,
+ limit,
)
if err != nil {
return nil, stacktrace.Propagate(err, "GetDiff query failed")
diff --git a/server/pkg/repo/userentity/repository.go b/server/pkg/repo/userentity/repository.go
index 5dc9ba9db8..73b53a1ffd 100644
--- a/server/pkg/repo/userentity/repository.go
+++ b/server/pkg/repo/userentity/repository.go
@@ -4,8 +4,6 @@ import (
"database/sql"
)
-// Repository defines the methods for inserting, updating and retrieving
-// userentity related keys and entities from the underlying repository
type Repository struct {
DB *sql.DB
}