π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[server] Update endpoint
Neeraj Guptabf7f1d43c0a5
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.goindex 3391b43ecc..c9144a30b9 100644--- a/server/cmd/museum/main.go+++ b/server/cmd/museum/main.go@@ -653,7 +653,7 @@ func main() {adminAPI.POST("/emails-from-hashes", adminHandler.GetEmailsFromHashes)adminAPI.PUT("/user/subscription", adminHandler.UpdateSubscription)adminAPI.POST("/queue/re-queue", adminHandler.ReQueueItem)- adminAPI.POST("/user/bf-2013", adminHandler.UpdateBFDeal)+ adminAPI.POST("/user/bonus", adminHandler.UpdateBonus)adminAPI.POST("/job/clear-orphan-objects", adminHandler.ClearOrphanObjects)userEntityController := &userEntityCtrl.Controller{Repo: userEntityRepo}diff --git a/server/ente/admin.go b/server/ente/admin.goindex 828173be7f..75ab9f3b53 100644--- a/server/ente/admin.go+++ b/server/ente/admin.go@@ -86,7 +86,7 @@ const (UPDATE AddOnAction = "UPDATE")-type UpdateBlackFridayDeal struct {+type SupportUpdateBonus struct {Action AddOnAction `json:"action" binding:"required"`UserID int64 `json:"userID" binding:"required"`Year int `json:"year"`@@ -96,15 +96,15 @@ type UpdateBlackFridayDeal struct {Minute int64 `json:"minute"`}-func (u UpdateBlackFridayDeal) UpdateLog() string {+func (u SupportUpdateBonus) UpdateLog() string {if u.Testing {- return fmt.Sprintf("BF_UPDATE_TESTING: %s, storageInMB: %d, minute: %d", u.Action, u.StorageInMB, u.Minute)+ return fmt.Sprintf("SupportUpdateBonus: %s, storageInMB: %d, minute: %d", u.Action, u.StorageInMB, u.Minute)} else {return fmt.Sprintf("BF_UPDATE: %s, storageInGB: %d, year: %d", u.Action, u.StorageInGB, u.Year)}}-func (u UpdateBlackFridayDeal) Validate() error {+func (u SupportUpdateBonus) Validate() error {if u.Action == ADD || u.Action == UPDATE {if u.Testing {if u.StorageInMB == 0 && u.Minute == 0 {diff --git a/server/pkg/api/admin.go b/server/pkg/api/admin.goindex 53be188779..6e301df7e1 100644--- a/server/pkg/api/admin.go+++ b/server/pkg/api/admin.go@@ -452,8 +452,8 @@ func (h *AdminHandler) ReQueueItem(c *gin.Context) {c.JSON(http.StatusOK, gin.H{})}-func (h *AdminHandler) UpdateBFDeal(c *gin.Context) {- var r ente.UpdateBlackFridayDeal+func (h *AdminHandler) UpdateBonus(c *gin.Context) {+ var r ente.SupportUpdateBonusif err := c.ShouldBindJSON(&r); err != nil {handler.Error(c, stacktrace.Propagate(ente.ErrBadRequest, "Bad request"))returndiff --git a/server/pkg/repo/storagebonus/bf_addon.go b/server/pkg/repo/storagebonus/bf_addon.goindex a057025486..edaca9b52b 100644--- a/server/pkg/repo/storagebonus/bf_addon.go+++ b/server/pkg/repo/storagebonus/bf_addon.go@@ -7,6 +7,9 @@ import ()func (r *Repository) InsertAddOnBonus(ctx context.Context, bonusType storagebonus.BonusType, userID int64, validTill int64, storage int64) error {+ if err := _validate(bonusType); err != nil {+ return err+ }bonusID := fmt.Sprintf("%s-%d", bonusType, userID)_, err := r.DB.ExecContext(ctx, "INSERT INTO storage_bonus (bonus_id, user_id, storage, type, valid_till) VALUES ($1, $2, $3, $4, $5)", bonusID, userID, storage, storagebonus.AddOnBf2023, validTill)if err != nil {@@ -16,6 +19,9 @@ func (r *Repository) InsertAddOnBonus(ctx context.Context, bonusType storagebonu}func (r *Repository) RemoveAddOnBonus(ctx context.Context, bonusType storagebonus.BonusType, userID int64) (int64, error) {+ if err := _validate(bonusType); err != nil {+ return 0, err+ }bonusID := fmt.Sprintf("%s-%d", bonusType, userID)res, err := r.DB.ExecContext(ctx, "DELETE FROM storage_bonus WHERE bonus_id = $1", bonusID)if err != nil {@@ -25,6 +31,9 @@ func (r *Repository) RemoveAddOnBonus(ctx context.Context, bonusType storagebonu}func (r *Repository) UpdateAddOnBonus(ctx context.Context, bonusType storagebonus.BonusType, userID int64, validTill int64, storage int64) error {+ if err := _validate(bonusType); err != nil {+ return err+ }bonusID := fmt.Sprintf("%s-%d", bonusType, userID)_, err := r.DB.ExecContext(ctx, "UPDATE storage_bonus SET storage = $1, valid_till = $2 WHERE bonus_id = $3", storage, validTill, bonusID)if err != nil {@@ -32,3 +41,10 @@ func (r *Repository) UpdateAddOnBonus(ctx context.Context, bonusType storagebonu}return nil}++func _validate(bonusType storagebonus.BonusType) error {+ if bonusType == storagebonus.AddOnBf2023 || bonusType == storagebonus.AddOnSupport {+ return nil+ }+ return fmt.Errorf("invalid bonus type: %s", bonusType)+}