refactor: db code

This commit is contained in:
Simon Ding
2025-04-22 15:39:47 +08:00
parent 26dc488d48
commit 7ccc73e044
8 changed files with 181 additions and 103 deletions

View File

@@ -4,10 +4,8 @@ import (
"fmt"
"polaris/engine"
"polaris/ent"
"polaris/ent/blacklist"
"polaris/ent/episode"
"polaris/ent/history"
"polaris/ent/schema"
"polaris/log"
"polaris/pkg/utils"
"strconv"
@@ -124,19 +122,19 @@ func (s *Server) addTorrent2Blacklist(link string) error {
if link == "" {
return nil
}
if hash, err := utils.MagnetHash(link); err != nil {
if _, err := utils.MagnetHash(link); err != nil {
return err
} else {
item := ent.Blacklist{
Type: blacklist.TypeTorrent,
Value: schema.BlacklistValue{
TorrentHash: hash,
},
}
err := s.db.AddBlacklistItem(&item)
if err != nil {
return errors.Wrap(err, "add to db")
}
// item := ent.Blacklist{
// Type: blacklist.TypeTorrent,
// Value: schema.BlacklistValue{
// TorrentHash: hash,
// },
// }
// err := s.db.AddBlacklistItem(&item)
// if err != nil {
// return errors.Wrap(err, "add to db")
// }
}
return nil
}

View File

@@ -21,7 +21,7 @@ import (
"github.com/pkg/errors"
)
func NewServer(db *db.Client) *Server {
func NewServer(db db.Database) *Server {
r := gin.Default()
s := &Server{
r: r,
@@ -36,7 +36,7 @@ func NewServer(db *db.Client) *Server {
type Server struct {
r *gin.Engine
db *db.Client
db db.Database
core *engine.Engine
language string
jwtSerect string