🗑️ Remove account
This commit is contained in:
@ -6,7 +6,6 @@ import (
|
||||
)
|
||||
|
||||
var AutoMaintainRange = []any{
|
||||
&models.Account{},
|
||||
&models.AttachmentPool{},
|
||||
&models.Attachment{},
|
||||
&models.StickerPack{},
|
||||
|
@ -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")
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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"`
|
||||
}
|
@ -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"`
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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"`
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,6 @@ func createAttachmentDirectly(c *fiber.Ctx) error {
|
||||
|
||||
tx.Commit()
|
||||
|
||||
metadata.Account = models.Account{UserInfo: user}
|
||||
metadata.Pool = &pool
|
||||
services.PublishAnalyzeTask(metadata)
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user