🗑️ Remove account

This commit is contained in:
LittleSheep 2024-11-03 01:53:57 +08:00
parent 94b777a3e4
commit 2d119826fe
16 changed files with 57 additions and 91 deletions

View File

@ -6,29 +6,19 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":recycle: Migrated to nexus"> <list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":recycle: Migrated to nexus">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" /> <change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" /> <change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/database/migrator.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/database/migrator.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/database/migrator.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/database/migrator.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/database/source.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/database/source.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/database/source.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/database/source.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/grpc/services.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/services.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/grpc/services.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/services.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/attachments_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/attachments_api.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/models/accounts.go" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/models/attachments.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/models/attachments.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/models/pools.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/models/pools.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/models/stickers.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/models/stickers.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/index_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/index_api.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/server/api/index_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/index_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/pools_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/pools_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/sticker_packs_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/sticker_packs_api.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/server/api/sticker_packs_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/sticker_packs_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/stickers_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/stickers_api.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/server/api/stickers_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/stickers_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/up_direct_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/up_direct_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/up_multipart_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/up_multipart_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/server.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/server.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/analyzer.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/analyzer.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/attachments.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/attachments.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/services/attachments.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/attachments.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/cleaner.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/cleaner.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/merger.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/merger.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/pools.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/pools.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/recycler.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/recycler.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/sticker_packs.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/sticker_packs.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/stickers.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/stickers.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/uploader.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/uploader.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/main.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/main.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@ -64,33 +54,33 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;DefaultGoTemplateProperty&quot;: &quot;Go File&quot;, "DefaultGoTemplateProperty": "Go File",
&quot;Go Build.Backend.executor&quot;: &quot;Run&quot;, "Go Build.Backend.executor": "Run",
&quot;Go 构建.Backend.executor&quot;: &quot;Run&quot;, "Go 构建.Backend.executor": "Run",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;RunOnceActivity.go.formatter.settings.were.checked&quot;: &quot;true&quot;, "RunOnceActivity.go.formatter.settings.were.checked": "true",
&quot;RunOnceActivity.go.migrated.go.modules.settings&quot;: &quot;true&quot;, "RunOnceActivity.go.migrated.go.modules.settings": "true",
&quot;RunOnceActivity.go.modules.automatic.dependencies.download&quot;: &quot;true&quot;, "RunOnceActivity.go.modules.automatic.dependencies.download": "true",
&quot;RunOnceActivity.go.modules.go.list.on.any.changes.was.set&quot;: &quot;true&quot;, "RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
&quot;git-widget-placeholder&quot;: &quot;refactor/nexus&quot;, "git-widget-placeholder": "master",
&quot;go.import.settings.migrated&quot;: &quot;true&quot;, "go.import.settings.migrated": "true",
&quot;go.sdk.automatically.set&quot;: &quot;true&quot;, "go.sdk.automatically.set": "true",
&quot;last_opened_file_path&quot;: &quot;/Users/littlesheep/Documents/Projects/Hydrogen/Paperclip/pkg/internal/gap&quot;, "last_opened_file_path": "/Users/littlesheep/Documents/Projects/Hypernet/Paperclip",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "nodejs_package_manager_path": "npm",
&quot;run.code.analysis.last.selected.profile&quot;: &quot;pProject Default&quot;, "run.code.analysis.last.selected.profile": "pProject Default",
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;, "settings.editor.selected.configurable": "preferences.pluginManager",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "vue.rearranger.settings.migration": "true"
}, },
&quot;keyToStringList&quot;: { "keyToStringList": {
&quot;DatabaseDriversLRU&quot;: [ "DatabaseDriversLRU": [
&quot;postgresql&quot; "postgresql"
] ]
} }
}</component> }]]></component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/pkg/internal/gap" /> <recent name="$PROJECT_DIR$/pkg/internal/gap" />

8
go.mod
View File

