diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index c1e14a6..17f36d2 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -6,29 +6,19 @@
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
@@ -64,33 +54,33 @@
- {
- "keyToString": {
- "DefaultGoTemplateProperty": "Go File",
- "Go Build.Backend.executor": "Run",
- "Go 构建.Backend.executor": "Run",
- "RunOnceActivity.ShowReadmeOnStart": "true",
- "RunOnceActivity.go.formatter.settings.were.checked": "true",
- "RunOnceActivity.go.migrated.go.modules.settings": "true",
- "RunOnceActivity.go.modules.automatic.dependencies.download": "true",
- "RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
- "git-widget-placeholder": "refactor/nexus",
- "go.import.settings.migrated": "true",
- "go.sdk.automatically.set": "true",
- "last_opened_file_path": "/Users/littlesheep/Documents/Projects/Hydrogen/Paperclip/pkg/internal/gap",
- "node.js.detected.package.eslint": "true",
- "node.js.selected.package.eslint": "(autodetect)",
- "nodejs_package_manager_path": "npm",
- "run.code.analysis.last.selected.profile": "pProject Default",
- "settings.editor.selected.configurable": "preferences.pluginManager",
- "vue.rearranger.settings.migration": "true"
+
+}]]>
diff --git a/go.mod b/go.mod
index 4eda458..7a1d352 100644
--- a/go.mod
+++ b/go.mod
@@ -1,11 +1,10 @@
module git.solsynth.dev/hypernet/paperclip
-go 1.22.0
-
-toolchain go1.23.2
+go 1.23.2
require (
- git.solsynth.dev/hypernet/nexus v0.0.0-20241031133156-6bb8eab3fcd8
+ git.solsynth.dev/hypernet/nexus v0.0.0-20241102174036-194d27090415
+ git.solsynth.dev/hypernet/passport v0.0.0-20241102174750-808e7998dd1c
github.com/barasher/go-exiftool v1.10.0
github.com/dgraph-io/ristretto v0.1.1
github.com/eko/gocache/lib/v4 v4.1.6
@@ -31,6 +30,7 @@ require (
require (
filippo.io/edwards25519 v1.1.0 // indirect
+ git.solsynth.dev/hypernet/pusher v0.0.0-20241026153052-cd2c326efa4e // indirect
github.com/andybalholm/brotli v1.1.1 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
diff --git a/go.sum b/go.sum
index 22a9626..d76633a 100644
--- a/go.sum
+++ b/go.sum
@@ -33,10 +33,12 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
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-20241027051235-ae3583ead196 h1:vTT1Vhz9OJHUh+D07AUFO3jjm3p8/dRo194REny0Wk4=
-git.solsynth.dev/hypernet/nexus v0.0.0-20241027051235-ae3583ead196/go.mod h1:fXQsHXGio+7/0U95IitKF07wS4yTdCMp5ms8wpFBwVI=
-git.solsynth.dev/hypernet/nexus v0.0.0-20241031133156-6bb8eab3fcd8 h1:fo9WuAXcmxdGfYXZKTiAbqGLHAkeL7vf0zpwbjoUNc0=
-git.solsynth.dev/hypernet/nexus v0.0.0-20241031133156-6bb8eab3fcd8/go.mod h1:fXQsHXGio+7/0U95IitKF07wS4yTdCMp5ms8wpFBwVI=
+git.solsynth.dev/hypernet/nexus v0.0.0-20241102174036-194d27090415 h1:7K6rv7fLgT1KQptFHJPp6+fHITLdl3Or3uT7cl8fnOM=
+git.solsynth.dev/hypernet/nexus v0.0.0-20241102174036-194d27090415/go.mod h1:fXQsHXGio+7/0U95IitKF07wS4yTdCMp5ms8wpFBwVI=
+git.solsynth.dev/hypernet/passport v0.0.0-20241102174750-808e7998dd1c h1:RVY0xsYGpb22ZuITxS+xpFu76XpPDrOpbIuSMDjW1+Q=
+git.solsynth.dev/hypernet/passport v0.0.0-20241102174750-808e7998dd1c/go.mod h1:Gj8uWVKUeUxU3Z6v1sYLGHB79ln1nubQ5XfsJVUcvWM=
+git.solsynth.dev/hypernet/pusher v0.0.0-20241026153052-cd2c326efa4e h1:DtHhMjgxS/spUt/KEdbRFtaVnepI6Vx8pbHdJaNH1hs=
+git.solsynth.dev/hypernet/pusher v0.0.0-20241026153052-cd2c326efa4e/go.mod h1:XHTqFU/vBe4JiuAjl87GUcL8+w/IizSNoqH6n3WkQFc=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
diff --git a/pkg/internal/database/migrator.go b/pkg/internal/database/migrator.go
index f2a850f..8a84da0 100644
--- a/pkg/internal/database/migrator.go
+++ b/pkg/internal/database/migrator.go
@@ -6,7 +6,6 @@ import (
)
var AutoMaintainRange = []any{
- &models.Account{},
&models.AttachmentPool{},
&models.Attachment{},
&models.StickerPack{},
diff --git a/pkg/internal/database/source.go b/pkg/internal/database/source.go
index ee2f9bd..dee325f 100644
--- a/pkg/internal/database/source.go
+++ b/pkg/internal/database/source.go
@@ -13,7 +13,7 @@ import (
var C *gorm.DB
-func NewSource() error {
+func NewGorm() error {
var err error
dsn, err := cruda.NewCrudaConn(gap.Nx).AllocDatabase("paperclip")
diff --git a/pkg/internal/grpc/services.go b/pkg/internal/grpc/services.go
index 8802142..0aea880 100644
--- a/pkg/internal/grpc/services.go
+++ b/pkg/internal/grpc/services.go
@@ -7,7 +7,6 @@ import (
"git.solsynth.dev/hypernet/nexus/pkg/proto"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
- "git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
)
func (v *Server) BroadcastEvent(ctx context.Context, in *proto.EventInfo) (*proto.EventResponse, error) {
@@ -35,10 +34,6 @@ func (v *Server) BroadcastEvent(ctx context.Context, in *proto.EventInfo) (*prot
tx.Delete(model, "account_id = ?", numericId)
}
}
- if tx.Delete(&models.Account{}, "id = ?", numericId).Error != nil {
- tx.Rollback()
- break
- }
tx.Commit()
}
}
diff --git a/pkg/internal/models/accounts.go b/pkg/internal/models/accounts.go
deleted file mode 100644
index 868eafe..0000000
--- a/pkg/internal/models/accounts.go
+++ /dev/null
@@ -1,10 +0,0 @@
-package models
-
-import "git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
-
-type Account struct {
- sec.UserInfo
-
- Attachments []Attachment `json:"attachments"`
- Pools []AttachmentPool `json:"pools"`
-}
diff --git a/pkg/internal/models/attachments.go b/pkg/internal/models/attachments.go
index 88426de..b8df398 100644
--- a/pkg/internal/models/attachments.go
+++ b/pkg/internal/models/attachments.go
@@ -46,6 +46,5 @@ type Attachment struct {
Pool *AttachmentPool `json:"pool"`
PoolID *uint `json:"pool_id"`
- Account Account `json:"account"`
- AccountID uint `json:"account_id"`
+ AccountID uint `json:"account_id"`
}
diff --git a/pkg/internal/models/pools.go b/pkg/internal/models/pools.go
index 2d687a8..15b1d24 100644
--- a/pkg/internal/models/pools.go
+++ b/pkg/internal/models/pools.go
@@ -15,8 +15,7 @@ type AttachmentPool struct {
Attachments []Attachment `json:"attachments" gorm:"foreignKey:PoolID"`
- Account *Account `json:"account"`
- AccountID *uint `json:"account_id"`
+ AccountID *uint `json:"account_id"`
}
type AttachmentPoolConfig struct {
diff --git a/pkg/internal/models/stickers.go b/pkg/internal/models/stickers.go
index d33c988..1dc5c57 100644
--- a/pkg/internal/models/stickers.go
+++ b/pkg/internal/models/stickers.go
@@ -14,7 +14,6 @@ type Sticker struct {
PackID uint `json:"pack_id"`
Pack StickerPack `json:"pack"`
AccountID uint `json:"account_id"`
- Account Account `json:"account"`
}
type StickerPack struct {
@@ -25,5 +24,4 @@ type StickerPack struct {
Description string `json:"description"`
Stickers []Sticker `json:"stickers" gorm:"foreignKey:PackID;constraint:OnDelete:CASCADE"`
AccountID uint `json:"account_id"`
- Account Account `json:"account"`
}
diff --git a/pkg/internal/server/api/index_api.go b/pkg/internal/server/api/index_api.go
index 5cdd6cb..2f8d41e 100644
--- a/pkg/internal/server/api/index_api.go
+++ b/pkg/internal/server/api/index_api.go
@@ -2,6 +2,8 @@ package api
import (
"fmt"
+ "git.solsynth.dev/hypernet/paperclip/pkg/internal/gap"
+ "git.solsynth.dev/hypernet/passport/pkg/authkit"
"github.com/spf13/viper"
"gorm.io/datatypes"
"strings"
@@ -53,12 +55,9 @@ func listAttachment(c *fiber.Ctx) error {
}
if len(c.Query("author")) > 0 {
- var author models.Account
- if err := database.C.Where("name = ?", c.Query("author")).First(&author).Error; err != nil {
- return fiber.NewError(fiber.StatusBadRequest, err.Error())
- } else {
- prefix := viper.GetString("database.prefix")
- tx = tx.Where(fmt.Sprintf("%sattachments.account_id = ?", prefix), author.ID)
+ author, err := authkit.GetUserByName(gap.Nx, c.Query("author"))
+ if err == nil {
+ tx = tx.Where("attachments.account_id = ?", author.ID)
}
}
diff --git a/pkg/internal/server/api/sticker_packs_api.go b/pkg/internal/server/api/sticker_packs_api.go
index b7d374d..a179bd3 100644
--- a/pkg/internal/server/api/sticker_packs_api.go
+++ b/pkg/internal/server/api/sticker_packs_api.go
@@ -3,9 +3,11 @@ package api
import (
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
+ "git.solsynth.dev/hypernet/paperclip/pkg/internal/gap"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/server/exts"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/services"
+ "git.solsynth.dev/hypernet/passport/pkg/authkit"
"github.com/gofiber/fiber/v2"
)
@@ -20,10 +22,8 @@ func listStickerPacks(c *fiber.Ctx) error {
tx := database.C
if len(c.Query("author")) > 0 {
- var author models.Account
- if err := database.C.Where("name = ?", c.Query("author")).First(&author).Error; err != nil {
- return fiber.NewError(fiber.StatusBadRequest, err.Error())
- } else {
+ author, err := authkit.GetUserByName(gap.Nx, c.Query("author"))
+ if err == nil {
tx = tx.Where("account_id = ?", author.ID)
}
}
diff --git a/pkg/internal/server/api/stickers_api.go b/pkg/internal/server/api/stickers_api.go
index 778cb37..b334f8a 100644
--- a/pkg/internal/server/api/stickers_api.go
+++ b/pkg/internal/server/api/stickers_api.go
@@ -3,6 +3,8 @@ package api
import (
"fmt"
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
+ "git.solsynth.dev/hypernet/paperclip/pkg/internal/gap"
+ "git.solsynth.dev/hypernet/passport/pkg/authkit"
"strings"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
@@ -41,10 +43,8 @@ func listStickers(c *fiber.Ctx) error {
tx := database.C
if len(c.Query("author")) > 0 {
- var author models.Account
- if err := database.C.Where("name = ?", c.Query("author")).First(&author).Error; err != nil {
- return fiber.NewError(fiber.StatusBadRequest, err.Error())
- } else {
+ author, err := authkit.GetUserByName(gap.Nx, c.Query("author"))
+ if err == nil {
tx = tx.Where("account_id = ?", author.ID)
}
}
diff --git a/pkg/internal/server/api/up_direct_api.go b/pkg/internal/server/api/up_direct_api.go
index 3f4fb54..5fb6e3b 100644
--- a/pkg/internal/server/api/up_direct_api.go
+++ b/pkg/internal/server/api/up_direct_api.go
@@ -65,7 +65,6 @@ func createAttachmentDirectly(c *fiber.Ctx) error {
tx.Commit()
- metadata.Account = models.Account{UserInfo: user}
metadata.Pool = &pool
services.PublishAnalyzeTask(metadata)
diff --git a/pkg/internal/services/attachments.go b/pkg/internal/services/attachments.go
index cc6a1fa..21de432 100644
--- a/pkg/internal/services/attachments.go
+++ b/pkg/internal/services/attachments.go
@@ -53,9 +53,7 @@ func GetAttachmentByRID(rid string) (models.Attachment, error) {
GetAttachmentCacheKey(rid),
new(models.Attachment),
); err == nil {
- if val.(models.Attachment).Account.ID > 0 {
- return val.(models.Attachment), nil
- }
+ return val.(models.Attachment), nil
}
var attachment models.Attachment
@@ -90,9 +88,7 @@ func GetAttachmentCache(rid string) (models.Attachment, bool) {
GetAttachmentCacheKey(rid),
new(models.Attachment),
); err == nil {
- if val.(models.Attachment).Account.ID > 0 {
- return val.(models.Attachment), true
- }
+ return val.(models.Attachment), true
}
return models.Attachment{}, false
}
diff --git a/pkg/main.go b/pkg/main.go
index ad67a72..4d27b59 100644
--- a/pkg/main.go
+++ b/pkg/main.go
@@ -60,7 +60,7 @@ func main() {
}
// Connect to database
- if err := database.NewSource(); err != nil {
+ if err := database.NewGorm(); err != nil {
log.Fatal().Err(err).Msg("An error occurred when connect to database.")
} else if err := database.RunMigration(database.C); err != nil {
log.Fatal().Err(err).Msg("An error occurred when running database auto migration.")