feat: api to add torrent hash to blacklist

This commit is contained in:
Simon Ding
2024-10-10 00:49:32 +08:00
parent 7e4d907ef6
commit 5daeca0bd9
28 changed files with 1122 additions and 1137 deletions

View File

@@ -11,7 +11,7 @@ import (
"polaris/ent/migrate"
"polaris/ent/blocklist"
"polaris/ent/blacklist"
"polaris/ent/downloadclients"
"polaris/ent/episode"
"polaris/ent/history"
@@ -33,8 +33,8 @@ type Client struct {
config
// Schema is the client for creating, migrating and dropping schema.
Schema *migrate.Schema
// Blocklist is the client for interacting with the Blocklist builders.
Blocklist *BlocklistClient
// Blacklist is the client for interacting with the Blacklist builders.
Blacklist *BlacklistClient
// DownloadClients is the client for interacting with the DownloadClients builders.
DownloadClients *DownloadClientsClient
// Episode is the client for interacting with the Episode builders.
@@ -64,7 +64,7 @@ func NewClient(opts ...Option) *Client {
func (c *Client) init() {
c.Schema = migrate.NewSchema(c.driver)
c.Blocklist = NewBlocklistClient(c.config)
c.Blacklist = NewBlacklistClient(c.config)
c.DownloadClients = NewDownloadClientsClient(c.config)
c.Episode = NewEpisodeClient(c.config)
c.History = NewHistoryClient(c.config)
@@ -166,7 +166,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
return &Tx{
ctx: ctx,
config: cfg,
Blocklist: NewBlocklistClient(cfg),
Blacklist: NewBlacklistClient(cfg),
DownloadClients: NewDownloadClientsClient(cfg),
Episode: NewEpisodeClient(cfg),
History: NewHistoryClient(cfg),
@@ -195,7 +195,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
return &Tx{
ctx: ctx,
config: cfg,
Blocklist: NewBlocklistClient(cfg),
Blacklist: NewBlacklistClient(cfg),
DownloadClients: NewDownloadClientsClient(cfg),
Episode: NewEpisodeClient(cfg),
History: NewHistoryClient(cfg),
@@ -211,7 +211,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
//
// client.Debug().
// Blocklist.
// Blacklist.
// Query().
// Count(ctx)
func (c *Client) Debug() *Client {
@@ -234,7 +234,7 @@ func (c *Client) Close() error {
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
func (c *Client) Use(hooks ...Hook) {
for _, n := range []interface{ Use(...Hook) }{
c.Blocklist, c.DownloadClients, c.Episode, c.History, c.ImportList, c.Indexers,
c.Blacklist, c.DownloadClients, c.Episode, c.History, c.ImportList, c.Indexers,
c.Media, c.NotificationClient, c.Settings, c.Storage,
} {
n.Use(hooks...)
@@ -245,7 +245,7 @@ func (c *Client) Use(hooks ...Hook) {
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
func (c *Client) Intercept(interceptors ...Interceptor) {
for _, n := range []interface{ Intercept(...Interceptor) }{
c.Blocklist, c.DownloadClients, c.Episode, c.History, c.ImportList, c.Indexers,
c.Blacklist, c.DownloadClients, c.Episode, c.History, c.ImportList, c.Indexers,
c.Media, c.NotificationClient, c.Settings, c.Storage,
} {
n.Intercept(interceptors...)
@@ -255,8 +255,8 @@ func (c *Client) Intercept(interceptors ...Interceptor) {
// Mutate implements the ent.Mutator interface.
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
switch m := m.(type) {
case *BlocklistMutation:
return c.Blocklist.mutate(ctx, m)
case *BlacklistMutation:
return c.Blacklist.mutate(ctx, m)
case *DownloadClientsMutation:
return c.DownloadClients.mutate(ctx, m)
case *EpisodeMutation:
@@ -280,107 +280,107 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
}
}
// BlocklistClient is a client for the Blocklist schema.
type BlocklistClient struct {
// BlacklistClient is a client for the Blacklist schema.
type BlacklistClient struct {
config
}
// NewBlocklistClient returns a client for the Blocklist from the given config.
func NewBlocklistClient(c config) *BlocklistClient {
return &BlocklistClient{config: c}
// NewBlacklistClient returns a client for the Blacklist from the given config.
func NewBlacklistClient(c config) *BlacklistClient {
return &BlacklistClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `blocklist.Hooks(f(g(h())))`.
func (c *BlocklistClient) Use(hooks ...Hook) {
c.hooks.Blocklist = append(c.hooks.Blocklist, hooks...)
// A call to `Use(f, g, h)` equals to `blacklist.Hooks(f(g(h())))`.
func (c *BlacklistClient) Use(hooks ...Hook) {
c.hooks.Blacklist = append(c.hooks.Blacklist, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `blocklist.Intercept(f(g(h())))`.
func (c *BlocklistClient) Intercept(interceptors ...Interceptor) {
c.inters.Blocklist = append(c.inters.Blocklist, interceptors...)
// A call to `Intercept(f, g, h)` equals to `blacklist.Intercept(f(g(h())))`.
func (c *BlacklistClient) Intercept(interceptors ...Interceptor) {
c.inters.Blacklist = append(c.inters.Blacklist, interceptors...)
}
// Create returns a builder for creating a Blocklist entity.
func (c *BlocklistClient) Create() *BlocklistCreate {
mutation := newBlocklistMutation(c.config, OpCreate)
return &BlocklistCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
// Create returns a builder for creating a Blacklist entity.
func (c *BlacklistClient) Create() *BlacklistCreate {
mutation := newBlacklistMutation(c.config, OpCreate)
return &BlacklistCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of Blocklist entities.
func (c *BlocklistClient) CreateBulk(builders ...*BlocklistCreate) *BlocklistCreateBulk {
return &BlocklistCreateBulk{config: c.config, builders: builders}
// CreateBulk returns a builder for creating a bulk of Blacklist entities.
func (c *BlacklistClient) CreateBulk(builders ...*BlacklistCreate) *BlacklistCreateBulk {
return &BlacklistCreateBulk{config: c.config, builders: builders}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *BlocklistClient) MapCreateBulk(slice any, setFunc func(*BlocklistCreate, int)) *BlocklistCreateBulk {
func (c *BlacklistClient) MapCreateBulk(slice any, setFunc func(*BlacklistCreate, int)) *BlacklistCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &BlocklistCreateBulk{err: fmt.Errorf("calling to BlocklistClient.MapCreateBulk with wrong type %T, need slice", slice)}
return &BlacklistCreateBulk{err: fmt.Errorf("calling to BlacklistClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*BlocklistCreate, rv.Len())
builders := make([]*BlacklistCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &BlocklistCreateBulk{config: c.config, builders: builders}
return &BlacklistCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for Blocklist.
func (c *BlocklistClient) Update() *BlocklistUpdate {
mutation := newBlocklistMutation(c.config, OpUpdate)
return &BlocklistUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
// Update returns an update builder for Blacklist.
func (c *BlacklistClient) Update() *BlacklistUpdate {
mutation := newBlacklistMutation(c.config, OpUpdate)
return &BlacklistUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *BlocklistClient) UpdateOne(b *Blocklist) *BlocklistUpdateOne {
mutation := newBlocklistMutation(c.config, OpUpdateOne, withBlocklist(b))
return &BlocklistUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
func (c *BlacklistClient) UpdateOne(b *Blacklist) *BlacklistUpdateOne {
mutation := newBlacklistMutation(c.config, OpUpdateOne, withBlacklist(b))
return &BlacklistUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *BlocklistClient) UpdateOneID(id int) *BlocklistUpdateOne {
mutation := newBlocklistMutation(c.config, OpUpdateOne, withBlocklistID(id))
return &BlocklistUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
func (c *BlacklistClient) UpdateOneID(id int) *BlacklistUpdateOne {
mutation := newBlacklistMutation(c.config, OpUpdateOne, withBlacklistID(id))
return &BlacklistUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for Blocklist.
func (c *BlocklistClient) Delete() *BlocklistDelete {
mutation := newBlocklistMutation(c.config, OpDelete)
return &BlocklistDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
// Delete returns a delete builder for Blacklist.
func (c *BlacklistClient) Delete() *BlacklistDelete {
mutation := newBlacklistMutation(c.config, OpDelete)
return &BlacklistDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *BlocklistClient) DeleteOne(b *Blocklist) *BlocklistDeleteOne {
func (c *BlacklistClient) DeleteOne(b *Blacklist) *BlacklistDeleteOne {
return c.DeleteOneID(b.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *BlocklistClient) DeleteOneID(id int) *BlocklistDeleteOne {
builder := c.Delete().Where(blocklist.ID(id))
func (c *BlacklistClient) DeleteOneID(id int) *BlacklistDeleteOne {
builder := c.Delete().Where(blacklist.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &BlocklistDeleteOne{builder}
return &BlacklistDeleteOne{builder}
}
// Query returns a query builder for Blocklist.
func (c *BlocklistClient) Query() *BlocklistQuery {
return &BlocklistQuery{
// Query returns a query builder for Blacklist.
func (c *BlacklistClient) Query() *BlacklistQuery {
return &BlacklistQuery{
config: c.config,
ctx: &QueryContext{Type: TypeBlocklist},
ctx: &QueryContext{Type: TypeBlacklist},
inters: c.Interceptors(),
}
}
// Get returns a Blocklist entity by its id.
func (c *BlocklistClient) Get(ctx context.Context, id int) (*Blocklist, error) {
return c.Query().Where(blocklist.ID(id)).Only(ctx)
// Get returns a Blacklist entity by its id.
func (c *BlacklistClient) Get(ctx context.Context, id int) (*Blacklist, error) {
return c.Query().Where(blacklist.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *BlocklistClient) GetX(ctx context.Context, id int) *Blocklist {
func (c *BlacklistClient) GetX(ctx context.Context, id int) *Blacklist {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
@@ -389,27 +389,27 @@ func (c *BlocklistClient) GetX(ctx context.Context, id int) *Blocklist {
}
// Hooks returns the client hooks.
func (c *BlocklistClient) Hooks() []Hook {
return c.hooks.Blocklist
func (c *BlacklistClient) Hooks() []Hook {
return c.hooks.Blacklist
}
// Interceptors returns the client interceptors.
func (c *BlocklistClient) Interceptors() []Interceptor {
return c.inters.Blocklist
func (c *BlacklistClient) Interceptors() []Interceptor {
return c.inters.Blacklist
}
func (c *BlocklistClient) mutate(ctx context.Context, m *BlocklistMutation) (Value, error) {
func (c *BlacklistClient) mutate(ctx context.Context, m *BlacklistMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&BlocklistCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
return (&BlacklistCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&BlocklistUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
return (&BlacklistUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&BlocklistUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
return (&BlacklistUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&BlocklistDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
return (&BlacklistDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown Blocklist mutation op: %q", m.Op())
return nil, fmt.Errorf("ent: unknown Blacklist mutation op: %q", m.Op())
}
}
@@ -1645,11 +1645,11 @@ func (c *StorageClient) mutate(ctx context.Context, m *StorageMutation) (Value,
// hooks and interceptors per client, for fast access.
type (
hooks struct {
Blocklist, DownloadClients, Episode, History, ImportList, Indexers, Media,
Blacklist, DownloadClients, Episode, History, ImportList, Indexers, Media,
NotificationClient, Settings, Storage []ent.Hook
}
inters struct {
Blocklist, DownloadClients, Episode, History, ImportList, Indexers, Media,
Blacklist, DownloadClients, Episode, History, ImportList, Indexers, Media,
NotificationClient, Settings, Storage []ent.Interceptor
}
)