@ -1,11 +1,10 @@
module git.solsynth.dev/hypernet/paperclip module git.solsynth.dev/hypernet/paperclip
go 1.22.0 go 1.23.2
toolchain go1.23.2
require ( 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/barasher/go-exiftool v1.10.0
github.com/dgraph-io/ristretto v0.1.1 github.com/dgraph-io/ristretto v0.1.1
github.com/eko/gocache/lib/v4 v4.1.6 github.com/eko/gocache/lib/v4 v4.1.6
@ -31,6 +30,7 @@ require (
require ( require (
filippo.io/edwards25519 v1.1.0 // indirect 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/andybalholm/brotli v1.1.1 // indirect
github.com/armon/go-metrics v0.4.1 // indirect github.com/armon/go-metrics v0.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect github.com/beorn7/perks v1.0.1 // indirect

10
go.sum
View File

@ -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= 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 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= 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-20241102174036-194d27090415 h1:7K6rv7fLgT1KQptFHJPp6+fHITLdl3Or3uT7cl8fnOM=
git.solsynth.dev/hypernet/nexus v0.0.0-20241027051235-ae3583ead196/go.mod h1:fXQsHXGio+7/0U95IitKF07wS4yTdCMp5ms8wpFBwVI= git.solsynth.dev/hypernet/nexus v0.0.0-20241102174036-194d27090415/go.mod h1:fXQsHXGio+7/0U95IitKF07wS4yTdCMp5ms8wpFBwVI=
git.solsynth.dev/hypernet/nexus v0.0.0-20241031133156-6bb8eab3fcd8 h1:fo9WuAXcmxdGfYXZKTiAbqGLHAkeL7vf0zpwbjoUNc0= git.solsynth.dev/hypernet/passport v0.0.0-20241102174750-808e7998dd1c h1:RVY0xsYGpb22ZuITxS+xpFu76XpPDrOpbIuSMDjW1+Q=
git.solsynth.dev/hypernet/nexus v0.0.0-20241031133156-6bb8eab3fcd8/go.mod h1:fXQsHXGio+7/0U95IitKF07wS4yTdCMp5ms8wpFBwVI= 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/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/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= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=

View File

@ -6,7 +6,6 @@ import (
) )
var AutoMaintainRange = []any{ var AutoMaintainRange = []any{
&models.Account{},
&models.AttachmentPool{}, &models.AttachmentPool{},
&models.Attachment{}, &models.Attachment{},
&models.StickerPack{}, &models.StickerPack{},

View File

@ -13,7 +13,7 @@ import (
var C *gorm.DB var C *gorm.DB
func NewSource() error { func NewGorm() error {
var err error var err error
dsn, err := cruda.NewCrudaConn(gap.Nx).AllocDatabase("paperclip") dsn, err := cruda.NewCrudaConn(gap.Nx).AllocDatabase("paperclip")

View File

@ -7,7 +7,6 @@ import (
"git.solsynth.dev/hypernet/nexus/pkg/proto" "git.solsynth.dev/hypernet/nexus/pkg/proto"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database" "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) { 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) tx.Delete(model, "account_id = ?", numericId)
} }
} }
if tx.Delete(&models.Account{}, "id = ?", numericId).Error != nil {
tx.Rollback()
break
}
tx.Commit() tx.Commit()
} }
} }

View File

@ -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"`
}

View File

@ -46,6 +46,5 @@ type Attachment struct {
Pool *AttachmentPool `json:"pool"` Pool *AttachmentPool `json:"pool"`
PoolID *uint `json:"pool_id"` PoolID *uint `json:"pool_id"`
Account Account `json:"account"` AccountID uint `json:"account_id"`
AccountID uint `json:"account_id"`
} }

View File

