mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-24 20:50:46 +08:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4186d7d97f | ||
|
|
5d726dbcf1 | ||
|
|
ce25c090f5 | ||
|
|
2683c5dbf2 | ||
|
|
b717885270 | ||
|
|
4e457e99b9 | ||
|
|
ecfe31ea45 | ||
|
|
89104785d7 | ||
|
|
f4ccc69b50 | ||
|
|
40c6e2df5c | ||
|
|
37dfb0fe94 | ||
|
|
9968f9f225 | ||
|
|
f5c977224b | ||
|
|
8af3ffccd3 | ||
|
|
c535dfd714 | ||
|
|
f696b78260 | ||
|
|
4f3e3e399d |
40
.github/workflows/goreleaser.yml
vendored
Normal file
40
.github/workflows/goreleaser.yml
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
name: goreleaser
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
|
||||
jobs:
|
||||
goreleaser:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '>=1.23.0'
|
||||
check-latest: true
|
||||
-
|
||||
name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v6
|
||||
with:
|
||||
# either 'goreleaser' (default) or 'goreleaser-pro'
|
||||
distribution: goreleaser
|
||||
# 'latest', 'nightly', or a semver
|
||||
version: '~> v2'
|
||||
args: release --clean
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
|
||||
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -30,3 +30,5 @@ ui/dist/
|
||||
# Go workspace file
|
||||
go.work
|
||||
go.work.sum
|
||||
|
||||
dist/
|
||||
|
||||
51
.goreleaser.yaml
Normal file
51
.goreleaser.yaml
Normal file
@@ -0,0 +1,51 @@
|
||||
# This is an example .goreleaser.yml file with some sensible defaults.
|
||||
# Make sure to check the documentation at https://goreleaser.com
|
||||
|
||||
# The lines below are called `modelines`. See `:help modeline`
|
||||
# Feel free to remove those if you don't want/need to use them.
|
||||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
|
||||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
|
||||
|
||||
version: 2
|
||||
|
||||
before:
|
||||
hooks:
|
||||
# You may remove this if you don't use go modules.
|
||||
- go mod tidy
|
||||
# you may remove this if you don't need go generate
|
||||
#- go generate ./...
|
||||
|
||||
builds:
|
||||
- env:
|
||||
- CGO_ENABLED=0
|
||||
goos:
|
||||
- linux
|
||||
- windows
|
||||
- darwin
|
||||
- freebsd
|
||||
main: ./cmd
|
||||
goarch:
|
||||
- amd64
|
||||
- arm64
|
||||
|
||||
archives:
|
||||
- format: tar.gz
|
||||
# this name template makes the OS and Arch compatible with the results of `uname`.
|
||||
name_template: >-
|
||||
{{ .ProjectName }}_
|
||||
{{- title .Os }}_
|
||||
{{- if eq .Arch "amd64" }}x86_64
|
||||
{{- else if eq .Arch "386" }}i386
|
||||
{{- else }}{{ .Arch }}{{ end }}
|
||||
{{- if .Arm }}v{{ .Arm }}{{ end }}
|
||||
# use zip for windows archives
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- "^docs:"
|
||||
- "^test:"
|
||||
12
cmd/main.go
12
cmd/main.go
@@ -3,20 +3,28 @@ package main
|
||||
import (
|
||||
"polaris/db"
|
||||
"polaris/log"
|
||||
"polaris/pkg/utils"
|
||||
"polaris/server"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Infof("------------------- Starting Polaris ---------------------")
|
||||
|
||||
syscall.Umask(0) //max permission 0777
|
||||
utils.MaxPermission()
|
||||
|
||||
dbClient, err := db.Open()
|
||||
if err != nil {
|
||||
log.Panicf("init db error: %v", err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
time.Sleep(2 * time.Second)
|
||||
if err := utils.OpenURL("http://127.0.0.1:8080"); err != nil {
|
||||
log.Errorf("open url error: %v", err)
|
||||
}
|
||||
|
||||
}()
|
||||
s := server.NewServer(dbClient)
|
||||
if err := s.Serve(); err != nil {
|
||||
log.Errorf("server start error: %v", err)
|
||||
|
||||
23
db/const.go
23
db/const.go
@@ -14,6 +14,9 @@ const (
|
||||
SettingNfoSupportEnabled = "nfo_support_enabled"
|
||||
SettingAllowQiangban = "filter_qiangban"
|
||||
SettingEnableTmdbAdultContent = "tmdb_adult_content"
|
||||
SetttingSizeLimiter = "size_limiter"
|
||||
SettingTvNamingFormat = "tv_naming_format"
|
||||
SettingMovieNamingFormat = "movie_naming_format"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -34,6 +37,26 @@ const (
|
||||
LanguageCN = "zh-CN"
|
||||
)
|
||||
|
||||
const DefaultNamingFormat = "{{.NameCN}} {{.NameEN}} {{if .Year}} ({{.Year}}) {{end}}"
|
||||
|
||||
type NamingInfo struct {
|
||||
NameCN string
|
||||
NameEN string
|
||||
Year string
|
||||
TmdbID int
|
||||
}
|
||||
|
||||
type ResolutionType string
|
||||
|
||||
const JwtSerectKey = "jwt_secrect_key"
|
||||
|
||||
type SizeLimiter struct {
|
||||
R720p Limiter `json:"720p"`
|
||||
R1080p Limiter `json:"1080p"`
|
||||
R2160p Limiter `json:"2160p"`
|
||||
}
|
||||
|
||||
type Limiter struct {
|
||||
Max int `json:"max"`
|
||||
Min int `json:"min"`
|
||||
}
|
||||
|
||||
46
db/db.go
46
db/db.go
@@ -22,7 +22,8 @@ import (
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
_ "github.com/ncruces/go-sqlite3/driver"
|
||||
_ "github.com/ncruces/go-sqlite3/embed"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -530,6 +531,16 @@ func (c *Client) SetEpisodeStatus(id int, status episode.Status) error {
|
||||
return c.ent.Episode.Update().Where(episode.ID(id)).SetStatus(status).Exec(context.TODO())
|
||||
}
|
||||
|
||||
func (c *Client) IsEpisodeDownloadingOrDownloaded(id int) bool {
|
||||
his := c.ent.History.Query().Where(history.EpisodeID(id)).AllX(context.Background())
|
||||
for _, h := range his {
|
||||
if h.Status != history.StatusFail {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *Client) SetSeasonAllEpisodeStatus(mediaID, seasonNum int, status episode.Status) error {
|
||||
return c.ent.Episode.Update().Where(episode.MediaID(mediaID), episode.SeasonNumber(seasonNum)).SetStatus(status).Exec(context.TODO())
|
||||
}
|
||||
@@ -602,4 +613,35 @@ func (c *Client) AddImportlist(il *ent.ImportList) error {
|
||||
|
||||
func (c *Client) DeleteImportlist(id int) error {
|
||||
return c.ent.ImportList.DeleteOneID(id).Exec(context.TODO())
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) GetSizeLimiter() (*SizeLimiter, error) {
|
||||
v := c.GetSetting(SetttingSizeLimiter)
|
||||
var limiter SizeLimiter
|
||||
err := json.Unmarshal([]byte(v), &limiter)
|
||||
return &limiter, err
|
||||
}
|
||||
|
||||
func (c *Client) SetSizeLimiter(limiter *SizeLimiter) error {
|
||||
data, err := json.Marshal(limiter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.SetSetting(SetttingSizeLimiter, string(data))
|
||||
}
|
||||
|
||||
func (c *Client) GetTvNamingFormat() string {
|
||||
s := c.GetSetting(SettingTvNamingFormat)
|
||||
if s == "" {
|
||||
return DefaultNamingFormat
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (c *Client) GetMovingNamingFormat() string {
|
||||
s := c.GetSetting(SettingMovieNamingFormat)
|
||||
if s == "" {
|
||||
return DefaultNamingFormat
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
114
ent/blocklist.go
Normal file
114
ent/blocklist.go
Normal file
@@ -0,0 +1,114 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"polaris/ent/blocklist"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Blocklist is the model entity for the Blocklist schema.
|
||||
type Blocklist struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Type holds the value of the "type" field.
|
||||
Type blocklist.Type `json:"type,omitempty"`
|
||||
// Value holds the value of the "value" field.
|
||||
Value string `json:"value,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Blocklist) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case blocklist.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case blocklist.FieldType, blocklist.FieldValue:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Blocklist fields.
|
||||
func (b *Blocklist) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case blocklist.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
b.ID = int(value.Int64)
|
||||
case blocklist.FieldType:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field type", values[i])
|
||||
} else if value.Valid {
|
||||
b.Type = blocklist.Type(value.String)
|
||||
}
|
||||
case blocklist.FieldValue:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field value", values[i])
|
||||
} else if value.Valid {
|
||||
b.Value = value.String
|
||||
}
|
||||
default:
|
||||
b.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetValue returns the ent.Value that was dynamically selected and assigned to the Blocklist.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (b *Blocklist) GetValue(name string) (ent.Value, error) {
|
||||
return b.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Blocklist.
|
||||
// Note that you need to call Blocklist.Unwrap() before calling this method if this Blocklist
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (b *Blocklist) Update() *BlocklistUpdateOne {
|
||||
return NewBlocklistClient(b.config).UpdateOne(b)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Blocklist entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (b *Blocklist) Unwrap() *Blocklist {
|
||||
_tx, ok := b.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Blocklist is not a transactional entity")
|
||||
}
|
||||
b.config.driver = _tx.drv
|
||||
return b
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (b *Blocklist) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Blocklist(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", b.ID))
|
||||
builder.WriteString("type=")
|
||||
builder.WriteString(fmt.Sprintf("%v", b.Type))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("value=")
|
||||
builder.WriteString(b.Value)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Blocklists is a parsable slice of Blocklist.
|
||||
type Blocklists []*Blocklist
|
||||
80
ent/blocklist/blocklist.go
Normal file
80
ent/blocklist/blocklist.go
Normal file
@@ -0,0 +1,80 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package blocklist
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the blocklist type in the database.
|
||||
Label = "blocklist"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldType holds the string denoting the type field in the database.
|
||||
FieldType = "type"
|
||||
// FieldValue holds the string denoting the value field in the database.
|
||||
FieldValue = "value"
|
||||
// Table holds the table name of the blocklist in the database.
|
||||
Table = "blocklists"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for blocklist fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldType,
|
||||
FieldValue,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Type defines the type for the "type" enum field.
|
||||
type Type string
|
||||
|
||||
// Type values.
|
||||
const (
|
||||
TypeMedia Type = "media"
|
||||
TypeTorrent Type = "torrent"
|
||||
)
|
||||
|
||||
func (_type Type) String() string {
|
||||
return string(_type)
|
||||
}
|
||||
|
||||
// TypeValidator is a validator for the "type" field enum values. It is called by the builders before save.
|
||||
func TypeValidator(_type Type) error {
|
||||
switch _type {
|
||||
case TypeMedia, TypeTorrent:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("blocklist: invalid enum value for type field: %q", _type)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the Blocklist queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByType orders the results by the type field.
|
||||
func ByType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldType, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByValue orders the results by the value field.
|
||||
func ByValue(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldValue, opts...).ToFunc()
|
||||
}
|
||||
159
ent/blocklist/where.go
Normal file
159
ent/blocklist/where.go
Normal file
@@ -0,0 +1,159 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package blocklist
|
||||
|
||||
import (
|
||||
"polaris/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Value applies equality check predicate on the "value" field. It's identical to ValueEQ.
|
||||
func Value(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldEQ(FieldValue, v))
|
||||
}
|
||||
|
||||
// TypeEQ applies the EQ predicate on the "type" field.
|
||||
func TypeEQ(v Type) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeNEQ applies the NEQ predicate on the "type" field.
|
||||
func TypeNEQ(v Type) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldNEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeIn applies the In predicate on the "type" field.
|
||||
func TypeIn(vs ...Type) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// TypeNotIn applies the NotIn predicate on the "type" field.
|
||||
func TypeNotIn(vs ...Type) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldNotIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// ValueEQ applies the EQ predicate on the "value" field.
|
||||
func ValueEQ(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldEQ(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueNEQ applies the NEQ predicate on the "value" field.
|
||||
func ValueNEQ(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldNEQ(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueIn applies the In predicate on the "value" field.
|
||||
func ValueIn(vs ...string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldIn(FieldValue, vs...))
|
||||
}
|
||||
|
||||
// ValueNotIn applies the NotIn predicate on the "value" field.
|
||||
func ValueNotIn(vs ...string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldNotIn(FieldValue, vs...))
|
||||
}
|
||||
|
||||
// ValueGT applies the GT predicate on the "value" field.
|
||||
func ValueGT(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldGT(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueGTE applies the GTE predicate on the "value" field.
|
||||
func ValueGTE(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldGTE(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueLT applies the LT predicate on the "value" field.
|
||||
func ValueLT(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldLT(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueLTE applies the LTE predicate on the "value" field.
|
||||
func ValueLTE(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldLTE(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueContains applies the Contains predicate on the "value" field.
|
||||
func ValueContains(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldContains(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueHasPrefix applies the HasPrefix predicate on the "value" field.
|
||||
func ValueHasPrefix(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldHasPrefix(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueHasSuffix applies the HasSuffix predicate on the "value" field.
|
||||
func ValueHasSuffix(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldHasSuffix(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueEqualFold applies the EqualFold predicate on the "value" field.
|
||||
func ValueEqualFold(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldEqualFold(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueContainsFold applies the ContainsFold predicate on the "value" field.
|
||||
func ValueContainsFold(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldContainsFold(FieldValue, v))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Blocklist) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Blocklist) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Blocklist) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.NotPredicates(p))
|
||||
}
|
||||
201
ent/blocklist_create.go
Normal file
201
ent/blocklist_create.go
Normal file
@@ -0,0 +1,201 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/blocklist"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// BlocklistCreate is the builder for creating a Blocklist entity.
|
||||
type BlocklistCreate struct {
|
||||
config
|
||||
mutation *BlocklistMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (bc *BlocklistCreate) SetType(b blocklist.Type) *BlocklistCreate {
|
||||
bc.mutation.SetType(b)
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (bc *BlocklistCreate) SetValue(s string) *BlocklistCreate {
|
||||
bc.mutation.SetValue(s)
|
||||
return bc
|
||||
}
|
||||
|
||||
// Mutation returns the BlocklistMutation object of the builder.
|
||||
func (bc *BlocklistCreate) Mutation() *BlocklistMutation {
|
||||
return bc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Blocklist in the database.
|
||||
func (bc *BlocklistCreate) Save(ctx context.Context) (*Blocklist, error) {
|
||||
return withHooks(ctx, bc.sqlSave, bc.mutation, bc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (bc *BlocklistCreate) SaveX(ctx context.Context) *Blocklist {
|
||||
v, err := bc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (bc *BlocklistCreate) Exec(ctx context.Context) error {
|
||||
_, err := bc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (bc *BlocklistCreate) ExecX(ctx context.Context) {
|
||||
if err := bc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (bc *BlocklistCreate) check() error {
|
||||
if _, ok := bc.mutation.GetType(); !ok {
|
||||
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Blocklist.type"`)}
|
||||
}
|
||||
if v, ok := bc.mutation.GetType(); ok {
|
||||
if err := blocklist.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Blocklist.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := bc.mutation.Value(); !ok {
|
||||
return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "Blocklist.value"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (bc *BlocklistCreate) sqlSave(ctx context.Context) (*Blocklist, error) {
|
||||
if err := bc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := bc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, bc.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
bc.mutation.id = &_node.ID
|
||||
bc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (bc *BlocklistCreate) createSpec() (*Blocklist, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Blocklist{config: bc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(blocklist.Table, sqlgraph.NewFieldSpec(blocklist.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := bc.mutation.GetType(); ok {
|
||||
_spec.SetField(blocklist.FieldType, field.TypeEnum, value)
|
||||
_node.Type = value
|
||||
}
|
||||
if value, ok := bc.mutation.Value(); ok {
|
||||
_spec.SetField(blocklist.FieldValue, field.TypeString, value)
|
||||
_node.Value = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// BlocklistCreateBulk is the builder for creating many Blocklist entities in bulk.
|
||||
type BlocklistCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*BlocklistCreate
|
||||
}
|
||||
|
||||
// Save creates the Blocklist entities in the database.
|
||||
func (bcb *BlocklistCreateBulk) Save(ctx context.Context) ([]*Blocklist, error) {
|
||||
if bcb.err != nil {
|
||||
return nil, bcb.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(bcb.builders))
|
||||
nodes := make([]*Blocklist, len(bcb.builders))
|
||||
mutators := make([]Mutator, len(bcb.builders))
|
||||
for i := range bcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := bcb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*BlocklistMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, bcb.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, bcb.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, bcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (bcb *BlocklistCreateBulk) SaveX(ctx context.Context) []*Blocklist {
|
||||
v, err := bcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (bcb *BlocklistCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := bcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (bcb *BlocklistCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := bcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
88
ent/blocklist_delete.go
Normal file
88
ent/blocklist_delete.go
Normal file
@@ -0,0 +1,88 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"polaris/ent/blocklist"
|
||||
"polaris/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// BlocklistDelete is the builder for deleting a Blocklist entity.
|
||||
type BlocklistDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *BlocklistMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the BlocklistDelete builder.
|
||||
func (bd *BlocklistDelete) Where(ps ...predicate.Blocklist) *BlocklistDelete {
|
||||
bd.mutation.Where(ps...)
|
||||
return bd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (bd *BlocklistDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, bd.sqlExec, bd.mutation, bd.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (bd *BlocklistDelete) ExecX(ctx context.Context) int {
|
||||
n, err := bd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (bd *BlocklistDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(blocklist.Table, sqlgraph.NewFieldSpec(blocklist.FieldID, field.TypeInt))
|
||||
if ps := bd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, bd.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
bd.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// BlocklistDeleteOne is the builder for deleting a single Blocklist entity.
|
||||
type BlocklistDeleteOne struct {
|
||||
bd *BlocklistDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the BlocklistDelete builder.
|
||||
func (bdo *BlocklistDeleteOne) Where(ps ...predicate.Blocklist) *BlocklistDeleteOne {
|
||||
bdo.bd.mutation.Where(ps...)
|
||||
return bdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (bdo *BlocklistDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := bdo.bd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{blocklist.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (bdo *BlocklistDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := bdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
526
ent/blocklist_query.go
Normal file
526
ent/blocklist_query.go
Normal file
@@ -0,0 +1,526 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"polaris/ent/blocklist"
|
||||
"polaris/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// BlocklistQuery is the builder for querying Blocklist entities.
|
||||
type BlocklistQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []blocklist.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Blocklist
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the BlocklistQuery builder.
|
||||
func (bq *BlocklistQuery) Where(ps ...predicate.Blocklist) *BlocklistQuery {
|
||||
bq.predicates = append(bq.predicates, ps...)
|
||||
return bq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (bq *BlocklistQuery) Limit(limit int) *BlocklistQuery {
|
||||
bq.ctx.Limit = &limit
|
||||
return bq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (bq *BlocklistQuery) Offset(offset int) *BlocklistQuery {
|
||||
bq.ctx.Offset = &offset
|
||||
return bq
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (bq *BlocklistQuery) Unique(unique bool) *BlocklistQuery {
|
||||
bq.ctx.Unique = &unique
|
||||
return bq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (bq *BlocklistQuery) Order(o ...blocklist.OrderOption) *BlocklistQuery {
|
||||
bq.order = append(bq.order, o...)
|
||||
return bq
|
||||
}
|
||||
|
||||
// First returns the first Blocklist entity from the query.
|
||||
// Returns a *NotFoundError when no Blocklist was found.
|
||||
func (bq *BlocklistQuery) First(ctx context.Context) (*Blocklist, error) {
|
||||
nodes, err := bq.Limit(1).All(setContextOp(ctx, bq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{blocklist.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (bq *BlocklistQuery) FirstX(ctx context.Context) *Blocklist {
|
||||
node, err := bq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Blocklist ID from the query.
|
||||
// Returns a *NotFoundError when no Blocklist ID was found.
|
||||
func (bq *BlocklistQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = bq.Limit(1).IDs(setContextOp(ctx, bq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{blocklist.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (bq *BlocklistQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := bq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Blocklist entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Blocklist entity is found.
|
||||
// Returns a *NotFoundError when no Blocklist entities are found.
|
||||
func (bq *BlocklistQuery) Only(ctx context.Context) (*Blocklist, error) {
|
||||
nodes, err := bq.Limit(2).All(setContextOp(ctx, bq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{blocklist.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{blocklist.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (bq *BlocklistQuery) OnlyX(ctx context.Context) *Blocklist {
|
||||
node, err := bq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Blocklist ID in the query.
|
||||
// Returns a *NotSingularError when more than one Blocklist ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (bq *BlocklistQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = bq.Limit(2).IDs(setContextOp(ctx, bq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{blocklist.Label}
|
||||
default:
|
||||
err = &NotSingularError{blocklist.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (bq *BlocklistQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := bq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Blocklists.
|
||||
func (bq *BlocklistQuery) All(ctx context.Context) ([]*Blocklist, error) {
|
||||
ctx = setContextOp(ctx, bq.ctx, "All")
|
||||
if err := bq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Blocklist, *BlocklistQuery]()
|
||||
return withInterceptors[[]*Blocklist](ctx, bq, qr, bq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (bq *BlocklistQuery) AllX(ctx context.Context) []*Blocklist {
|
||||
nodes, err := bq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Blocklist IDs.
|
||||
func (bq *BlocklistQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if bq.ctx.Unique == nil && bq.path != nil {
|
||||
bq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, bq.ctx, "IDs")
|
||||
if err = bq.Select(blocklist.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (bq *BlocklistQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := bq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (bq *BlocklistQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, bq.ctx, "Count")
|
||||
if err := bq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, bq, querierCount[*BlocklistQuery](), bq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (bq *BlocklistQuery) CountX(ctx context.Context) int {
|
||||
count, err := bq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (bq *BlocklistQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, bq.ctx, "Exist")
|
||||
switch _, err := bq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (bq *BlocklistQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := bq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the BlocklistQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (bq *BlocklistQuery) Clone() *BlocklistQuery {
|
||||
if bq == nil {
|
||||
return nil
|
||||
}
|
||||
return &BlocklistQuery{
|
||||
config: bq.config,
|
||||
ctx: bq.ctx.Clone(),
|
||||
order: append([]blocklist.OrderOption{}, bq.order...),
|
||||
inters: append([]Interceptor{}, bq.inters...),
|
||||
predicates: append([]predicate.Blocklist{}, bq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: bq.sql.Clone(),
|
||||
path: bq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Type blocklist.Type `json:"type,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Blocklist.Query().
|
||||
// GroupBy(blocklist.FieldType).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (bq *BlocklistQuery) GroupBy(field string, fields ...string) *BlocklistGroupBy {
|
||||
bq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &BlocklistGroupBy{build: bq}
|
||||
grbuild.flds = &bq.ctx.Fields
|
||||
grbuild.label = blocklist.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Type blocklist.Type `json:"type,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Blocklist.Query().
|
||||
// Select(blocklist.FieldType).
|
||||
// Scan(ctx, &v)
|
||||
func (bq *BlocklistQuery) Select(fields ...string) *BlocklistSelect {
|
||||
bq.ctx.Fields = append(bq.ctx.Fields, fields...)
|
||||
sbuild := &BlocklistSelect{BlocklistQuery: bq}
|
||||
sbuild.label = blocklist.Label
|
||||
sbuild.flds, sbuild.scan = &bq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a BlocklistSelect configured with the given aggregations.
|
||||
func (bq *BlocklistQuery) Aggregate(fns ...AggregateFunc) *BlocklistSelect {
|
||||
return bq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (bq *BlocklistQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range bq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, bq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range bq.ctx.Fields {
|
||||
if !blocklist.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if bq.path != nil {
|
||||
prev, err := bq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (bq *BlocklistQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Blocklist, error) {
|
||||
var (
|
||||
nodes = []*Blocklist{}
|
||||
_spec = bq.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Blocklist).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Blocklist{config: bq.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, bq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (bq *BlocklistQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := bq.querySpec()
|
||||
_spec.Node.Columns = bq.ctx.Fields
|
||||
if len(bq.ctx.Fields) > 0 {
|
||||
_spec.Unique = bq.ctx.Unique != nil && *bq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, bq.driver, _spec)
|
||||
}
|
||||
|
||||
func (bq *BlocklistQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(blocklist.Table, blocklist.Columns, sqlgraph.NewFieldSpec(blocklist.FieldID, field.TypeInt))
|
||||
_spec.From = bq.sql
|
||||
if unique := bq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if bq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := bq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, blocklist.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != blocklist.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := bq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := bq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := bq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := bq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (bq *BlocklistQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(bq.driver.Dialect())
|
||||
t1 := builder.Table(blocklist.Table)
|
||||
columns := bq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = blocklist.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if bq.sql != nil {
|
||||
selector = bq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if bq.ctx.Unique != nil && *bq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range bq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range bq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := bq.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := bq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// BlocklistGroupBy is the group-by builder for Blocklist entities.
|
||||
type BlocklistGroupBy struct {
|
||||
selector
|
||||
build *BlocklistQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (bgb *BlocklistGroupBy) Aggregate(fns ...AggregateFunc) *BlocklistGroupBy {
|
||||
bgb.fns = append(bgb.fns, fns...)
|
||||
return bgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (bgb *BlocklistGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, bgb.build.ctx, "GroupBy")
|
||||
if err := bgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*BlocklistQuery, *BlocklistGroupBy](ctx, bgb.build, bgb, bgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (bgb *BlocklistGroupBy) sqlScan(ctx context.Context, root *BlocklistQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(bgb.fns))
|
||||
for _, fn := range bgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*bgb.flds)+len(bgb.fns))
|
||||
for _, f := range *bgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*bgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := bgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// BlocklistSelect is the builder for selecting fields of Blocklist entities.
|
||||
type BlocklistSelect struct {
|
||||
*BlocklistQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (bs *BlocklistSelect) Aggregate(fns ...AggregateFunc) *BlocklistSelect {
|
||||
bs.fns = append(bs.fns, fns...)
|
||||
return bs
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (bs *BlocklistSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, bs.ctx, "Select")
|
||||
if err := bs.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*BlocklistQuery, *BlocklistSelect](ctx, bs.BlocklistQuery, bs, bs.inters, v)
|
||||
}
|
||||
|
||||
func (bs *BlocklistSelect) sqlScan(ctx context.Context, root *BlocklistQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(bs.fns))
|
||||
for _, fn := range bs.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*bs.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := bs.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
269
ent/blocklist_update.go
Normal file
269
ent/blocklist_update.go
Normal file
@@ -0,0 +1,269 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/blocklist"
|
||||
"polaris/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// BlocklistUpdate is the builder for updating Blocklist entities.
|
||||
type BlocklistUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *BlocklistMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the BlocklistUpdate builder.
|
||||
func (bu *BlocklistUpdate) Where(ps ...predicate.Blocklist) *BlocklistUpdate {
|
||||
bu.mutation.Where(ps...)
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (bu *BlocklistUpdate) SetType(b blocklist.Type) *BlocklistUpdate {
|
||||
bu.mutation.SetType(b)
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (bu *BlocklistUpdate) SetNillableType(b *blocklist.Type) *BlocklistUpdate {
|
||||
if b != nil {
|
||||
bu.SetType(*b)
|
||||
}
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (bu *BlocklistUpdate) SetValue(s string) *BlocklistUpdate {
|
||||
bu.mutation.SetValue(s)
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetNillableValue sets the "value" field if the given value is not nil.
|
||||
func (bu *BlocklistUpdate) SetNillableValue(s *string) *BlocklistUpdate {
|
||||
if s != nil {
|
||||
bu.SetValue(*s)
|
||||
}
|
||||
return bu
|
||||
}
|
||||
|
||||
// Mutation returns the BlocklistMutation object of the builder.
|
||||
func (bu *BlocklistUpdate) Mutation() *BlocklistMutation {
|
||||
return bu.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (bu *BlocklistUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, bu.sqlSave, bu.mutation, bu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (bu *BlocklistUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := bu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (bu *BlocklistUpdate) Exec(ctx context.Context) error {
|
||||
_, err := bu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (bu *BlocklistUpdate) ExecX(ctx context.Context) {
|
||||
if err := bu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (bu *BlocklistUpdate) check() error {
|
||||
if v, ok := bu.mutation.GetType(); ok {
|
||||
if err := blocklist.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Blocklist.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (bu *BlocklistUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := bu.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(blocklist.Table, blocklist.Columns, sqlgraph.NewFieldSpec(blocklist.FieldID, field.TypeInt))
|
||||
if ps := bu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := bu.mutation.GetType(); ok {
|
||||
_spec.SetField(blocklist.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := bu.mutation.Value(); ok {
|
||||
_spec.SetField(blocklist.FieldValue, field.TypeString, value)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, bu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{blocklist.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
bu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// BlocklistUpdateOne is the builder for updating a single Blocklist entity.
|
||||
type BlocklistUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *BlocklistMutation
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (buo *BlocklistUpdateOne) SetType(b blocklist.Type) *BlocklistUpdateOne {
|
||||
buo.mutation.SetType(b)
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (buo *BlocklistUpdateOne) SetNillableType(b *blocklist.Type) *BlocklistUpdateOne {
|
||||
if b != nil {
|
||||
buo.SetType(*b)
|
||||
}
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (buo *BlocklistUpdateOne) SetValue(s string) *BlocklistUpdateOne {
|
||||
buo.mutation.SetValue(s)
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetNillableValue sets the "value" field if the given value is not nil.
|
||||
func (buo *BlocklistUpdateOne) SetNillableValue(s *string) *BlocklistUpdateOne {
|
||||
if s != nil {
|
||||
buo.SetValue(*s)
|
||||
}
|
||||
return buo
|
||||
}
|
||||
|
||||
// Mutation returns the BlocklistMutation object of the builder.
|
||||
func (buo *BlocklistUpdateOne) Mutation() *BlocklistMutation {
|
||||
return buo.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the BlocklistUpdate builder.
|
||||
func (buo *BlocklistUpdateOne) Where(ps ...predicate.Blocklist) *BlocklistUpdateOne {
|
||||
buo.mutation.Where(ps...)
|
||||
return buo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (buo *BlocklistUpdateOne) Select(field string, fields ...string) *BlocklistUpdateOne {
|
||||
buo.fields = append([]string{field}, fields...)
|
||||
return buo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Blocklist entity.
|
||||
func (buo *BlocklistUpdateOne) Save(ctx context.Context) (*Blocklist, error) {
|
||||
return withHooks(ctx, buo.sqlSave, buo.mutation, buo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (buo *BlocklistUpdateOne) SaveX(ctx context.Context) *Blocklist {
|
||||
node, err := buo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (buo *BlocklistUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := buo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (buo *BlocklistUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := buo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (buo *BlocklistUpdateOne) check() error {
|
||||
if v, ok := buo.mutation.GetType(); ok {
|
||||
if err := blocklist.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Blocklist.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (buo *BlocklistUpdateOne) sqlSave(ctx context.Context) (_node *Blocklist, err error) {
|
||||
if err := buo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(blocklist.Table, blocklist.Columns, sqlgraph.NewFieldSpec(blocklist.FieldID, field.TypeInt))
|
||||
id, ok := buo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Blocklist.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := buo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, blocklist.FieldID)
|
||||
for _, f := range fields {
|
||||
if !blocklist.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != blocklist.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := buo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := buo.mutation.GetType(); ok {
|
||||
_spec.SetField(blocklist.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := buo.mutation.Value(); ok {
|
||||
_spec.SetField(blocklist.FieldValue, field.TypeString, value)
|
||||
}
|
||||
_node = &Blocklist{config: buo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, buo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{blocklist.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
buo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
155
ent/client.go
155
ent/client.go
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"polaris/ent/migrate"
|
||||
|
||||
"polaris/ent/blocklist"
|
||||
"polaris/ent/downloadclients"
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/history"
|
||||
@@ -32,6 +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
|
||||
// DownloadClients is the client for interacting with the DownloadClients builders.
|
||||
DownloadClients *DownloadClientsClient
|
||||
// Episode is the client for interacting with the Episode builders.
|
||||
@@ -61,6 +64,7 @@ func NewClient(opts ...Option) *Client {
|
||||
|
||||
func (c *Client) init() {
|
||||
c.Schema = migrate.NewSchema(c.driver)
|
||||
c.Blocklist = NewBlocklistClient(c.config)
|
||||
c.DownloadClients = NewDownloadClientsClient(c.config)
|
||||
c.Episode = NewEpisodeClient(c.config)
|
||||
c.History = NewHistoryClient(c.config)
|
||||
@@ -162,6 +166,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Blocklist: NewBlocklistClient(cfg),
|
||||
DownloadClients: NewDownloadClientsClient(cfg),
|
||||
Episode: NewEpisodeClient(cfg),
|
||||
History: NewHistoryClient(cfg),
|
||||
@@ -190,6 +195,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Blocklist: NewBlocklistClient(cfg),
|
||||
DownloadClients: NewDownloadClientsClient(cfg),
|
||||
Episode: NewEpisodeClient(cfg),
|
||||
History: NewHistoryClient(cfg),
|
||||
@@ -205,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().
|
||||
// DownloadClients.
|
||||
// Blocklist.
|
||||
// Query().
|
||||
// Count(ctx)
|
||||
func (c *Client) Debug() *Client {
|
||||
@@ -228,8 +234,8 @@ 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.DownloadClients, c.Episode, c.History, c.ImportList, c.Indexers, c.Media,
|
||||
c.NotificationClient, c.Settings, c.Storage,
|
||||
c.Blocklist, c.DownloadClients, c.Episode, c.History, c.ImportList, c.Indexers,
|
||||
c.Media, c.NotificationClient, c.Settings, c.Storage,
|
||||
} {
|
||||
n.Use(hooks...)
|
||||
}
|
||||
@@ -239,8 +245,8 @@ 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.DownloadClients, c.Episode, c.History, c.ImportList, c.Indexers, c.Media,
|
||||
c.NotificationClient, c.Settings, c.Storage,
|
||||
c.Blocklist, c.DownloadClients, c.Episode, c.History, c.ImportList, c.Indexers,
|
||||
c.Media, c.NotificationClient, c.Settings, c.Storage,
|
||||
} {
|
||||
n.Intercept(interceptors...)
|
||||
}
|
||||
@@ -249,6 +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 *DownloadClientsMutation:
|
||||
return c.DownloadClients.mutate(ctx, m)
|
||||
case *EpisodeMutation:
|
||||
@@ -272,6 +280,139 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// BlocklistClient is a client for the Blocklist schema.
|
||||
type BlocklistClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewBlocklistClient returns a client for the Blocklist from the given config.
|
||||
func NewBlocklistClient(c config) *BlocklistClient {
|
||||
return &BlocklistClient{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...)
|
||||
}
|
||||
|
||||
// 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...)
|
||||
}
|
||||
|
||||
// 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}
|
||||
}
|
||||
|
||||
// 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}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
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)}
|
||||
}
|
||||
builders := make([]*BlocklistCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &BlocklistCreateBulk{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}
|
||||
}
|
||||
|
||||
// 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}
|
||||
}
|
||||
|
||||
// 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}
|
||||
}
|
||||
|
||||
// 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}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *BlocklistClient) DeleteOne(b *Blocklist) *BlocklistDeleteOne {
|
||||
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))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &BlocklistDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Blocklist.
|
||||
func (c *BlocklistClient) Query() *BlocklistQuery {
|
||||
return &BlocklistQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeBlocklist},
|
||||
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)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *BlocklistClient) GetX(ctx context.Context, id int) *Blocklist {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *BlocklistClient) Hooks() []Hook {
|
||||
return c.hooks.Blocklist
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *BlocklistClient) Interceptors() []Interceptor {
|
||||
return c.inters.Blocklist
|
||||
}
|
||||
|
||||
func (c *BlocklistClient) mutate(ctx context.Context, m *BlocklistMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&BlocklistCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&BlocklistUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&BlocklistUpdateOne{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)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown Blocklist mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// DownloadClientsClient is a client for the DownloadClients schema.
|
||||
type DownloadClientsClient struct {
|
||||
config
|
||||
@@ -1504,11 +1645,11 @@ func (c *StorageClient) mutate(ctx context.Context, m *StorageMutation) (Value,
|
||||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
DownloadClients, Episode, History, ImportList, Indexers, Media,
|
||||
Blocklist, DownloadClients, Episode, History, ImportList, Indexers, Media,
|
||||
NotificationClient, Settings, Storage []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
DownloadClients, Episode, History, ImportList, Indexers, Media,
|
||||
Blocklist, DownloadClients, Episode, History, ImportList, Indexers, Media,
|
||||
NotificationClient, Settings, Storage []ent.Interceptor
|
||||
}
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/blocklist"
|
||||
"polaris/ent/downloadclients"
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/history"
|
||||
@@ -81,6 +82,7 @@ var (
|
||||
func checkColumn(table, column string) error {
|
||||
initCheck.Do(func() {
|
||||
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||
blocklist.Table: blocklist.ValidColumn,
|
||||
downloadclients.Table: downloadclients.ValidColumn,
|
||||
episode.Table: episode.ValidColumn,
|
||||
history.Table: history.ValidColumn,
|
||||
|
||||
@@ -8,6 +8,18 @@ import (
|
||||
"polaris/ent"
|
||||
)
|
||||
|
||||
// The BlocklistFunc type is an adapter to allow the use of ordinary
|
||||
// function as Blocklist mutator.
|
||||
type BlocklistFunc func(context.Context, *ent.BlocklistMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f BlocklistFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.BlocklistMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.BlocklistMutation", m)
|
||||
}
|
||||
|
||||
// The DownloadClientsFunc type is an adapter to allow the use of ordinary
|
||||
// function as DownloadClients mutator.
|
||||
type DownloadClientsFunc func(context.Context, *ent.DownloadClientsMutation) (ent.Value, error)
|
||||
|
||||
@@ -8,6 +8,18 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// BlocklistsColumns holds the columns for the "blocklists" table.
|
||||
BlocklistsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "type", Type: field.TypeEnum, Enums: []string{"media", "torrent"}},
|
||||
{Name: "value", Type: field.TypeString},
|
||||
}
|
||||
// BlocklistsTable holds the schema information for the "blocklists" table.
|
||||
BlocklistsTable = &schema.Table{
|
||||
Name: "blocklists",
|
||||
Columns: BlocklistsColumns,
|
||||
PrimaryKey: []*schema.Column{BlocklistsColumns[0]},
|
||||
}
|
||||
// DownloadClientsColumns holds the columns for the "download_clients" table.
|
||||
DownloadClientsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
@@ -179,6 +191,7 @@ var (
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
BlocklistsTable,
|
||||
DownloadClientsTable,
|
||||
EpisodesTable,
|
||||
HistoriesTable,
|
||||
|
||||
382
ent/mutation.go
382
ent/mutation.go
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/blocklist"
|
||||
"polaris/ent/downloadclients"
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/history"
|
||||
@@ -33,6 +34,7 @@ const (
|
||||
OpUpdateOne = ent.OpUpdateOne
|
||||
|
||||
// Node types.
|
||||
TypeBlocklist = "Blocklist"
|
||||
TypeDownloadClients = "DownloadClients"
|
||||
TypeEpisode = "Episode"
|
||||
TypeHistory = "History"
|
||||
@@ -44,6 +46,386 @@ const (
|
||||
TypeStorage = "Storage"
|
||||
)
|
||||
|
||||
// BlocklistMutation represents an operation that mutates the Blocklist nodes in the graph.
|
||||
type BlocklistMutation struct {
|
||||
config
|
||||
op Op
|
||||
typ string
|
||||
id *int
|
||||
_type *blocklist.Type
|
||||
value *string
|
||||
clearedFields map[string]struct{}
|
||||
done bool
|
||||
oldValue func(context.Context) (*Blocklist, error)
|
||||
predicates []predicate.Blocklist
|
||||
}
|
||||
|
||||
var _ ent.Mutation = (*BlocklistMutation)(nil)
|
||||
|
||||
// blocklistOption allows management of the mutation configuration using functional options.
|
||||
type blocklistOption func(*BlocklistMutation)
|
||||
|
||||
// newBlocklistMutation creates new mutation for the Blocklist entity.
|
||||
func newBlocklistMutation(c config, op Op, opts ...blocklistOption) *BlocklistMutation {
|
||||
m := &BlocklistMutation{
|
||||
config: c,
|
||||
op: op,
|
||||
typ: TypeBlocklist,
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(m)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// withBlocklistID sets the ID field of the mutation.
|
||||
func withBlocklistID(id int) blocklistOption {
|
||||
return func(m *BlocklistMutation) {
|
||||
var (
|
||||
err error
|
||||
once sync.Once
|
||||
value *Blocklist
|
||||
)
|
||||
m.oldValue = func(ctx context.Context) (*Blocklist, error) {
|
||||
once.Do(func() {
|
||||
if m.done {
|
||||
err = errors.New("querying old values post mutation is not allowed")
|
||||
} else {
|
||||
value, err = m.Client().Blocklist.Get(ctx, id)
|
||||
}
|
||||
})
|
||||
return value, err
|
||||
}
|
||||
m.id = &id
|
||||
}
|
||||
}
|
||||
|
||||
// withBlocklist sets the old Blocklist of the mutation.
|
||||
func withBlocklist(node *Blocklist) blocklistOption {
|
||||
return func(m *BlocklistMutation) {
|
||||
m.oldValue = func(context.Context) (*Blocklist, error) {
|
||||
return node, nil
|
||||
}
|
||||
m.id = &node.ID
|
||||
}
|
||||
}
|
||||
|
||||
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
||||
// executed in a transaction (ent.Tx), a transactional client is returned.
|
||||
func (m BlocklistMutation) Client() *Client {
|
||||
client := &Client{config: m.config}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
||||
// it returns an error otherwise.
|
||||
func (m BlocklistMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// ID returns the ID value in the mutation. Note that the ID is only available
|
||||
// if it was provided to the builder or after it was returned from the database.
|
||||
func (m *BlocklistMutation) ID() (id int, exists bool) {
|
||||
if m.id == nil {
|
||||
return
|
||||
}
|
||||
return *m.id, true
|
||||
}
|
||||
|
||||
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
||||
// That means, if the mutation is applied within a transaction with an isolation level such
|
||||
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
||||
// or updated by the mutation.
|
||||
func (m *BlocklistMutation) IDs(ctx context.Context) ([]int, error) {
|
||||
switch {
|
||||
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []int{id}, nil
|
||||
}
|
||||
fallthrough
|
||||
case m.op.Is(OpUpdate | OpDelete):
|
||||
return m.Client().Blocklist.Query().Where(m.predicates...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||
}
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (m *BlocklistMutation) SetType(b blocklist.Type) {
|
||||
m._type = &b
|
||||
}
|
||||
|
||||
// GetType returns the value of the "type" field in the mutation.
|
||||
func (m *BlocklistMutation) GetType() (r blocklist.Type, exists bool) {
|
||||
v := m._type
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldType returns the old "type" field's value of the Blocklist entity.
|
||||
// If the Blocklist object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *BlocklistMutation) OldType(ctx context.Context) (v blocklist.Type, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldType is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldType requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldType: %w", err)
|
||||
}
|
||||
return oldValue.Type, nil
|
||||
}
|
||||
|
||||
// ResetType resets all changes to the "type" field.
|
||||
func (m *BlocklistMutation) ResetType() {
|
||||
m._type = nil
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (m *BlocklistMutation) SetValue(s string) {
|
||||
m.value = &s
|
||||
}
|
||||
|
||||
// Value returns the value of the "value" field in the mutation.
|
||||
func (m *BlocklistMutation) Value() (r string, exists bool) {
|
||||
v := m.value
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldValue returns the old "value" field's value of the Blocklist entity.
|
||||
// If the Blocklist object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *BlocklistMutation) OldValue(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldValue is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldValue requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldValue: %w", err)
|
||||
}
|
||||
return oldValue.Value, nil
|
||||
}
|
||||
|
||||
// ResetValue resets all changes to the "value" field.
|
||||
func (m *BlocklistMutation) ResetValue() {
|
||||
m.value = nil
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the BlocklistMutation builder.
|
||||
func (m *BlocklistMutation) Where(ps ...predicate.Blocklist) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
}
|
||||
|
||||
// WhereP appends storage-level predicates to the BlocklistMutation builder. Using this method,
|
||||
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||
func (m *BlocklistMutation) WhereP(ps ...func(*sql.Selector)) {
|
||||
p := make([]predicate.Blocklist, len(ps))
|
||||
for i := range ps {
|
||||
p[i] = ps[i]
|
||||
}
|
||||
m.Where(p...)
|
||||
}
|
||||
|
||||
// Op returns the operation name.
|
||||
func (m *BlocklistMutation) Op() Op {
|
||||
return m.op
|
||||
}
|
||||
|
||||
// SetOp allows setting the mutation operation.
|
||||
func (m *BlocklistMutation) SetOp(op Op) {
|
||||
m.op = op
|
||||
}
|
||||
|
||||
// Type returns the node type of this mutation (Blocklist).
|
||||
func (m *BlocklistMutation) Type() string {
|
||||
return m.typ
|
||||
}
|
||||
|
||||
// Fields returns all fields that were changed during this mutation. Note that in
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *BlocklistMutation) Fields() []string {
|
||||
fields := make([]string, 0, 2)
|
||||
if m._type != nil {
|
||||
fields = append(fields, blocklist.FieldType)
|
||||
}
|
||||
if m.value != nil {
|
||||
fields = append(fields, blocklist.FieldValue)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// Field returns the value of a field with the given name. The second boolean
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *BlocklistMutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case blocklist.FieldType:
|
||||
return m.GetType()
|
||||
case blocklist.FieldValue:
|
||||
return m.Value()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *BlocklistMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
switch name {
|
||||
case blocklist.FieldType:
|
||||
return m.OldType(ctx)
|
||||
case blocklist.FieldValue:
|
||||
return m.OldValue(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown Blocklist field %s", name)
|
||||
}
|
||||
|
||||
// SetField sets the value of a field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *BlocklistMutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case blocklist.FieldType:
|
||||
v, ok := value.(blocklist.Type)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetType(v)
|
||||
return nil
|
||||
case blocklist.FieldValue:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetValue(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Blocklist field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *BlocklistMutation) AddedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||
// with the given name. The second boolean return value indicates that this field
|
||||
// was not set, or was not defined in the schema.
|
||||
func (m *BlocklistMutation) AddedField(name string) (ent.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// AddField adds the value to the field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *BlocklistMutation) AddField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
}
|
||||
return fmt.Errorf("unknown Blocklist numeric field %s", name)
|
||||
}
|
||||
|
||||
// ClearedFields returns all nullable fields that were cleared during this
|
||||
// mutation.
|
||||
func (m *BlocklistMutation) ClearedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||
// cleared in this mutation.
|
||||
func (m *BlocklistMutation) FieldCleared(name string) bool {
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value of the field with the given name. It returns an
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *BlocklistMutation) ClearField(name string) error {
|
||||
return fmt.Errorf("unknown Blocklist nullable field %s", name)
|
||||
}
|
||||
|
||||
// ResetField resets all changes in the mutation for the field with the given name.
|
||||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *BlocklistMutation) ResetField(name string) error {
|
||||
switch name {
|
||||
case blocklist.FieldType:
|
||||
m.ResetType()
|
||||
return nil
|
||||
case blocklist.FieldValue:
|
||||
m.ResetValue()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Blocklist field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *BlocklistMutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||
// name in this mutation.
|
||||
func (m *BlocklistMutation) AddedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *BlocklistMutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *BlocklistMutation) RemovedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *BlocklistMutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||
// was cleared in this mutation.
|
||||
func (m *BlocklistMutation) EdgeCleared(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||
// if that edge is not defined in the schema.
|
||||
func (m *BlocklistMutation) ClearEdge(name string) error {
|
||||
return fmt.Errorf("unknown Blocklist unique edge %s", name)
|
||||
}
|
||||
|
||||
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *BlocklistMutation) ResetEdge(name string) error {
|
||||
return fmt.Errorf("unknown Blocklist edge %s", name)
|
||||
}
|
||||
|
||||
// DownloadClientsMutation represents an operation that mutates the DownloadClients nodes in the graph.
|
||||
type DownloadClientsMutation struct {
|
||||
config
|
||||
|
||||
@@ -6,6 +6,9 @@ import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Blocklist is the predicate function for blocklist builders.
|
||||
type Blocklist func(*sql.Selector)
|
||||
|
||||
// DownloadClients is the predicate function for downloadclients builders.
|
||||
type DownloadClients func(*sql.Selector)
|
||||
|
||||
|
||||
24
ent/schema/blocklist.go
Normal file
24
ent/schema/blocklist.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Blocklist holds the schema definition for the Blocklist entity.
|
||||
type Blocklist struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Blocklist.
|
||||
func (Blocklist) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Enum("type").Values("media", "torrent"),
|
||||
field.String("value"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Blocklist.
|
||||
func (Blocklist) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
@@ -12,6 +12,8 @@ import (
|
||||
// Tx is a transactional client that is created by calling Client.Tx().
|
||||
type Tx struct {
|
||||
config
|
||||
// Blocklist is the client for interacting with the Blocklist builders.
|
||||
Blocklist *BlocklistClient
|
||||
// DownloadClients is the client for interacting with the DownloadClients builders.
|
||||
DownloadClients *DownloadClientsClient
|
||||
// Episode is the client for interacting with the Episode builders.
|
||||
@@ -161,6 +163,7 @@ func (tx *Tx) Client() *Client {
|
||||
}
|
||||
|
||||
func (tx *Tx) init() {
|
||||
tx.Blocklist = NewBlocklistClient(tx.config)
|
||||
tx.DownloadClients = NewDownloadClientsClient(tx.config)
|
||||
tx.Episode = NewEpisodeClient(tx.config)
|
||||
tx.History = NewHistoryClient(tx.config)
|
||||
@@ -179,7 +182,7 @@ func (tx *Tx) init() {
|
||||
// of them in order to commit or rollback the transaction.
|
||||
//
|
||||
// If a closed transaction is embedded in one of the generated entities, and the entity
|
||||
// applies a query, for example: DownloadClients.QueryXXX(), the query will be executed
|
||||
// applies a query, for example: Blocklist.QueryXXX(), the query will be executed
|
||||
// through the driver which created this transaction.
|
||||
//
|
||||
// Note that txDriver is not goroutine safe.
|
||||
|
||||
17
go.mod
17
go.mod
@@ -5,30 +5,35 @@ go 1.22.4
|
||||
require (
|
||||
entgo.io/ent v0.13.1
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1
|
||||
github.com/mattn/go-sqlite3 v1.14.16
|
||||
github.com/mattn/go-sqlite3 v1.14.22 // indirect
|
||||
github.com/robfig/cron v1.2.0
|
||||
go.uber.org/zap v1.27.0
|
||||
golang.org/x/net v0.27.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/PuerkitoBio/goquery v1.9.2
|
||||
github.com/gin-contrib/zap v1.1.3
|
||||
github.com/ncruces/go-sqlite3 v0.18.4
|
||||
github.com/nikoksr/notify v1.0.0
|
||||
github.com/stretchr/testify v1.9.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.4.0 // indirect
|
||||
github.com/PuerkitoBio/goquery v1.9.2 // indirect
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.2 // indirect
|
||||
github.com/andybalholm/cascadia v1.3.2 // indirect
|
||||
github.com/blinkbean/dingtalk v1.1.3 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect
|
||||
github.com/go-test/deep v1.0.4 // indirect
|
||||
github.com/gregdel/pushover v1.3.1 // indirect
|
||||
github.com/ncruces/julianday v1.0.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/stretchr/objx v0.5.2 // indirect
|
||||
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
|
||||
golang.org/x/sync v0.7.0 // indirect
|
||||
github.com/tetratelabs/wazero v1.8.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
@@ -75,11 +80,11 @@ require (
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
github.com/zclconf/go-cty v1.8.0 // indirect
|
||||
golang.org/x/arch v0.8.0 // indirect
|
||||
golang.org/x/crypto v0.25.0
|
||||
golang.org/x/crypto v0.27.0
|
||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
|
||||
golang.org/x/mod v0.19.0 // indirect
|
||||
golang.org/x/sys v0.22.0
|
||||
golang.org/x/text v0.16.0 // indirect
|
||||
golang.org/x/sys v0.25.0
|
||||
golang.org/x/text v0.18.0 // indirect
|
||||
google.golang.org/protobuf v1.34.2 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
||||
43
go.sum
43
go.sum
@@ -4,8 +4,8 @@ entgo.io/ent v0.13.1 h1:uD8QwN1h6SNphdCCzmkMN3feSUzNnVvV/WIkHKMbzOE=
|
||||
entgo.io/ent v0.13.1/go.mod h1:qCEmo+biw3ccBn9OyL4ZK5dfpwg++l1Gxwac5B1206A=
|
||||
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
|
||||
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
|
||||
github.com/PuerkitoBio/goquery v1.9.2 h1:4/wZksC3KgkQw7SQgkKotmKljk0M6V8TUvA8Wb4yPeE=
|
||||
github.com/PuerkitoBio/goquery v1.9.2/go.mod h1:GHPCaP0ODyyxqcNoFGYlAprUFH81NuRPd0GX3Zu2Mvk=
|
||||
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
|
||||
@@ -56,8 +56,8 @@ github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBEx
|
||||
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
||||
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaELYAEARXRkq2LrJ0yDDv1rW7+wrTEdVL3uaU=
|
||||
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM=
|
||||
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
|
||||
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
|
||||
github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho=
|
||||
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
|
||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
|
||||
@@ -86,6 +86,7 @@ github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
|
||||
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
|
||||
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||
@@ -105,10 +106,8 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V
|
||||
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
|
||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
@@ -120,10 +119,12 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk=
|
||||
github.com/ncruces/go-sqlite3 v0.18.4 h1:Je8o3y33MDwPYY/Cacas8yCsuoUzpNY/AgoSlN2ekyE=
|
||||
github.com/ncruces/go-sqlite3 v0.18.4/go.mod h1:4HLag13gq1k10s4dfGBhMfRVsssJRT9/5hYqVM9RUYo=
|
||||
github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt7M=
|
||||
github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g=
|
||||
github.com/nikoksr/notify v1.0.0 h1:qe9/6FRsWdxBgQgWcpvQ0sv8LRGJZDpRB4TkL2uNdO8=
|
||||
github.com/nikoksr/notify v1.0.0/go.mod h1:hPaaDt30d6LAA7/5nb0e48Bp/MctDfycCSs8VEgN29I=
|
||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
@@ -147,8 +148,6 @@ github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
|
||||
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
|
||||
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
|
||||
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
|
||||
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
|
||||
@@ -170,6 +169,8 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8
|
||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||
github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM=
|
||||
github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog=
|
||||
github.com/tetratelabs/wazero v1.8.0 h1:iEKu0d4c2Pd+QSRieYbnQC9yiFlMS9D+Jr0LsRmcF4g=
|
||||
github.com/tetratelabs/wazero v1.8.0/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
|
||||
@@ -190,8 +191,8 @@ golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
|
||||
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
|
||||
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
|
||||
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
|
||||
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
|
||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
|
||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
@@ -210,8 +211,8 @@ golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
@@ -220,8 +221,8 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
||||
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
|
||||
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
@@ -233,14 +234,12 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
|
||||
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
|
||||
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package pkg
|
||||
|
||||
type Torrent interface {
|
||||
Name() string
|
||||
Progress() int
|
||||
Name() (string, error)
|
||||
Progress() (int, error)
|
||||
Stop() error
|
||||
Start() error
|
||||
Remove() error
|
||||
Save() string
|
||||
Exists() bool
|
||||
SeedRatio() *float64
|
||||
SeedRatio() (float64, error)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ func ParseDoulist(doulistUrl string) (*importlist.Response, error) {
|
||||
continue
|
||||
} else {
|
||||
n := ppp[1]
|
||||
n1, err := strconv.Atoi(n)
|
||||
n1, err := strconv.Atoi(strings.TrimSpace(n))
|
||||
if err != nil {
|
||||
log.Errorf("convert year number %s to int error: %v", n, err)
|
||||
continue
|
||||
|
||||
@@ -2,6 +2,7 @@ package metadata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"polaris/log"
|
||||
"polaris/pkg/utils"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -170,7 +171,7 @@ func parseChineseName(name string) *Metadata {
|
||||
}
|
||||
|
||||
//episode number
|
||||
re1 := regexp.MustCompile(`\[\d{1,2}\]`)
|
||||
re1 := regexp.MustCompile(`\[\d{1,3}\]`)
|
||||
episodeMatches1 := re1.FindAllString(name, -1)
|
||||
if len(episodeMatches1) > 0 { //[11] [1080p]
|
||||
epNum := strings.TrimRight(strings.TrimLeft(episodeMatches1[0], "["), "]")
|
||||
@@ -228,12 +229,17 @@ func parseChineseName(name string) *Metadata {
|
||||
}
|
||||
meta.Season = n
|
||||
} else {
|
||||
seasonRe1 := regexp.MustCompile(`第.{1}季`)
|
||||
seasonRe1 := regexp.MustCompile(`第.{1,2}季`)
|
||||
seasonMatches := seasonRe1.FindAllString(name, -1)
|
||||
if len(seasonMatches) > 0 {
|
||||
se := []rune(seasonMatches[0])
|
||||
seNum := se[1]
|
||||
meta.Season = chinese2Num[string(seNum)]
|
||||
m1 := []rune(seasonMatches[0])
|
||||
seNum := m1[1 : len(m1)-1]
|
||||
n, err := strconv.Atoi(string(seNum))
|
||||
if err != nil {
|
||||
log.Warnf("parse season number %v error: %v, try to parse using chinese", seNum, err)
|
||||
n = chinese2Num[string(seNum)]
|
||||
}
|
||||
meta.Season = n
|
||||
|
||||
}
|
||||
}
|
||||
@@ -245,24 +251,29 @@ func parseChineseName(name string) *Metadata {
|
||||
}
|
||||
|
||||
//tv name
|
||||
title := name
|
||||
|
||||
fields := strings.FieldsFunc(title, func(r rune) bool {
|
||||
fields := strings.FieldsFunc(name, func(r rune) bool {
|
||||
return r == '[' || r == ']' || r == '【' || r == '】'
|
||||
})
|
||||
title = ""
|
||||
titleCn := ""
|
||||
title := ""
|
||||
for _, p := range fields { //寻找匹配的最长的字符串,最有可能是名字
|
||||
if len([]rune(p)) > len([]rune(title)) {
|
||||
if utils.ContainsChineseChar(p) && len([]rune(p)) > len([]rune(titleCn)) { //最长含中文字符串
|
||||
titleCn = p
|
||||
}
|
||||
if len([]rune(p)) > len([]rune(title)) { //最长字符串
|
||||
title = p
|
||||
}
|
||||
}
|
||||
re := regexp.MustCompile(`[^\p{L}\w\s]`)
|
||||
title = re.ReplaceAllString(strings.TrimSpace(strings.ToLower(title)), "")
|
||||
title = re.ReplaceAllString(strings.TrimSpace(strings.ToLower(title)), "") //去除标点符号
|
||||
titleCn = re.ReplaceAllString(strings.TrimSpace(strings.ToLower(titleCn)), "")
|
||||
|
||||
meta.NameCn = title
|
||||
meta.NameCn = titleCn
|
||||
cnRe := regexp.MustCompile(`\p{Han}.*\p{Han}`)
|
||||
cnmatches := cnRe.FindAllString(title, -1)
|
||||
cnmatches := cnRe.FindAllString(titleCn, -1)
|
||||
|
||||
//titleCn中最长的中文字符
|
||||
if len(cnmatches) > 0 {
|
||||
for _, t := range cnmatches {
|
||||
if len([]rune(t)) > len([]rune(meta.NameCn)) {
|
||||
@@ -271,12 +282,13 @@ func parseChineseName(name string) *Metadata {
|
||||
}
|
||||
}
|
||||
|
||||
//匹配title中最长拉丁字符串
|
||||
enRe := regexp.MustCompile(`[[:ascii:]]*`)
|
||||
enM := enRe.FindAllString(title, -1)
|
||||
if len(enM) > 0 {
|
||||
for _, t := range enM {
|
||||
if len(t) > len(meta.NameEn) {
|
||||
meta.NameEn = strings.ToLower(t)
|
||||
meta.NameEn = strings.TrimSpace(strings.ToLower(t))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,11 +137,11 @@ func Test_ParseTV13(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_ParseTV14(t *testing.T) {
|
||||
s1 := ""
|
||||
s1 := "[GM-Team][国漫][斗破苍穹 第5季][Fights Break Sphere Ⅴ][2022][113][HEVC][GB][4K]"
|
||||
m := ParseTv(s1)
|
||||
log.Infof("results: %+v", m)
|
||||
assert.Equal(t, 2, m.Season)
|
||||
assert.Equal(t, 01, m.Episode)
|
||||
assert.Equal(t, 5, m.Season)
|
||||
assert.Equal(t, 113, m.Episode)
|
||||
assert.Equal(t, false, m.IsSeasonPack)
|
||||
assert.Equal(t, "720p", m.Resolution)
|
||||
}
|
||||
//assert.Equal(t, "720p", m.Resolution)
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func (c *Client) GetAll() ([]*Torrent, error) {
|
||||
var torrents []*Torrent
|
||||
for _, t := range all {
|
||||
torrents = append(torrents, &Torrent{
|
||||
ID: *t.ID,
|
||||
Hash: *t.HashString,
|
||||
c: c.c,
|
||||
Config: c.cfg,
|
||||
})
|
||||
@@ -86,12 +86,12 @@ func (c *Client) Download(link, dir string) (*Torrent, error) {
|
||||
DownloadDir: &dir,
|
||||
})
|
||||
log.Infof("get torrent info: %+v", t)
|
||||
if t.ID == nil {
|
||||
if t.HashString == nil {
|
||||
return nil, fmt.Errorf("download torrent error: %v", link)
|
||||
}
|
||||
|
||||
return &Torrent{
|
||||
ID: *t.ID,
|
||||
Hash: *t.HashString,
|
||||
c: c.c,
|
||||
Config: c.cfg,
|
||||
}, err
|
||||
@@ -100,7 +100,7 @@ func (c *Client) Download(link, dir string) (*Torrent, error) {
|
||||
type Torrent struct {
|
||||
//t *transmissionrpc.Torrent
|
||||
c *transmissionrpc.Client
|
||||
ID int64 `json:"id"`
|
||||
Hash string `json:"hash"`
|
||||
Config
|
||||
}
|
||||
|
||||
@@ -113,68 +113,92 @@ func (t *Torrent) reloadClient() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Torrent) getTorrent() transmissionrpc.Torrent {
|
||||
r, err := t.c.TorrentGetAllFor(context.TODO(), []int64{t.ID})
|
||||
func (t *Torrent) getTorrent() (transmissionrpc.Torrent, error) {
|
||||
r, err := t.c.TorrentGetAllForHashes(context.TODO(), []string{t.Hash})
|
||||
if err != nil {
|
||||
log.Errorf("get torrent info for error: %v", err)
|
||||
}
|
||||
return r[0]
|
||||
if len(r) == 0 {
|
||||
return transmissionrpc.Torrent{}, fmt.Errorf("no torrent")
|
||||
}
|
||||
return r[0], nil
|
||||
}
|
||||
|
||||
func (t *Torrent) Exists() bool {
|
||||
r, err := t.c.TorrentGetAllFor(context.TODO(), []int64{t.ID})
|
||||
r, err := t.c.TorrentGetAllForHashes(context.TODO(), []string{t.Hash})
|
||||
if err != nil {
|
||||
log.Errorf("get torrent info for error: %v", err)
|
||||
}
|
||||
return len(r) > 0
|
||||
}
|
||||
|
||||
func (t *Torrent) Name() string {
|
||||
if !t.Exists() {
|
||||
return ""
|
||||
|
||||
func (t *Torrent) Name() (string, error) {
|
||||
tt, err := t.getTorrent()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return *t.getTorrent().Name
|
||||
return *tt.Name, nil
|
||||
}
|
||||
|
||||
func (t *Torrent) Progress() int {
|
||||
if t.getTorrent().IsFinished != nil && *t.getTorrent().IsFinished {
|
||||
return 100
|
||||
func (t *Torrent) Progress() (int, error) {
|
||||
tt, err := t.getTorrent()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if t.getTorrent().PercentComplete != nil && *t.getTorrent().PercentComplete >= 1 {
|
||||
return 100
|
||||
if tt.IsFinished != nil && *tt.IsFinished {
|
||||
return 100, nil
|
||||
}
|
||||
if tt.PercentComplete != nil && *tt.PercentComplete >= 1 {
|
||||
return 100, nil
|
||||
}
|
||||
|
||||
if t.getTorrent().PercentComplete != nil {
|
||||
p := int(*t.getTorrent().PercentComplete * 100)
|
||||
if tt.PercentComplete != nil {
|
||||
p := int(*tt.PercentComplete * 100)
|
||||
if p == 100 {
|
||||
p = 99
|
||||
}
|
||||
return p
|
||||
return p, nil
|
||||
}
|
||||
return 0
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (t *Torrent) Stop() error {
|
||||
return t.c.TorrentStopIDs(context.TODO(), []int64{t.ID})
|
||||
return t.c.TorrentStopHashes(context.TODO(), []string{t.Hash})
|
||||
}
|
||||
|
||||
func (t *Torrent) SeedRatio() *float64 {
|
||||
return t.getTorrent().UploadRatio
|
||||
func (t *Torrent) SeedRatio() (float64, error) {
|
||||
tt, err := t.getTorrent()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if tt.UploadRatio == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return *tt.UploadRatio, nil
|
||||
}
|
||||
|
||||
func (t *Torrent) Start() error {
|
||||
return t.c.TorrentStartIDs(context.TODO(), []int64{t.ID})
|
||||
return t.c.TorrentStartHashes(context.TODO(), []string{t.Hash})
|
||||
}
|
||||
|
||||
func (t *Torrent) Remove() error {
|
||||
tt, err := t.getTorrent()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get torrent")
|
||||
}
|
||||
return t.c.TorrentRemove(context.TODO(), transmissionrpc.TorrentRemovePayload{
|
||||
IDs: []int64{t.ID},
|
||||
IDs: []int64{*tt.ID},
|
||||
DeleteLocalData: true,
|
||||
})
|
||||
}
|
||||
|
||||
func (t *Torrent) Size() int {
|
||||
return int(t.getTorrent().TotalSize.Byte())
|
||||
func (t *Torrent) Size() (int, error) {
|
||||
tt, err := t.getTorrent()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "get torrent")
|
||||
}
|
||||
return int(tt.TotalSize.Byte()), nil
|
||||
}
|
||||
|
||||
func (t *Torrent) Save() string {
|
||||
|
||||
25
pkg/utils/linux.go
Normal file
25
pkg/utils/linux.go
Normal file
@@ -0,0 +1,25 @@
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/unix"
|
||||
"math"
|
||||
"runtime"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func AvailableSpace(dir string) uint64 {
|
||||
if runtime.GOOS != "linux" {
|
||||
return math.MaxUint64
|
||||
}
|
||||
var stat unix.Statfs_t
|
||||
|
||||
unix.Statfs(dir, &stat)
|
||||
return stat.Bavail * uint64(stat.Bsize)
|
||||
}
|
||||
|
||||
func MaxPermission() {
|
||||
syscall.Umask(0) //max permission 0777
|
||||
}
|
||||
16
pkg/utils/other.go
Normal file
16
pkg/utils/other.go
Normal file
@@ -0,0 +1,16 @@
|
||||
//go:build !linux
|
||||
// +build !linux
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
func AvailableSpace(dir string) uint64 {
|
||||
return math.MaxUint64
|
||||
}
|
||||
|
||||
func MaxPermission() {
|
||||
return
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
@@ -10,7 +13,6 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"golang.org/x/exp/rand"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func IsASCII(s string) bool {
|
||||
@@ -128,13 +130,6 @@ func SeasonId(seasonName string) (int, error) {
|
||||
return num, nil
|
||||
}
|
||||
|
||||
func AvailableSpace(dir string) uint64 {
|
||||
var stat unix.Statfs_t
|
||||
|
||||
unix.Statfs(dir, &stat)
|
||||
return stat.Bavail * uint64(stat.Bsize)
|
||||
}
|
||||
|
||||
func ChangeFileHash(name string) error {
|
||||
f, err := os.OpenFile(name, os.O_APPEND|os.O_WRONLY, 0655)
|
||||
if err != nil {
|
||||
@@ -147,3 +142,79 @@ func ChangeFileHash(name string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TrimFields(v interface{}) error {
|
||||
bytes, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var mapSI map[string]interface{}
|
||||
if err := json.Unmarshal(bytes, &mapSI); err != nil {
|
||||
return err
|
||||
}
|
||||
mapSI = trimMapStringInterface(mapSI).(map[string]interface{})
|
||||
bytes2, err := json.Marshal(mapSI)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := json.Unmarshal(bytes2, v); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func trimMapStringInterface(data interface{}) interface{} {
|
||||
if values, valid := data.([]interface{}); valid {
|
||||
for i := range values {
|
||||
data.([]interface{})[i] = trimMapStringInterface(values[i])
|
||||
}
|
||||
} else if values, valid := data.(map[string]interface{}); valid {
|
||||
for k, v := range values {
|
||||
data.(map[string]interface{})[k] = trimMapStringInterface(v)
|
||||
}
|
||||
} else if value, valid := data.(string); valid {
|
||||
data = strings.TrimSpace(value)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/39320371/how-start-web-server-to-open-page-in-browser-in-golang
|
||||
// openURL opens the specified URL in the default browser of the user.
|
||||
func OpenURL(url string) error {
|
||||
var cmd string
|
||||
var args []string
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
cmd = "cmd"
|
||||
args = []string{"/c", "start"}
|
||||
case "darwin":
|
||||
cmd = "open"
|
||||
args = []string{url}
|
||||
default: // "linux", "freebsd", "openbsd", "netbsd"
|
||||
// Check if running under WSL
|
||||
if isWSL() {
|
||||
// Use 'cmd.exe /c start' to open the URL in the default Windows browser
|
||||
cmd = "cmd.exe"
|
||||
args = []string{"/c", "start", url}
|
||||
} else {
|
||||
// Use xdg-open on native Linux environments
|
||||
cmd = "xdg-open"
|
||||
args = []string{url}
|
||||
}
|
||||
}
|
||||
if len(args) > 1 {
|
||||
// args[0] is used for 'start' command argument, to prevent issues with URLs starting with a quote
|
||||
args = append(args[:1], append([]string{""}, args[1:]...)...)
|
||||
}
|
||||
return exec.Command(cmd, args...).Start()
|
||||
}
|
||||
|
||||
// isWSL checks if the Go program is running inside Windows Subsystem for Linux
|
||||
func isWSL() bool {
|
||||
releaseData, err := exec.Command("uname", "-r").Output()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return strings.Contains(strings.ToLower(string(releaseData)), "microsoft")
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
type Activity struct {
|
||||
*ent.History
|
||||
Progress int `json:"progress"`
|
||||
SeedRatio float32 `json:"seed_ratio"`
|
||||
SeedRatio float64 `json:"seed_ratio"`
|
||||
}
|
||||
|
||||
func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) {
|
||||
@@ -30,8 +30,18 @@ func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) {
|
||||
}
|
||||
for id, task := range s.core.GetTasks() {
|
||||
if h.ID == id && task.Exists() {
|
||||
a.Progress = task.Progress()
|
||||
a.SeedRatio = float32(*task.SeedRatio())
|
||||
p, err := task.Progress()
|
||||
if err != nil {
|
||||
log.Warnf("get task progress error: %v", err)
|
||||
} else {
|
||||
a.Progress = p
|
||||
}
|
||||
r, err := task.SeedRatio()
|
||||
if err != nil {
|
||||
log.Warnf("get task seed ratio error: %v", err)
|
||||
} else {
|
||||
a.SeedRatio = r
|
||||
}
|
||||
}
|
||||
}
|
||||
activities = append(activities, a)
|
||||
@@ -68,9 +78,13 @@ func (s *Server) RemoveActivity(c *gin.Context) (interface{}, error) {
|
||||
if err := s.core.RemoveTaskAndTorrent(his.ID); err != nil {
|
||||
return nil, errors.Wrap(err, "remove torrent")
|
||||
}
|
||||
err = s.db.DeleteHistory(id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "db")
|
||||
}
|
||||
|
||||
if his.EpisodeID != 0 {
|
||||
if his.Status == history.StatusRunning || his.Status == history.StatusUploading {
|
||||
if !s.db.IsEpisodeDownloadingOrDownloaded(his.EpisodeID) {
|
||||
s.db.SetEpisodeStatus(his.EpisodeID, episode.StatusMissing)
|
||||
}
|
||||
|
||||
@@ -85,10 +99,6 @@ func (s *Server) RemoveActivity(c *gin.Context) (interface{}, error) {
|
||||
}
|
||||
}
|
||||
|
||||
err = s.db.DeleteHistory(id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "db")
|
||||
}
|
||||
log.Infof("history record successful deleted: %v", his.SourceTitle)
|
||||
return nil, nil
|
||||
}
|
||||
@@ -107,7 +117,7 @@ func (s *Server) GetMediaDownloadHistory(c *gin.Context) (interface{}, error) {
|
||||
|
||||
type TorrentInfo struct {
|
||||
Name string `json:"name"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
SeedRatio float32 `json:"seed_ratio"`
|
||||
Progress int `json:"progress"`
|
||||
}
|
||||
@@ -126,10 +136,12 @@ func (s *Server) GetAllTorrents(c *gin.Context) (interface{}, error) {
|
||||
if !t.Exists() {
|
||||
continue
|
||||
}
|
||||
name, _ := t.Name()
|
||||
p, _ := t.Progress()
|
||||
infos = append(infos, TorrentInfo{
|
||||
Name: t.Name(),
|
||||
ID: t.ID,
|
||||
Progress: t.Progress(),
|
||||
Name: name,
|
||||
ID: t.Hash,
|
||||
Progress: p,
|
||||
})
|
||||
}
|
||||
return infos, nil
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -16,7 +18,6 @@ import (
|
||||
"polaris/pkg/utils"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
tmdb "github.com/cyruzin/golang-tmdb"
|
||||
"github.com/pkg/errors"
|
||||
@@ -132,7 +133,16 @@ func (c *Client) AddTv2Watchlist(in AddWatchlistIn) (interface{}, error) {
|
||||
} else {
|
||||
detail = detailEn
|
||||
}
|
||||
log.Infof("find detail for tv id %d: %v", in.TmdbID, detail)
|
||||
log.Infof("find detail for tv id %d: %+v", in.TmdbID, detail)
|
||||
|
||||
lastSeason := 0
|
||||
for _, season := range detail.Seasons {
|
||||
if season.SeasonNumber > lastSeason && season.EpisodeCount > 0 { //如果最新一季已经有剧集信息,则以最新一季为准
|
||||
lastSeason = season.SeasonNumber
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("latest season is %v", lastSeason)
|
||||
|
||||
var epIds []int
|
||||
for _, season := range detail.Seasons {
|
||||
@@ -142,36 +152,41 @@ func (c *Client) AddTv2Watchlist(in AddWatchlistIn) (interface{}, error) {
|
||||
log.Errorf("get season detail (%s) error: %v", detail.Name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
shouldMonitor := seasonId >= lastSeason //监控最新的一季
|
||||
|
||||
for _, ep := range se.Episodes {
|
||||
shouldMonitor := false
|
||||
//如果设置下载往期剧集,则监控所有剧集。如果没有则监控未上映的剧集,考虑时差等问题留24h余量
|
||||
if in.DownloadHistoryEpisodes {
|
||||
shouldMonitor = true
|
||||
} else {
|
||||
t, err := time.Parse("2006-01-02", ep.AirDate)
|
||||
if err != nil {
|
||||
log.Error("air date not known, will monitor: %v", ep.AirDate)
|
||||
shouldMonitor = true
|
||||
|
||||
} else {
|
||||
if time.Since(t) < 24*time.Hour { //monitor episode air 24h before now
|
||||
shouldMonitor = true
|
||||
}
|
||||
}
|
||||
}
|
||||
// //如果设置下载往期剧集,则监控所有剧集。如果没有则监控未上映的剧集,考虑时差等问题留24h余量
|
||||
// if in.DownloadHistoryEpisodes {
|
||||
// shouldMonitor = true
|
||||
// } else {
|
||||
// t, err := time.Parse("2006-01-02", ep.AirDate)
|
||||
// if err != nil {
|
||||
// log.Error("air date not known, will monitor: %v", ep.AirDate)
|
||||
// shouldMonitor = true
|
||||
|
||||
epid, err := c.db.SaveEposideDetail(&ent.Episode{
|
||||
// } else {
|
||||
// if time.Since(t) < 24*time.Hour { //monitor episode air 24h before now
|
||||
// shouldMonitor = true
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
ep := ent.Episode{
|
||||
SeasonNumber: seasonId,
|
||||
EpisodeNumber: ep.EpisodeNumber,
|
||||
Title: ep.Name,
|
||||
Overview: ep.Overview,
|
||||
AirDate: ep.AirDate,
|
||||
Monitored: shouldMonitor,
|
||||
})
|
||||
}
|
||||
epid, err := c.db.SaveEposideDetail(&ep)
|
||||
if err != nil {
|
||||
log.Errorf("save episode info error: %v", err)
|
||||
continue
|
||||
}
|
||||
log.Debugf("success save episode %+v", ep)
|
||||
epIds = append(epIds, epid)
|
||||
}
|
||||
}
|
||||
@@ -361,27 +376,35 @@ func (c *Client) SuggestedMovieFolderName(tmdbId int) (string, error) {
|
||||
return javid, nil
|
||||
}
|
||||
}
|
||||
|
||||
//if name is already in english, no need to query again
|
||||
if !utils.IsASCII(name) && c.language == db.LanguageCN {
|
||||
info := db.NamingInfo{TmdbID: tmdbId}
|
||||
if utils.IsASCII(name) {
|
||||
info.NameEN = stripExtraCharacters(name)
|
||||
} else {
|
||||
info.NameCN = stripExtraCharacters(name)
|
||||
en, err := c.MustTMDB().GetMovieDetails(tmdbId, db.LanguageEN)
|
||||
if err != nil {
|
||||
log.Errorf("get en movie detail error: %v", err)
|
||||
log.Errorf("get en tv detail error: %v", err)
|
||||
} else {
|
||||
name = fmt.Sprintf("%s %s", name, en.Title)
|
||||
info.NameEN = stripExtraCharacters(en.Title)
|
||||
}
|
||||
}
|
||||
//remove extra characters
|
||||
re := regexp.MustCompile(`[^\p{L}\w\s]`)
|
||||
name = re.ReplaceAllString(name, " ")
|
||||
name = strings.Join(strings.Fields(name), " ")
|
||||
year := strings.Split(d1.ReleaseDate, "-")[0]
|
||||
if year != "" {
|
||||
name = fmt.Sprintf("%s (%s)", name, year)
|
||||
}
|
||||
info.Year = year
|
||||
movieNamingFormat := c.db.GetMovingNamingFormat()
|
||||
|
||||
log.Infof("tv series of tmdb id %v suggestting name is %v", tmdbId, name)
|
||||
return name, nil
|
||||
tmpl, err := template.New("test").Parse(movieNamingFormat)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "naming format")
|
||||
}
|
||||
buff := &bytes.Buffer{}
|
||||
err = tmpl.Execute(buff, info)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "tmpl exec")
|
||||
}
|
||||
res := strings.TrimSpace(buff.String())
|
||||
|
||||
log.Infof("tv series of tmdb id %v suggestting name is %v", tmdbId, res)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (c *Client) SuggestedSeriesFolderName(tmdbId int) (string, error) {
|
||||
@@ -393,24 +416,42 @@ func (c *Client) SuggestedSeriesFolderName(tmdbId int) (string, error) {
|
||||
|
||||
name := d.Name
|
||||
|
||||
//if name is already in english, no need to query again
|
||||
if !utils.IsASCII(name) && c.language == db.LanguageCN {
|
||||
info := db.NamingInfo{TmdbID: tmdbId}
|
||||
if utils.IsASCII(name) {
|
||||
info.NameEN = stripExtraCharacters(name)
|
||||
} else {
|
||||
info.NameCN = stripExtraCharacters(name)
|
||||
en, err := c.MustTMDB().GetTvDetails(tmdbId, db.LanguageEN)
|
||||
if err != nil {
|
||||
log.Errorf("get en tv detail error: %v", err)
|
||||
} else {
|
||||
name = fmt.Sprintf("%s %s", name, en.Name)
|
||||
if en.Name != name { //sometimes en name is in chinese
|
||||
info.NameEN = stripExtraCharacters(en.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
//remove extra characters
|
||||
re := regexp.MustCompile(`[^\p{L}\w\s]`)
|
||||
name = re.ReplaceAllString(strings.ToLower(name), " ")
|
||||
name = strings.Join(strings.Fields(name), " ")
|
||||
year := strings.Split(d.FirstAirDate, "-")[0]
|
||||
if year != "" {
|
||||
name = fmt.Sprintf("%s (%s)", name, year)
|
||||
}
|
||||
info.Year = year
|
||||
|
||||
log.Infof("tv series of tmdb id %v suggestting name is %v", tmdbId, name)
|
||||
return name, nil
|
||||
tvNamingFormat := c.db.GetTvNamingFormat()
|
||||
|
||||
tmpl, err := template.New("test").Parse(tvNamingFormat)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "naming format")
|
||||
}
|
||||
buff := &bytes.Buffer{}
|
||||
err = tmpl.Execute(buff, info)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "tmpl exec")
|
||||
}
|
||||
res := strings.TrimSpace(buff.String())
|
||||
|
||||
log.Infof("tv series of tmdb id %v suggestting name is %v", tmdbId, res)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func stripExtraCharacters(s string) string {
|
||||
re := regexp.MustCompile(`[^\p{L}\w\s]`)
|
||||
s = re.ReplaceAllString(s, " ")
|
||||
return strings.Join(strings.Fields(s), " ")
|
||||
}
|
||||
|
||||
@@ -257,7 +257,11 @@ func (c *Client) findEpisodeFilesPreMoving(historyId int) error {
|
||||
isSingleEpisode := his.EpisodeID > 0
|
||||
downloadDir := c.db.GetDownloadDir()
|
||||
task := c.tasks[historyId]
|
||||
target := filepath.Join(downloadDir, task.Name())
|
||||
name, err := task.Name()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
target := filepath.Join(downloadDir, name)
|
||||
fi, err := os.Stat(target)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "read dir %v", target)
|
||||
|
||||
@@ -63,24 +63,33 @@ func (c *Client) checkTasks() error {
|
||||
delete(c.tasks, id)
|
||||
continue
|
||||
}
|
||||
log.Infof("task (%s) percentage done: %d%%", t.Name(), t.Progress())
|
||||
if t.Progress() == 100 {
|
||||
name, err := t.Name()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get name")
|
||||
}
|
||||
|
||||
progress, err := t.Progress()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get progress")
|
||||
}
|
||||
log.Infof("task (%s) percentage done: %d%%", name, progress)
|
||||
if progress == 100 {
|
||||
|
||||
if r.Status == history.StatusSeeding {
|
||||
//task already success, check seed ratio
|
||||
torrent := c.tasks[id]
|
||||
ok := c.isSeedRatioLimitReached(r.IndexerID, torrent)
|
||||
ratio, ok := c.isSeedRatioLimitReached(r.IndexerID, torrent)
|
||||
if ok {
|
||||
log.Infof("torrent file seed ratio reached, remove: %v, current seed ratio: %v", torrent.Name(), *torrent.SeedRatio())
|
||||
log.Infof("torrent file seed ratio reached, remove: %v, current seed ratio: %v", name, ratio)
|
||||
torrent.Remove()
|
||||
delete(c.tasks, id)
|
||||
} else {
|
||||
log.Infof("torrent file still sedding: %v, current seed ratio: %v", torrent.Name(), *torrent.SeedRatio())
|
||||
log.Infof("torrent file still sedding: %v, current seed ratio: %v", name, ratio)
|
||||
}
|
||||
continue
|
||||
}
|
||||
log.Infof("task is done: %v", t.Name())
|
||||
c.sendMsg(fmt.Sprintf(message.DownloadComplete, t.Name()))
|
||||
log.Infof("task is done: %v", name)
|
||||
c.sendMsg(fmt.Sprintf(message.DownloadComplete, name))
|
||||
|
||||
go c.postTaskProcessing(id)
|
||||
}
|
||||
@@ -122,14 +131,19 @@ func (c *Client) moveCompletedTask(id int) (err1 error) {
|
||||
log.Errorf("get task download client error: %v, use default one", err)
|
||||
downloadclient = &ent.DownloadClients{RemoveCompletedDownloads: true, RemoveFailedDownloads: true}
|
||||
}
|
||||
torrentName := torrent.Name()
|
||||
torrentName, err := torrent.Name()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
|
||||
if err1 != nil {
|
||||
c.db.SetHistoryStatus(r.ID, history.StatusFail)
|
||||
if r.EpisodeID != 0 {
|
||||
c.db.SetEpisodeStatus(r.EpisodeID, episode.StatusMissing)
|
||||
if !c.db.IsEpisodeDownloadingOrDownloaded(r.EpisodeID) {
|
||||
c.db.SetEpisodeStatus(r.EpisodeID, episode.StatusMissing)
|
||||
}
|
||||
} else {
|
||||
c.db.SetSeasonAllEpisodeStatus(r.MediaID, seasonNum, episode.StatusMissing)
|
||||
}
|
||||
@@ -167,9 +181,9 @@ func (c *Client) moveCompletedTask(id int) (err1 error) {
|
||||
c.sendMsg(fmt.Sprintf(message.ProcessingComplete, torrentName))
|
||||
|
||||
//判断是否需要删除本地文件
|
||||
ok := c.isSeedRatioLimitReached(r.IndexerID, torrent)
|
||||
r1, ok := c.isSeedRatioLimitReached(r.IndexerID, torrent)
|
||||
if downloadclient.RemoveCompletedDownloads && ok {
|
||||
log.Debugf("download complete,remove torrent and files related, torrent: %v, seed ratio: %v", torrentName, *torrent.SeedRatio())
|
||||
log.Debugf("download complete,remove torrent and files related, torrent: %v, seed ratio: %v", torrentName, r1)
|
||||
c.db.SetHistoryStatus(r.ID, history.StatusSuccess)
|
||||
delete(c.tasks, r.ID)
|
||||
torrent.Remove()
|
||||
@@ -426,15 +440,15 @@ func (c *Client) checkSeiesNewSeason(media *ent.Media) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) isSeedRatioLimitReached(indexId int, t pkg.Torrent) bool {
|
||||
func (c *Client) isSeedRatioLimitReached(indexId int, t pkg.Torrent)(float64,bool) {
|
||||
indexer, err := c.db.GetIndexer(indexId)
|
||||
if err != nil {
|
||||
return true
|
||||
return 0, true
|
||||
}
|
||||
currentRatio := t.SeedRatio()
|
||||
if currentRatio == nil {
|
||||
log.Warnf("get current seed ratio error, current ratio is nil")
|
||||
return indexer.SeedRatio == 0
|
||||
currentRatio, err := t.SeedRatio()
|
||||
if err != nil {
|
||||
log.Warnf("get current seed ratio error: %v", err)
|
||||
return currentRatio, indexer.SeedRatio == 0
|
||||
}
|
||||
return *currentRatio >= float64(indexer.SeedRatio)
|
||||
return currentRatio, currentRatio >= float64(indexer.SeedRatio)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"polaris/ent"
|
||||
"polaris/ent/importlist"
|
||||
"polaris/pkg/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
@@ -28,6 +29,8 @@ func (s *Server) addImportlist(c *gin.Context) (interface{}, error) {
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
return nil, errors.Wrap(err, "json")
|
||||
}
|
||||
utils.TrimFields(&in)
|
||||
|
||||
st := s.db.GetStorage(in.StorageId)
|
||||
if st == nil {
|
||||
return nil, fmt.Errorf("storage id not exist: %v", in.StorageId)
|
||||
|
||||
@@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"polaris/ent"
|
||||
"polaris/pkg/utils"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -35,6 +36,7 @@ func (s *Server) AddNotificationClient(c *gin.Context) (interface{}, error) {
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
return nil, errors.Wrap(err, "json")
|
||||
}
|
||||
utils.TrimFields(&in)
|
||||
|
||||
err := s.db.AddNotificationClient(in.Name, in.Service, in.Settings, in.Enabled)
|
||||
if err != nil {
|
||||
|
||||
@@ -3,10 +3,12 @@ package server
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"polaris/db"
|
||||
"polaris/ent"
|
||||
"polaris/log"
|
||||
"polaris/pkg/transmission"
|
||||
"polaris/pkg/utils"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -22,6 +24,8 @@ type GeneralSettings struct {
|
||||
EnableNfo bool `json:"enable_nfo"`
|
||||
AllowQiangban bool `json:"allow_qiangban"`
|
||||
EnableAdultContent bool `json:"enable_adult_content"`
|
||||
TvNamingFormat string `json:"tv_naming_format"`
|
||||
MovieNamingFormat string `json:"movie_naming_format"`
|
||||
}
|
||||
|
||||
func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
|
||||
@@ -29,6 +33,8 @@ func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
return nil, errors.Wrap(err, "bind json")
|
||||
}
|
||||
utils.TrimFields(&in)
|
||||
|
||||
log.Infof("set setting input: %+v", in)
|
||||
if in.TmdbApiKey != "" {
|
||||
if err := s.db.SetSetting(db.SettingTmdbApiKey, in.TmdbApiKey); err != nil {
|
||||
@@ -46,7 +52,25 @@ func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
|
||||
if err := s.db.SetSetting(db.SettingLogLevel, in.LogLevel); err != nil {
|
||||
return nil, errors.Wrap(err, "save log level")
|
||||
}
|
||||
}
|
||||
if in.TvNamingFormat != "" {
|
||||
if _, err := template.New("test").Parse(in.TvNamingFormat); err != nil {
|
||||
return nil, errors.Wrap(err, "tv format")
|
||||
}
|
||||
|
||||
s.db.SetSetting(db.SettingTvNamingFormat, in.TvNamingFormat)
|
||||
} else {
|
||||
s.db.SetSetting(db.SettingTvNamingFormat, "")
|
||||
}
|
||||
|
||||
if in.MovieNamingFormat != "" {
|
||||
if _, err := template.New("test").Parse(in.MovieNamingFormat); err != nil {
|
||||
return nil, errors.Wrap(err, "movie format")
|
||||
}
|
||||
|
||||
s.db.SetSetting(db.SettingMovieNamingFormat, in.MovieNamingFormat)
|
||||
} else {
|
||||
s.db.SetSetting(db.SettingMovieNamingFormat, "")
|
||||
}
|
||||
|
||||
plexmatchEnabled := s.db.GetSetting(db.SettingPlexMatchEnabled)
|
||||
@@ -74,7 +98,6 @@ func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
|
||||
} else {
|
||||
s.db.SetSetting(db.SettingEnableTmdbAdultContent, "false")
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -86,15 +109,19 @@ func (s *Server) GetSetting(c *gin.Context) (interface{}, error) {
|
||||
allowQiangban := s.db.GetSetting(db.SettingAllowQiangban)
|
||||
enableNfo := s.db.GetSetting(db.SettingNfoSupportEnabled)
|
||||
enableAdult := s.db.GetSetting(db.SettingEnableTmdbAdultContent)
|
||||
tvFormat := s.db.GetTvNamingFormat()
|
||||
movieFormat := s.db.GetMovingNamingFormat()
|
||||
return &GeneralSettings{
|
||||
TmdbApiKey: tmdb,
|
||||
DownloadDir: downloadDir,
|
||||
LogLevel: logLevel,
|
||||
Proxy: s.db.GetSetting(db.SettingProxy),
|
||||
EnablePlexmatch: plexmatchEnabled == "true",
|
||||
AllowQiangban: allowQiangban == "true",
|
||||
EnableNfo: enableNfo == "true",
|
||||
TmdbApiKey: tmdb,
|
||||
DownloadDir: downloadDir,
|
||||
LogLevel: logLevel,
|
||||
Proxy: s.db.GetSetting(db.SettingProxy),
|
||||
EnablePlexmatch: plexmatchEnabled == "true",
|
||||
AllowQiangban: allowQiangban == "true",
|
||||
EnableNfo: enableNfo == "true",
|
||||
EnableAdultContent: enableAdult == "true",
|
||||
TvNamingFormat: tvFormat,
|
||||
MovieNamingFormat: movieFormat,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -113,6 +140,7 @@ func (s *Server) AddTorznabInfo(c *gin.Context) (interface{}, error) {
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
return nil, errors.Wrap(err, "bind json")
|
||||
}
|
||||
utils.TrimFields(&in)
|
||||
|
||||
log.Infof("add indexer settings: %+v", in)
|
||||
setting := db.TorznabSetting{
|
||||
@@ -188,6 +216,7 @@ func (s *Server) AddDownloadClient(c *gin.Context) (interface{}, error) {
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
return nil, errors.Wrap(err, "bind json")
|
||||
}
|
||||
utils.TrimFields(&in)
|
||||
//test connection
|
||||
_, err := transmission.NewClient(transmission.Config{
|
||||
URL: in.URL,
|
||||
@@ -262,4 +291,4 @@ func (s *Server) TriggerCronJob(c *gin.Context) (interface{}, error) {
|
||||
return nil, err
|
||||
}
|
||||
return "success", nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"polaris/log"
|
||||
"polaris/pkg/storage"
|
||||
"polaris/pkg/utils"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -22,6 +23,7 @@ func (s *Server) AddStorage(c *gin.Context) (interface{}, error) {
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
return nil, errors.Wrap(err, "bind json")
|
||||
}
|
||||
utils.TrimFields(&in)
|
||||
|
||||
if in.Implementation == "webdav" {
|
||||
//test webdav
|
||||
|
||||
@@ -138,7 +138,7 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
||||
trailing: selectedTab == 0
|
||||
? IconButton(
|
||||
tooltip: "删除任务",
|
||||
onPressed: () => onDelete()(ac.id!),
|
||||
onPressed: () => onDelete()(ac.id!.toString()),
|
||||
icon: const Icon(Icons.delete))
|
||||
: const Text("-"),
|
||||
),
|
||||
@@ -155,7 +155,7 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
||||
);
|
||||
}
|
||||
|
||||
Function(int) onDelete() {
|
||||
Function(String) onDelete() {
|
||||
return (id) {
|
||||
final f = ref
|
||||
.read(activitiesDataProvider("active").notifier)
|
||||
|
||||
@@ -47,7 +47,7 @@ class ActivityData extends AutoDisposeFamilyAsyncNotifier<List<Activity>, String
|
||||
return activities;
|
||||
}
|
||||
|
||||
Future<void> deleteActivity(int id) async {
|
||||
Future<void> deleteActivity(String id) async {
|
||||
final dio = await APIs.getDio();
|
||||
var resp = await dio.delete("${APIs.activityUrl}$id");
|
||||
final sp = ServerResponse.fromJson(resp.data);
|
||||
|
||||
@@ -59,6 +59,8 @@ class GeneralSetting {
|
||||
bool? allowQiangban;
|
||||
bool? enableNfo;
|
||||
bool? enableAdult;
|
||||
String? tvNamingFormat;
|
||||
String? movieNamingFormat;
|
||||
|
||||
GeneralSetting(
|
||||
{this.tmdbApiKey,
|
||||
@@ -68,6 +70,8 @@ class GeneralSetting {
|
||||
this.enablePlexmatch,
|
||||
this.enableNfo,
|
||||
this.allowQiangban,
|
||||
this.tvNamingFormat,
|
||||
this.movieNamingFormat,
|
||||
this.enableAdult});
|
||||
|
||||
factory GeneralSetting.fromJson(Map<String, dynamic> json) {
|
||||
@@ -79,6 +83,8 @@ class GeneralSetting {
|
||||
enableAdult: json["enable_adult_content"] ?? false,
|
||||
allowQiangban: json["allow_qiangban"] ?? false,
|
||||
enableNfo: json["enable_nfo"] ?? false,
|
||||
tvNamingFormat: json["tv_naming_format"],
|
||||
movieNamingFormat: json["movie_naming_format"],
|
||||
enablePlexmatch: json["enable_plexmatch"] ?? false);
|
||||
}
|
||||
|
||||
@@ -92,6 +98,8 @@ class GeneralSetting {
|
||||
data["allow_qiangban"] = allowQiangban;
|
||||
data["enable_nfo"] = enableNfo;
|
||||
data["enable_adult_content"] = enableAdult;
|
||||
data["tv_naming_format"] = tvNamingFormat;
|
||||
data["movie_naming_format"] = movieNamingFormat;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ class SearchPageData
|
||||
if (sp.code != 0) {
|
||||
throw sp.message;
|
||||
}
|
||||
ref.invalidate(tvWatchlistDataProvider);
|
||||
//ref.invalidate(tvWatchlistDataProvider);
|
||||
} else {
|
||||
var resp = await dio.post(APIs.watchlistMovieUrl, data: {
|
||||
"tmdb_id": tmdbId,
|
||||
|
||||
@@ -38,6 +38,8 @@ class _GeneralState extends ConsumerState<GeneralSettings> {
|
||||
"allow_qiangban": v.allowQiangban,
|
||||
"enable_nfo": v.enableNfo,
|
||||
"enable_adult": v.enableAdult,
|
||||
"tv_naming_format": v.tvNamingFormat,
|
||||
"movie_naming_format": v.movieNamingFormat,
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -66,6 +68,22 @@ class _GeneralState extends ConsumerState<GeneralSettings> {
|
||||
hintText: "http://10.0.0.1:1080",
|
||||
helperText: "后台联网代理地址,留空表示不启用代理"),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
decoration: const InputDecoration(
|
||||
icon: Icon(Icons.folder),
|
||||
labelText: "电视剧路径命名规则",
|
||||
helperText:
|
||||
"go template语法,可用的变量为:.NameCN, .NameEN, .Year, .TmdbID"),
|
||||
name: "tv_naming_format",
|
||||
),
|
||||
FormBuilderTextField(
|
||||
decoration: const InputDecoration(
|
||||
icon: Icon(Icons.folder),
|
||||
labelText: "电影路径命名规则",
|
||||
helperText:
|
||||
"go template语法,可用的变量为:.NameCN, .NameEN, .Year, .TmdbID"),
|
||||
name: "movie_naming_format",
|
||||
),
|
||||
SizedBox(
|
||||
width: 300,
|
||||
child: FormBuilderDropdown(
|
||||
@@ -137,6 +155,9 @@ class _GeneralState extends ConsumerState<GeneralSettings> {
|
||||
allowQiangban: values["allow_qiangban"],
|
||||
enableAdult: values["enable_adult"],
|
||||
enableNfo: values["enable_nfo"],
|
||||
tvNamingFormat: values["tv_naming_format"],
|
||||
movieNamingFormat:
|
||||
values["movie_naming_format"],
|
||||
enablePlexmatch:
|
||||
values["enable_plexmatch"]))
|
||||
.then((v) => showSnakeBar("更新成功"));
|
||||
|
||||
@@ -98,8 +98,8 @@ class MediaCard extends StatelessWidget {
|
||||
LinearProgressIndicator(
|
||||
value: 1,
|
||||
color: item.downloadedNum! >= item.monitoredNum!
|
||||
? Colors.green
|
||||
: Colors.blue,
|
||||
? Colors.teal
|
||||
: Colors.lightGreen,
|
||||
),
|
||||
Text(
|
||||
item.name!,
|
||||
|
||||
@@ -38,7 +38,7 @@ class _DetailCardState extends ConsumerState<DetailCard> {
|
||||
margin: const EdgeInsets.all(4),
|
||||
clipBehavior: Clip.hardEdge,
|
||||
child: Container(
|
||||
constraints: BoxConstraints(maxHeight: 400),
|
||||
constraints: const BoxConstraints(maxHeight: 400),
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
fit: BoxFit.cover,
|
||||
@@ -52,7 +52,7 @@ class _DetailCardState extends ConsumerState<DetailCard> {
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
screenWidth < 600
|
||||
? SizedBox()
|
||||
? const SizedBox()
|
||||
: Flexible(
|
||||
flex: 2,
|
||||
child: Padding(
|
||||
@@ -72,14 +72,14 @@ class _DetailCardState extends ConsumerState<DetailCard> {
|
||||
children: [
|
||||
//const Text(""),
|
||||
Text(
|
||||
"${widget.details.name} ${widget.details.name != widget.details.originalName ? widget.details.originalName : ''} (${widget.details.airDate!.split("-")[0]})",
|
||||
"${widget.details.name} ${widget.details.name != widget.details.originalName ? widget.details.originalName : ''} ${widget.details.airDate == null ? "" : (widget.details.airDate!.split("-")[0])}",
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
height: 2.5),
|
||||
),
|
||||
const Divider(thickness: 1, height: 1),
|
||||
Text(
|
||||
const Text(
|
||||
"",
|
||||
style: TextStyle(height: 0.2),
|
||||
),
|
||||
@@ -93,14 +93,14 @@ class _DetailCardState extends ConsumerState<DetailCard> {
|
||||
label: Text(
|
||||
"${widget.details.storage!.name}: ${widget.details.mediaType == "tv" ? widget.details.storage!.tvPath : widget.details.storage!.moviePath}"
|
||||
"${widget.details.targetDir}"),
|
||||
padding: EdgeInsets.all(0),
|
||||
padding: const EdgeInsets.all(0),
|
||||
),
|
||||
Chip(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
shape: ContinuousRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(100.0)),
|
||||
label: Text("${widget.details.resolution}"),
|
||||
padding: EdgeInsets.all(0),
|
||||
padding: const EdgeInsets.all(0),
|
||||
),
|
||||
widget.details.limiter != null &&
|
||||
widget.details.limiter!.sizeMax > 0
|
||||
@@ -109,13 +109,13 @@ class _DetailCardState extends ConsumerState<DetailCard> {
|
||||
shape: ContinuousRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(100.0)),
|
||||
padding: EdgeInsets.all(0),
|
||||
padding: const EdgeInsets.all(0),
|
||||
label: Text(
|
||||
"${(widget.details.limiter!.sizeMin).readableFileSize()} - ${(widget.details.limiter!.sizeMax).readableFileSize()}"))
|
||||
: const SizedBox(),
|
||||
MenuAnchor(
|
||||
style:
|
||||
MenuStyle(alignment: Alignment.bottomRight),
|
||||
style: const MenuStyle(
|
||||
alignment: Alignment.bottomRight),
|
||||
menuChildren: [
|
||||
ActionChip.elevated(
|
||||
onPressed: () => launchUrl(url),
|
||||
@@ -124,10 +124,10 @@ class _DetailCardState extends ConsumerState<DetailCard> {
|
||||
shape: ContinuousRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(100.0)),
|
||||
padding: EdgeInsets.all(0),
|
||||
label: Text("TMDB")),
|
||||
padding: const EdgeInsets.all(0),
|
||||
label: const Text("TMDB")),
|
||||
isBlank(widget.details.imdbid)
|
||||
? SizedBox()
|
||||
? const SizedBox()
|
||||
: ActionChip.elevated(
|
||||
onPressed: () => launchUrl(imdbUrl),
|
||||
backgroundColor: Colors.indigo[700],
|
||||
@@ -135,8 +135,8 @@ class _DetailCardState extends ConsumerState<DetailCard> {
|
||||
shape: ContinuousRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(100.0)),
|
||||
padding: EdgeInsets.all(0),
|
||||
label: Text("IMDB"),
|
||||
padding: const EdgeInsets.all(0),
|
||||
label: const Text("IMDB"),
|
||||
)
|
||||
],
|
||||
builder: (context, controller, child) {
|
||||
@@ -152,8 +152,8 @@ class _DetailCardState extends ConsumerState<DetailCard> {
|
||||
shape: ContinuousRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(100.0)),
|
||||
padding: EdgeInsets.all(0),
|
||||
label: Text("外部链接"));
|
||||
padding: const EdgeInsets.all(0),
|
||||
label: const Text("外部链接"));
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -170,7 +170,7 @@ class _DetailCardState extends ConsumerState<DetailCard> {
|
||||
children: [
|
||||
downloadButton(),
|
||||
editIcon(),
|
||||
deleteIcon(),
|
||||
deleteIcon(context),
|
||||
],
|
||||
)
|
||||
],
|
||||
@@ -185,14 +185,14 @@ class _DetailCardState extends ConsumerState<DetailCard> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget deleteIcon() {
|
||||
Widget deleteIcon(BuildContext oriContext) {
|
||||
return IconButton(
|
||||
tooltip: widget.details.mediaType == "tv" ? "删除剧集" : "删除电影",
|
||||
onPressed: () => showConfirmDialog(),
|
||||
onPressed: () => showConfirmDialog(oriContext),
|
||||
icon: const Icon(Icons.delete));
|
||||
}
|
||||
|
||||
Future<void> showConfirmDialog() {
|
||||
Future<void> showConfirmDialog(BuildContext oriContext) {
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
@@ -210,9 +210,13 @@ class _DetailCardState extends ConsumerState<DetailCard> {
|
||||
.read(mediaDetailsProvider(widget.details.id.toString())
|
||||
.notifier)
|
||||
.delete()
|
||||
.then((v) => context.go(widget.details.mediaType == "tv"
|
||||
.then((v) {
|
||||
if (oriContext.mounted) {
|
||||
oriContext.go(widget.details.mediaType == "tv"
|
||||
? WelcomePage.routeTv
|
||||
: WelcomePage.routeMoivie));
|
||||
: WelcomePage.routeMoivie);
|
||||
}
|
||||
});
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text("确认"))
|
||||
@@ -292,7 +296,11 @@ class _DetailCardState extends ConsumerState<DetailCard> {
|
||||
.notifier)
|
||||
.edit(values["resolution"], values["target_dir"],
|
||||
values["limiter"])
|
||||
.then((v) => Navigator.of(context).pop());
|
||||
.then((v) {
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
label: const Text("确认"))
|
||||
|
||||
Reference in New Issue
Block a user