diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index bbadbf2..3e155d6 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,12 +4,8 @@
-
-
-
-
+
-
@@ -120,7 +116,6 @@
-
@@ -145,7 +140,8 @@
-
+
+
true
diff --git a/go.mod b/go.mod
index 46e6a98..e78d95b 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module git.solsynth.dev/hydrogen/paperclip
go 1.21.6
require (
- git.solsynth.dev/hydrogen/dealer v0.0.0-20240823113302-208da7e90fdb
+ git.solsynth.dev/hydrogen/dealer v0.0.0-20240911145828-d734d617bfc8
github.com/go-playground/validator/v10 v10.17.0
github.com/gofiber/fiber/v2 v2.52.4
github.com/google/uuid v1.6.0
diff --git a/go.sum b/go.sum
index 2b2d489..6088365 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,7 @@
git.solsynth.dev/hydrogen/dealer v0.0.0-20240823113302-208da7e90fdb h1:dv4uVDMe53eBprW2Q8ocAhZuO+DKWlWyxGiJMiwE62E=
git.solsynth.dev/hydrogen/dealer v0.0.0-20240823113302-208da7e90fdb/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
+git.solsynth.dev/hydrogen/dealer v0.0.0-20240911145828-d734d617bfc8 h1:kWheneSdSySG5tz9TAXrtr546JdMpQZTyWDFk4jeGwg=
+git.solsynth.dev/hydrogen/dealer v0.0.0-20240911145828-d734d617bfc8/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
diff --git a/pkg/internal/models/accounts.go b/pkg/internal/models/accounts.go
index af6c3b1..4dc1cef 100644
--- a/pkg/internal/models/accounts.go
+++ b/pkg/internal/models/accounts.go
@@ -1,19 +1,9 @@
package models
-// Account profiles basically fetched from Hydrogen.Passport
-// But cache at here for better usage
-// At the same time this model can make relations between local models
-type Account struct {
- BaseModel
+import "git.solsynth.dev/hydrogen/dealer/pkg/hyper"
- Name string `json:"name"`
- Nick string `json:"nick"`
- Avatar string `json:"avatar"`
- Banner string `json:"banner"`
- Description string `json:"description"`
- EmailAddress string `json:"email_address"`
- PowerLevel int `json:"power_level"`
- ExternalID uint `json:"external_id"`
+type Account struct {
+ hyper.BaseUser
Attachments []Attachment `json:"attachments"`
Pools []AttachmentPool `json:"pools"`
diff --git a/pkg/internal/server/exts/auth.go b/pkg/internal/server/exts/auth.go
deleted file mode 100644
index 104cdc6..0000000
--- a/pkg/internal/server/exts/auth.go
+++ /dev/null
@@ -1,19 +0,0 @@
-package exts
-
-import (
- "git.solsynth.dev/hydrogen/dealer/pkg/proto"
- "git.solsynth.dev/hydrogen/paperclip/pkg/internal/services"
- "github.com/gofiber/fiber/v2"
-)
-
-func LinkAccountMiddleware(c *fiber.Ctx) error {
- if val, ok := c.Locals("p_user").(*proto.UserInfo); ok {
- if account, err := services.LinkAccount(val); err != nil {
- return fiber.NewError(fiber.StatusInternalServerError, err.Error())
- } else {
- c.Locals("user", account)
- }
- }
-
- return c.Next()
-}
diff --git a/pkg/internal/server/server.go b/pkg/internal/server/server.go
index ac7a462..ebb4aca 100644
--- a/pkg/internal/server/server.go
+++ b/pkg/internal/server/server.go
@@ -3,9 +3,11 @@ package server
import (
"strings"
+ "git.solsynth.dev/hydrogen/dealer/pkg/hyper"
+ "git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/gap"
+ "git.solsynth.dev/hydrogen/paperclip/pkg/internal/models"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/server/api"
- "git.solsynth.dev/hydrogen/paperclip/pkg/internal/server/exts"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
@@ -54,7 +56,15 @@ func NewServer() {
}))
app.Use(gap.H.AuthMiddleware)
- app.Use(exts.LinkAccountMiddleware)
+ app.Use(hyper.LinkAccountMiddleware(
+ database.C,
+ &models.Account{},
+ func(u hyper.BaseUser) models.Account {
+ return models.Account{
+ BaseUser: u,
+ }
+ },
+ ))
api.MapAPIs(app, "/api")
}
diff --git a/pkg/internal/services/auth.go b/pkg/internal/services/auth.go
deleted file mode 100644
index a661cf5..0000000
--- a/pkg/internal/services/auth.go
+++ /dev/null
@@ -1,51 +0,0 @@
-package services
-
-import (
- "errors"
- "fmt"
- "git.solsynth.dev/hydrogen/dealer/pkg/proto"
- "git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
- "git.solsynth.dev/hydrogen/paperclip/pkg/internal/models"
- "gorm.io/gorm"
- "reflect"
-)
-
-func LinkAccount(userinfo *proto.UserInfo) (models.Account, error) {
- var account models.Account
- if userinfo == nil {
- return account, fmt.Errorf("remote userinfo was not found")
- }
- if err := database.C.Where(&models.Account{
- ExternalID: uint(userinfo.Id),
- }).First(&account).Error; err != nil {
- if errors.Is(err, gorm.ErrRecordNotFound) {
- account = models.Account{
- Name: userinfo.Name,
- Nick: userinfo.Nick,
- Avatar: userinfo.Avatar,
- Banner: userinfo.Banner,
- Description: userinfo.GetDescription(),
- EmailAddress: userinfo.Email,
- PowerLevel: 0,
- ExternalID: uint(userinfo.Id),
- }
- return account, database.C.Save(&account).Error
- }
- return account, err
- }
-
- prev := account
- account.Name = userinfo.Name
- account.Nick = userinfo.Nick
- account.Avatar = userinfo.Avatar
- account.Banner = userinfo.Banner
- account.Description = userinfo.GetDescription()
- account.EmailAddress = userinfo.Email
-
- var err error
- if !reflect.DeepEqual(prev, account) {
- err = database.C.Save(&account).Error
- }
-
- return account, err
-}