@ -15,8 +15,7 @@ type AttachmentPool struct {
Attachments []Attachment `json:"attachments" gorm:"foreignKey:PoolID"` Attachments []Attachment `json:"attachments" gorm:"foreignKey:PoolID"`
Account *Account `json:"account"` AccountID *uint `json:"account_id"`
AccountID *uint `json:"account_id"`
} }
type AttachmentPoolConfig struct { type AttachmentPoolConfig struct {

View File

@ -14,7 +14,6 @@ type Sticker struct {
PackID uint `json:"pack_id"` PackID uint `json:"pack_id"`
Pack StickerPack `json:"pack"` Pack StickerPack `json:"pack"`
AccountID uint `json:"account_id"` AccountID uint `json:"account_id"`
Account Account `json:"account"`
} }
type StickerPack struct { type StickerPack struct {
@ -25,5 +24,4 @@ type StickerPack struct {
Description string `json:"description"` Description string `json:"description"`
Stickers []Sticker `json:"stickers" gorm:"foreignKey:PackID;constraint:OnDelete:CASCADE"` Stickers []Sticker `json:"stickers" gorm:"foreignKey:PackID;constraint:OnDelete:CASCADE"`
AccountID uint `json:"account_id"` AccountID uint `json:"account_id"`
Account Account `json:"account"`
} }

View File

@ -2,6 +2,8 @@ package api
import ( import (
"fmt" "fmt"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/gap"
"git.solsynth.dev/hypernet/passport/pkg/authkit"
"github.com/spf13/viper" "github.com/spf13/viper"
"gorm.io/datatypes" "gorm.io/datatypes"
"strings" "strings"
@ -53,12 +55,9 @@ func listAttachment(c *fiber.Ctx) error {
} }
if len(c.Query("author")) > 0 { if len(c.Query("author")) > 0 {
var author models.Account author, err := authkit.GetUserByName(gap.Nx, c.Query("author"))
if err := database.C.Where("name = ?", c.Query("author")).First(&author).Error; err != nil { if err == nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error()) tx = tx.Where("attachments.account_id = ?", author.ID)
} else {
prefix := viper.GetString("database.prefix")
tx = tx.Where(fmt.Sprintf("%sattachments.account_id = ?", prefix), author.ID)
} }
} }

View File

@ -3,9 +3,11 @@ package api
import ( import (
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec" "git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database" "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/models"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/server/exts" "git.solsynth.dev/hypernet/paperclip/pkg/internal/server/exts"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/services" "git.solsynth.dev/hypernet/paperclip/pkg/internal/services"
"git.solsynth.dev/hypernet/passport/pkg/authkit"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )
@ -20,10 +22,8 @@ func listStickerPacks(c *fiber.Ctx) error {
tx := database.C tx := database.C
if len(c.Query("author")) > 0 { if len(c.Query("author")) > 0 {
var author models.Account author, err := authkit.GetUserByName(gap.Nx, c.Query("author"))
if err := database.C.Where("name = ?", c.Query("author")).First(&author).Error; err != nil { if err == nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
} else {
tx = tx.Where("account_id = ?", author.ID) tx = tx.Where("account_id = ?", author.ID)
} }
} }

View File

@ -3,6 +3,8 @@ package api
import ( import (
"fmt" "fmt"
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec" "git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/gap"
"git.solsynth.dev/hypernet/passport/pkg/authkit"
"strings" "strings"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database" "git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
@ -41,10 +43,8 @@ func listStickers(c *fiber.Ctx) error {
tx := database.C tx := database.C
if len(c.Query("author")) > 0 { if len(c.Query("author")) > 0 {
var author models.Account author, err := authkit.GetUserByName(gap.Nx, c.Query("author"))
if err := database.C.Where("name = ?", c.Query("author")).First(&author).Error; err != nil { if err == nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
} else {
tx = tx.Where("account_id = ?", author.ID) tx = tx.Where("account_id = ?", author.ID)
} }
} }

View File

@ -65,7 +65,6 @@ func createAttachmentDirectly(c *fiber.Ctx) error {
tx.Commit() tx.Commit()
metadata.Account = models.Account{UserInfo: user}
metadata.Pool = &pool metadata.Pool = &pool
services.PublishAnalyzeTask(metadata) services.PublishAnalyzeTask(metadata)

View File

@ -53,9 +53,7 @@ func GetAttachmentByRID(rid string) (models.Attachment, error) {
GetAttachmentCacheKey(rid), GetAttachmentCacheKey(rid),
new(models.Attachment), new(models.Attachment),
); err == nil { ); err == nil {
if val.(models.Attachment).Account.ID > 0 { return val.(models.Attachment), nil
return val.(models.Attachment), nil
}
} }
var attachment models.Attachment var attachment models.Attachment
@ -90,9 +88,7 @@ func GetAttachmentCache(rid string) (models.Attachment, bool) {
GetAttachmentCacheKey(rid), GetAttachmentCacheKey(rid),
new(models.Attachment), new(models.Attachment),
); err == nil { ); err == nil {
if val.(models.Attachment).Account.ID > 0 { return val.(models.Attachment), true
return val.(models.Attachment), true
}
} }
return models.Attachment{}, false return models.Attachment{}, false
} }

View File

@ -60,7 +60,7 @@ func main() {
} }
// Connect to database // 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.") log.Fatal().Err(err).Msg("An error occurred when connect to database.")
} else if err := database.RunMigration(database.C); err != nil { } else if err := database.RunMigration(database.C); err != nil {
log.Fatal().Err(err).Msg("An error occurred when running database auto migration.") log.Fatal().Err(err).Msg("An error occurred when running database auto migration.")