diff --git a/go.mod b/go.mod index 095a488..a150838 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.23.2 require ( git.solsynth.dev/hypernet/nexus v0.0.0-20250301065153-8ac88413e0e1 + git.solsynth.dev/hypernet/paperclip v0.0.0-20250310151112-1d866f317f47 git.solsynth.dev/hypernet/pusher v0.0.0-20250216145944-5fb769823a88 git.solsynth.dev/hypernet/wallet v0.0.0-20250129150034-87b94cdb5488 github.com/dgraph-io/ristretto v0.2.0 diff --git a/go.sum b/go.sum index 0ffd620..f3704ca 100644 --- a/go.sum +++ b/go.sum @@ -35,6 +35,8 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= git.solsynth.dev/hypernet/nexus v0.0.0-20250301065153-8ac88413e0e1 h1:Jf5yQr8Yln2YkDQ9CwJhVYNstR2vNKPViGnR2YAZLsE= git.solsynth.dev/hypernet/nexus v0.0.0-20250301065153-8ac88413e0e1/go.mod h1:AXafZRL/2DISS37ZNngY0DreFAuBoeKu8mEDmCie8kw= +git.solsynth.dev/hypernet/paperclip v0.0.0-20250310151112-1d866f317f47 h1:fvu+bNKPTNtQocssnKbEZ66MqR0iBfAxY3HwlqnmYyE= +git.solsynth.dev/hypernet/paperclip v0.0.0-20250310151112-1d866f317f47/go.mod h1:jvxq2qftz2v72x+24+cTFJdQKr9eHQTdk3KVR7cx36s= git.solsynth.dev/hypernet/pusher v0.0.0-20250216145944-5fb769823a88 h1:2HEENe9KUrdaJeNBzx9lsuXQGyzWqCgnLTKQnr8xFr8= git.solsynth.dev/hypernet/pusher v0.0.0-20250216145944-5fb769823a88/go.mod h1:ildzMtLagNsLK0Rkw4Hgk2TrrwqZnjwJIUx0MNZwcDY= git.solsynth.dev/hypernet/wallet v0.0.0-20250129150034-87b94cdb5488 h1:/9Ol+PfDQFAYtHo0kk6sxqiEsZ6epb6yUEsZJxy14Mk= diff --git a/pkg/internal/web/api/avatar_api.go b/pkg/internal/web/api/avatar_api.go index 74ca4ae..3480edc 100644 --- a/pkg/internal/web/api/avatar_api.go +++ b/pkg/internal/web/api/avatar_api.go @@ -1,12 +1,16 @@ package api import ( + "strconv" + + "git.solsynth.dev/hypernet/paperclip/pkg/filekit" + "git.solsynth.dev/hypernet/paperclip/pkg/proto" "git.solsynth.dev/hypernet/passport/pkg/authkit/models" "git.solsynth.dev/hypernet/passport/pkg/internal/database" + "git.solsynth.dev/hypernet/passport/pkg/internal/gap" "git.solsynth.dev/hypernet/passport/pkg/internal/services" "git.solsynth.dev/hypernet/passport/pkg/internal/web/exts" "github.com/gofiber/fiber/v2" - "strconv" ) func setAvatar(c *fiber.Ctx) error { @@ -23,6 +27,7 @@ func setAvatar(c *fiber.Ctx) error { return err } + og := user.Avatar user.Avatar = &data.AttachmentID if err := database.C.Save(&user).Error; err != nil { @@ -32,6 +37,17 @@ func setAvatar(c *fiber.Ctx) error { services.InvalidAuthCacheWithUser(user.ID) } + if og != nil && len(*og) > 0 { + filekit.CountAttachmentUsage(gap.Nx, &proto.UpdateUsageRequest{ + Rid: []string{*og}, + Delta: -1, + }) + } + filekit.CountAttachmentUsage(gap.Nx, &proto.UpdateUsageRequest{ + Rid: []string{*user.Avatar}, + Delta: 1, + }) + return c.SendStatus(fiber.StatusOK) } @@ -49,6 +65,7 @@ func setBanner(c *fiber.Ctx) error { return err } + og := user.Banner user.Banner = &data.AttachmentID if err := database.C.Save(&user).Error; err != nil { @@ -58,6 +75,17 @@ func setBanner(c *fiber.Ctx) error { services.InvalidAuthCacheWithUser(user.ID) } + if og != nil && len(*og) > 0 { + filekit.CountAttachmentUsage(gap.Nx, &proto.UpdateUsageRequest{ + Rid: []string{*og}, + Delta: -1, + }) + } + filekit.CountAttachmentUsage(gap.Nx, &proto.UpdateUsageRequest{ + Rid: []string{*user.Banner}, + Delta: 1, + }) + return c.SendStatus(fiber.StatusOK) }