update plugins

This commit is contained in:
royalcat 2025-04-21 03:38:12 +04:00
parent ee8ffc2abd
commit dbf843ad07
23 changed files with 2607 additions and 639 deletions

View file

@ -13,6 +13,8 @@ import (
"time"
"git.kmsign.ru/royalcat/tstor/plugins/qbittorrent/delivery/graphql/model"
"git.kmsign.ru/royalcat/tstor/server/src/delivery/filter"
"git.kmsign.ru/royalcat/tstor/server/src/delivery/graphql/fs"
"github.com/99designs/gqlgen/graphql"
"github.com/99designs/gqlgen/graphql/introspection"
gqlparser "github.com/vektah/gqlparser/v2"
@ -41,9 +43,6 @@ type Config struct {
type ResolverRoot interface {
Mutation() MutationResolver
Query() QueryResolver
ResolverFS() ResolverFSResolver
SimpleDir() SimpleDirResolver
Torrent() TorrentResolver
}
type DirectiveRoot struct {
@ -105,15 +104,6 @@ type MutationResolver interface {
type QueryResolver interface {
Torrents(ctx context.Context, filter *model.TorrentFilter) ([]*model.Torrent, error)
}
type ResolverFSResolver interface {
Entries(ctx context.Context, obj *model.ResolverFs) ([]model.FsEntry, error)
}
type SimpleDirResolver interface {
Entries(ctx context.Context, obj *model.SimpleDir) ([]model.FsEntry, error)
}
type TorrentResolver interface {
SourceFiles(ctx context.Context, obj *model.Torrent) ([]string, error)
}
type executableSchema struct {
schema *ast.Schema
@ -129,7 +119,7 @@ func (e *executableSchema) Schema() *ast.Schema {
return parsedSchema
}
func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]any) (int, bool) {
func (e *executableSchema) Complexity(ctx context.Context, typeName, field string, childComplexity int, rawArgs map[string]any) (int, bool) {
ec := executionContext{nil, e, 0, 0, nil}
_ = ec
switch typeName + "." + field {
@ -167,7 +157,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
break
}
args, err := ec.field_Mutation_cleanup_args(context.TODO(), rawArgs)
args, err := ec.field_Mutation_cleanup_args(ctx, rawArgs)
if err != nil {
return 0, false
}
@ -179,7 +169,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
break
}
args, err := ec.field_Mutation_cleanupUnregistred_args(context.TODO(), rawArgs)
args, err := ec.field_Mutation_cleanupUnregistred_args(ctx, rawArgs)
if err != nil {
return 0, false
}
@ -191,7 +181,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
break
}
args, err := ec.field_Query_torrents_args(context.TODO(), rawArgs)
args, err := ec.field_Query_torrents_args(ctx, rawArgs)
if err != nil {
return 0, false
}
@ -429,7 +419,7 @@ type Schema {
mutation: Mutation
}
`, BuiltIn: false},
{Name: "../../../../graphql/types/filters.graphql", Input: `input Pagination {
{Name: "../../../../server/graphql/types/filters.graphql", Input: `input Pagination {
offset: Int!
limit: Int!
}
@ -461,7 +451,7 @@ input BooleanFilter @oneOf {
eq: Boolean
}
`, BuiltIn: false},
{Name: "../../../../graphql/types/fs.graphql", Input: `interface FsEntry {
{Name: "../../../../server/graphql/types/fs.graphql", Input: `interface FsEntry {
name: String!
}
@ -497,7 +487,7 @@ type ResolverFS implements Dir & FsEntry {
# size: Int!
# }
`, BuiltIn: false},
{Name: "../../../../graphql/types/progress.graphql", Input: `interface Progress {
{Name: "../../../../server/graphql/types/progress.graphql", Input: `interface Progress {
current: Int!
total: Int!
}
@ -1299,7 +1289,7 @@ func (ec *executionContext) fieldContext_Query___schema(_ context.Context, field
return fc, nil
}
func (ec *executionContext) _ResolverFS_name(ctx context.Context, field graphql.CollectedField, obj *model.ResolverFs) (ret graphql.Marshaler) {
func (ec *executionContext) _ResolverFS_name(ctx context.Context, field graphql.CollectedField, obj *fs.ResolverFs) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_ResolverFS_name(ctx, field)
if err != nil {
return graphql.Null
@ -1343,7 +1333,7 @@ func (ec *executionContext) fieldContext_ResolverFS_name(_ context.Context, fiel
return fc, nil
}
func (ec *executionContext) _ResolverFS_entries(ctx context.Context, field graphql.CollectedField, obj *model.ResolverFs) (ret graphql.Marshaler) {
func (ec *executionContext) _ResolverFS_entries(ctx context.Context, field graphql.CollectedField, obj *fs.ResolverFs) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_ResolverFS_entries(ctx, field)
if err != nil {
return graphql.Null
@ -1358,12 +1348,12 @@ func (ec *executionContext) _ResolverFS_entries(ctx context.Context, field graph
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) {
directive0 := func(rctx context.Context) (any, error) {
ctx = rctx // use context from middleware stack in children
return ec.resolvers.ResolverFS().Entries(rctx, obj)
return obj.Entries, nil
}
directive1 := func(ctx context.Context) (any, error) {
if ec.directives.Resolver == nil {
var zeroVal []model.FsEntry
var zeroVal []fs.FsEntry
return zeroVal, errors.New("directive resolver is not implemented")
}
return ec.directives.Resolver(ctx, obj, directive0)
@ -1376,10 +1366,10 @@ func (ec *executionContext) _ResolverFS_entries(ctx context.Context, field graph
if tmp == nil {
return nil, nil
}
if data, ok := tmp.([]model.FsEntry); ok {
if data, ok := tmp.([]fs.FsEntry); ok {
return data, nil
}
return nil, fmt.Errorf(`unexpected type %T from directive, should be []git.kmsign.ru/royalcat/tstor/plugins/qbittorrent/delivery/graphql/model.FsEntry`, tmp)
return nil, fmt.Errorf(`unexpected type %T from directive, should be []git.kmsign.ru/royalcat/tstor/server/src/delivery/graphql/fs.FsEntry`, tmp)
})
if err != nil {
ec.Error(ctx, err)
@ -1391,17 +1381,17 @@ func (ec *executionContext) _ResolverFS_entries(ctx context.Context, field graph
}
return graphql.Null
}
res := resTmp.([]model.FsEntry)
res := resTmp.([]fs.FsEntry)
fc.Result = res
return ec.marshalNFsEntry2ᚕgitᚗkmsignᚗruᚋroyalcatᚋtstorᚋpluginsᚋqbittorrentᚋdeliveryᚋgraphqlᚋmodelᚐFsEntryᚄ(ctx, field.Selections, res)
return ec.marshalNFsEntry2ᚕgitᚗkmsignᚗruᚋroyalcatᚋtstorᚋserverᚋsrcᚋdeliveryᚋgraphqlᚋfsᚐFsEntryᚄ(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_ResolverFS_entries(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "ResolverFS",
Field: field,
IsMethod: true,
IsResolver: true,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("FieldContext.Child cannot be called on type INTERFACE")
},
@ -1483,7 +1473,7 @@ func (ec *executionContext) fieldContext_Schema_mutation(_ context.Context, fiel
return fc, nil
}
func (ec *executionContext) _SimpleDir_name(ctx context.Context, field graphql.CollectedField, obj *model.SimpleDir) (ret graphql.Marshaler) {
func (ec *executionContext) _SimpleDir_name(ctx context.Context, field graphql.CollectedField, obj *fs.SimpleDir) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_SimpleDir_name(ctx, field)
if err != nil {
return graphql.Null
@ -1527,7 +1517,7 @@ func (ec *executionContext) fieldContext_SimpleDir_name(_ context.Context, field
return fc, nil
}
func (ec *executionContext) _SimpleDir_entries(ctx context.Context, field graphql.CollectedField, obj *model.SimpleDir) (ret graphql.Marshaler) {
func (ec *executionContext) _SimpleDir_entries(ctx context.Context, field graphql.CollectedField, obj *fs.SimpleDir) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_SimpleDir_entries(ctx, field)
if err != nil {
return graphql.Null
@ -1542,12 +1532,12 @@ func (ec *executionContext) _SimpleDir_entries(ctx context.Context, field graphq
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) {
directive0 := func(rctx context.Context) (any, error) {
ctx = rctx // use context from middleware stack in children
return ec.resolvers.SimpleDir().Entries(rctx, obj)
return obj.Entries, nil
}
directive1 := func(ctx context.Context) (any, error) {
if ec.directives.Resolver == nil {
var zeroVal []model.FsEntry
var zeroVal []fs.FsEntry
return zeroVal, errors.New("directive resolver is not implemented")
}
return ec.directives.Resolver(ctx, obj, directive0)
@ -1560,10 +1550,10 @@ func (ec *executionContext) _SimpleDir_entries(ctx context.Context, field graphq
if tmp == nil {
return nil, nil
}
if data, ok := tmp.([]model.FsEntry); ok {
if data, ok := tmp.([]fs.FsEntry); ok {
return data, nil
}
return nil, fmt.Errorf(`unexpected type %T from directive, should be []git.kmsign.ru/royalcat/tstor/plugins/qbittorrent/delivery/graphql/model.FsEntry`, tmp)
return nil, fmt.Errorf(`unexpected type %T from directive, should be []git.kmsign.ru/royalcat/tstor/server/src/delivery/graphql/fs.FsEntry`, tmp)
})
if err != nil {
ec.Error(ctx, err)
@ -1575,17 +1565,17 @@ func (ec *executionContext) _SimpleDir_entries(ctx context.Context, field graphq
}
return graphql.Null
}
res := resTmp.([]model.FsEntry)
res := resTmp.([]fs.FsEntry)
fc.Result = res
return ec.marshalNFsEntry2ᚕgitᚗkmsignᚗruᚋroyalcatᚋtstorᚋpluginsᚋqbittorrentᚋdeliveryᚋgraphqlᚋmodelᚐFsEntryᚄ(ctx, field.Selections, res)
return ec.marshalNFsEntry2ᚕgitᚗkmsignᚗruᚋroyalcatᚋtstorᚋserverᚋsrcᚋdeliveryᚋgraphqlᚋfsᚐFsEntryᚄ(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_SimpleDir_entries(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "SimpleDir",
Field: field,
IsMethod: true,
IsResolver: true,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("FieldContext.Child cannot be called on type INTERFACE")
},
@ -1593,7 +1583,7 @@ func (ec *executionContext) fieldContext_SimpleDir_entries(_ context.Context, fi
return fc, nil
}
func (ec *executionContext) _SimpleFile_name(ctx context.Context, field graphql.CollectedField, obj *model.SimpleFile) (ret graphql.Marshaler) {
func (ec *executionContext) _SimpleFile_name(ctx context.Context, field graphql.CollectedField, obj *fs.SimpleFile) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_SimpleFile_name(ctx, field)
if err != nil {
return graphql.Null
@ -1637,7 +1627,7 @@ func (ec *executionContext) fieldContext_SimpleFile_name(_ context.Context, fiel
return fc, nil
}
func (ec *executionContext) _SimpleFile_size(ctx context.Context, field graphql.CollectedField, obj *model.SimpleFile) (ret graphql.Marshaler) {
func (ec *executionContext) _SimpleFile_size(ctx context.Context, field graphql.CollectedField, obj *fs.SimpleFile) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_SimpleFile_size(ctx, field)
if err != nil {
return graphql.Null
@ -1784,7 +1774,7 @@ func (ec *executionContext) _Torrent_sourceFiles(ctx context.Context, field grap
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) {
directive0 := func(rctx context.Context) (any, error) {
ctx = rctx // use context from middleware stack in children
return ec.resolvers.Torrent().SourceFiles(rctx, obj)
return obj.SourceFiles, nil
}
directive1 := func(ctx context.Context) (any, error) {
@ -1826,8 +1816,8 @@ func (ec *executionContext) fieldContext_Torrent_sourceFiles(_ context.Context,
fc = &graphql.FieldContext{
Object: "Torrent",
Field: field,
IsMethod: true,
IsResolver: true,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type String does not have child fields")
},
@ -3786,8 +3776,8 @@ func (ec *executionContext) fieldContext___Type_isOneOf(_ context.Context, field
// region **************************** input.gotpl *****************************
func (ec *executionContext) unmarshalInputBooleanFilter(ctx context.Context, obj any) (model.BooleanFilter, error) {
var it model.BooleanFilter
func (ec *executionContext) unmarshalInputBooleanFilter(ctx context.Context, obj any) (filter.BooleanFilter, error) {
var it filter.BooleanFilter
asMap := map[string]any{}
for k, v := range obj.(map[string]any) {
asMap[k] = v
@ -3813,8 +3803,8 @@ func (ec *executionContext) unmarshalInputBooleanFilter(ctx context.Context, obj
return it, nil
}
func (ec *executionContext) unmarshalInputDateTimeFilter(ctx context.Context, obj any) (model.DateTimeFilter, error) {
var it model.DateTimeFilter
func (ec *executionContext) unmarshalInputDateTimeFilter(ctx context.Context, obj any) (filter.DateTimeFilter, error) {
var it filter.DateTimeFilter
asMap := map[string]any{}
for k, v := range obj.(map[string]any) {
asMap[k] = v
@ -3868,8 +3858,8 @@ func (ec *executionContext) unmarshalInputDateTimeFilter(ctx context.Context, ob
return it, nil
}
func (ec *executionContext) unmarshalInputIntFilter(ctx context.Context, obj any) (model.IntFilter, error) {
var it model.IntFilter
func (ec *executionContext) unmarshalInputIntFilter(ctx context.Context, obj any) (filter.IntFilter, error) {
var it filter.IntFilter
asMap := map[string]any{}
for k, v := range obj.(map[string]any) {
asMap[k] = v
@ -3964,8 +3954,8 @@ func (ec *executionContext) unmarshalInputPagination(ctx context.Context, obj an
return it, nil
}
func (ec *executionContext) unmarshalInputStringFilter(ctx context.Context, obj any) (model.StringFilter, error) {
var it model.StringFilter
func (ec *executionContext) unmarshalInputStringFilter(ctx context.Context, obj any) (filter.StringFilter, error) {
var it filter.StringFilter
asMap := map[string]any{}
for k, v := range obj.(map[string]any) {
asMap[k] = v
@ -4021,7 +4011,7 @@ func (ec *executionContext) unmarshalInputTorrentFilter(ctx context.Context, obj
switch k {
case "sourcesCount":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("sourcesCount"))
data, err := ec.unmarshalOIntFilter2ᚖgitᚗkmsignᚗruᚋroyalcatᚋtstorᚋpluginsᚋqbittorrentᚋdeliveryᚋgraphqlᚋmodelᚐIntFilter(ctx, v)
data, err := ec.unmarshalOIntFilter2ᚖgitᚗkmsignᚗruᚋroyalcatᚋtstorᚋserverᚋsrcᚋdeliveryᚋfilterᚐIntFilter(ctx, v)
if err != nil {
return it, err
}
@ -4036,20 +4026,20 @@ func (ec *executionContext) unmarshalInputTorrentFilter(ctx context.Context, obj
// region ************************** interface.gotpl ***************************
func (ec *executionContext) _Dir(ctx context.Context, sel ast.SelectionSet, obj model.Dir) graphql.Marshaler {
func (ec *executionContext) _Dir(ctx context.Context, sel ast.SelectionSet, obj fs.Dir) graphql.Marshaler {
switch obj := (obj).(type) {
case nil:
return graphql.Null
case model.SimpleDir:
case fs.SimpleDir:
return ec._SimpleDir(ctx, sel, &obj)
case *model.SimpleDir:
case *fs.SimpleDir:
if obj == nil {
return graphql.Null
}
return ec._SimpleDir(ctx, sel, obj)
case model.ResolverFs:
case fs.ResolverFs:
return ec._ResolverFS(ctx, sel, &obj)
case *model.ResolverFs:
case *fs.ResolverFs:
if obj == nil {
return graphql.Null
}
@ -4063,9 +4053,9 @@ func (ec *executionContext) _File(ctx context.Context, sel ast.SelectionSet, obj
switch obj := (obj).(type) {
case nil:
return graphql.Null
case model.SimpleFile:
case fs.SimpleFile:
return ec._SimpleFile(ctx, sel, &obj)
case *model.SimpleFile:
case *fs.SimpleFile:
if obj == nil {
return graphql.Null
}
@ -4075,27 +4065,27 @@ func (ec *executionContext) _File(ctx context.Context, sel ast.SelectionSet, obj
}
}
func (ec *executionContext) _FsEntry(ctx context.Context, sel ast.SelectionSet, obj model.FsEntry) graphql.Marshaler {
func (ec *executionContext) _FsEntry(ctx context.Context, sel ast.SelectionSet, obj fs.FsEntry) graphql.Marshaler {
switch obj := (obj).(type) {
case nil:
return graphql.Null
case model.SimpleFile:
case fs.SimpleFile:
return ec._SimpleFile(ctx, sel, &obj)
case *model.SimpleFile:
case *fs.SimpleFile:
if obj == nil {
return graphql.Null
}
return ec._SimpleFile(ctx, sel, obj)
case model.SimpleDir:
case fs.SimpleDir:
return ec._SimpleDir(ctx, sel, &obj)
case *model.SimpleDir:
case *fs.SimpleDir:
if obj == nil {
return graphql.Null
}
return ec._SimpleDir(ctx, sel, obj)
case model.ResolverFs:
case fs.ResolverFs:
return ec._ResolverFS(ctx, sel, &obj)
case *model.ResolverFs:
case *fs.ResolverFs:
if obj == nil {
return graphql.Null
}
@ -4105,7 +4095,7 @@ func (ec *executionContext) _FsEntry(ctx context.Context, sel ast.SelectionSet,
return graphql.Null
}
return ec._File(ctx, sel, obj)
case model.Dir:
case fs.Dir:
if obj == nil {
return graphql.Null
}
@ -4346,7 +4336,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr
var resolverFSImplementors = []string{"ResolverFS", "Dir", "FsEntry"}
func (ec *executionContext) _ResolverFS(ctx context.Context, sel ast.SelectionSet, obj *model.ResolverFs) graphql.Marshaler {
func (ec *executionContext) _ResolverFS(ctx context.Context, sel ast.SelectionSet, obj *fs.ResolverFs) graphql.Marshaler {
fields := graphql.CollectFields(ec.OperationContext, sel, resolverFSImplementors)
out := graphql.NewFieldSet(fields)
@ -4358,44 +4348,13 @@ func (ec *executionContext) _ResolverFS(ctx context.Context, sel ast.SelectionSe
case "name":
out.Values[i] = ec._ResolverFS_name(ctx, field, obj)
if out.Values[i] == graphql.Null {
atomic.AddUint32(&out.Invalids, 1)
out.Invalids++
}
case "entries":
field := field
innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._ResolverFS_entries(ctx, field, obj)
if res == graphql.Null {
atomic.AddUint32(&fs.Invalids, 1)
}
return res
out.Values[i] = ec._ResolverFS_entries(ctx, field, obj)
if out.Values[i] == graphql.Null {
out.Invalids++
}
if field.Deferrable != nil {
dfs, ok := deferred[field.Deferrable.Label]
di := 0
if ok {
dfs.AddField(field)
di = len(dfs.Values) - 1
} else {
dfs = graphql.NewFieldSet([]graphql.CollectedField{field})
deferred[field.Deferrable.Label] = dfs
}
dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler {
return innerFunc(ctx, dfs)
})
// don't run the out.Concurrently() call below
out.Values[i] = graphql.Null
continue
}
out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
default:
panic("unknown field " + strconv.Quote(field.Name))
}
@ -4459,7 +4418,7 @@ func (ec *executionContext) _Schema(ctx context.Context, sel ast.SelectionSet, o
var simpleDirImplementors = []string{"SimpleDir", "Dir", "FsEntry"}
func (ec *executionContext) _SimpleDir(ctx context.Context, sel ast.SelectionSet, obj *model.SimpleDir) graphql.Marshaler {
func (ec *executionContext) _SimpleDir(ctx context.Context, sel ast.SelectionSet, obj *fs.SimpleDir) graphql.Marshaler {
fields := graphql.CollectFields(ec.OperationContext, sel, simpleDirImplementors)
out := graphql.NewFieldSet(fields)
@ -4471,44 +4430,13 @@ func (ec *executionContext) _SimpleDir(ctx context.Context, sel ast.SelectionSet
case "name":
out.Values[i] = ec._SimpleDir_name(ctx, field, obj)
if out.Values[i] == graphql.Null {
atomic.AddUint32(&out.Invalids, 1)
out.Invalids++
}
case "entries":
field := field
innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._SimpleDir_entries(ctx, field, obj)
if res == graphql.Null {
atomic.AddUint32(&fs.Invalids, 1)
}
return res
out.Values[i] = ec._SimpleDir_entries(ctx, field, obj)
if out.Values[i] == graphql.Null {
out.Invalids++
}
if field.Deferrable != nil {
dfs, ok := deferred[field.Deferrable.Label]
di := 0
if ok {
dfs.AddField(field)
di = len(dfs.Values) - 1
} else {
dfs = graphql.NewFieldSet([]graphql.CollectedField{field})
deferred[field.Deferrable.Label] = dfs
}
dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler {
return innerFunc(ctx, dfs)
})
// don't run the out.Concurrently() call below
out.Values[i] = graphql.Null
continue
}
out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
default:
panic("unknown field " + strconv.Quote(field.Name))
}
@ -4534,7 +4462,7 @@ func (ec *executionContext) _SimpleDir(ctx context.Context, sel ast.SelectionSet
var simpleFileImplementors = []string{"SimpleFile", "File", "FsEntry"}
func (ec *executionContext) _SimpleFile(ctx context.Context, sel ast.SelectionSet, obj *model.SimpleFile) graphql.Marshaler {
func (ec *executionContext) _SimpleFile(ctx context.Context, sel ast.SelectionSet, obj *fs.SimpleFile) graphql.Marshaler {
fields := graphql.CollectFields(ec.OperationContext, sel, simpleFileImplementors)
out := graphql.NewFieldSet(fields)
@ -4590,49 +4518,18 @@ func (ec *executionContext) _Torrent(ctx context.Context, sel ast.SelectionSet,
case "name":
out.Values[i] = ec._Torrent_name(ctx, field, obj)
if out.Values[i] == graphql.Null {
atomic.AddUint32(&out.Invalids, 1)
out.Invalids++
}
case "hash":
out.Values[i] = ec._Torrent_hash(ctx, field, obj)
if out.Values[i] == graphql.Null {
atomic.AddUint32(&out.Invalids, 1)
out.Invalids++
}
case "sourceFiles":
field := field
innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._Torrent_sourceFiles(ctx, field, obj)
if res == graphql.Null {
atomic.AddUint32(&fs.Invalids, 1)
}
return res
out.Values[i] = ec._Torrent_sourceFiles(ctx, field, obj)
if out.Values[i] == graphql.Null {
out.Invalids++
}
if field.Deferrable != nil {
dfs, ok := deferred[field.Deferrable.Label]
di := 0
if ok {
dfs.AddField(field)
di = len(dfs.Values) - 1
} else {
dfs = graphql.NewFieldSet([]graphql.CollectedField{field})
deferred[field.Deferrable.Label] = dfs
}
dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler {
return innerFunc(ctx, dfs)
})
// don't run the out.Concurrently() call below
out.Values[i] = graphql.Null
continue
}
out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
default:
panic("unknown field " + strconv.Quote(field.Name))
}
@ -5034,7 +4931,7 @@ func (ec *executionContext) marshalNCleanupUnregistredResponse2ᚖgitᚗkmsign
return ec._CleanupUnregistredResponse(ctx, sel, v)
}
func (ec *executionContext) marshalNFsEntry2gitᚗkmsignᚗruᚋroyalcatᚋtstorᚋpluginsᚋqbittorrentᚋdeliveryᚋgraphqlᚋmodelᚐFsEntry(ctx context.Context, sel ast.SelectionSet, v model.FsEntry) graphql.Marshaler {
func (ec *executionContext) marshalNFsEntry2gitᚗkmsignᚗruᚋroyalcatᚋtstorᚋserverᚋsrcᚋdeliveryᚋgraphqlᚋfsᚐFsEntry(ctx context.Context, sel ast.SelectionSet, v fs.FsEntry) graphql.Marshaler {
if v == nil {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "the requested element is null which the schema does not allow")
@ -5044,7 +4941,7 @@ func (ec *executionContext) marshalNFsEntry2gitᚗkmsignᚗruᚋroyalcatᚋtstor
return ec._FsEntry(ctx, sel, v)
}
func (ec *executionContext) marshalNFsEntry2ᚕgitᚗkmsignᚗruᚋroyalcatᚋtstorᚋpluginsᚋqbittorrentᚋdeliveryᚋgraphqlᚋmodelᚐFsEntryᚄ(ctx context.Context, sel ast.SelectionSet, v []model.FsEntry) graphql.Marshaler {
func (ec *executionContext) marshalNFsEntry2ᚕgitᚗkmsignᚗruᚋroyalcatᚋtstorᚋserverᚋsrcᚋdeliveryᚋgraphqlᚋfsᚐFsEntryᚄ(ctx context.Context, sel ast.SelectionSet, v []fs.FsEntry) graphql.Marshaler {
ret := make(graphql.Array, len(v))
var wg sync.WaitGroup
isLen1 := len(v) == 1
@ -5068,7 +4965,7 @@ func (ec *executionContext) marshalNFsEntry2ᚕgitᚗkmsignᚗruᚋroyalcatᚋts
if !isLen1 {
defer wg.Done()
}
ret[i] = ec.marshalNFsEntry2gitᚗkmsignᚗruᚋroyalcatᚋtstorᚋpluginsᚋqbittorrentᚋdeliveryᚋgraphqlᚋmodelᚐFsEntry(ctx, sel, v[i])
ret[i] = ec.marshalNFsEntry2gitᚗkmsignᚗruᚋroyalcatᚋtstorᚋserverᚋsrcᚋdeliveryᚋgraphqlᚋfsᚐFsEntry(ctx, sel, v[i])
}
if isLen1 {
f(i)
@ -5547,7 +5444,7 @@ func (ec *executionContext) marshalOInt2ᚖint64(ctx context.Context, sel ast.Se
return res
}
func (ec *executionContext) unmarshalOIntFilter2ᚖgitᚗkmsignᚗruᚋroyalcatᚋtstorᚋpluginsᚋqbittorrentᚋdeliveryᚋgraphqlᚋmodelᚐIntFilter(ctx context.Context, v any) (*model.IntFilter, error) {
func (ec *executionContext) unmarshalOIntFilter2ᚖgitᚗkmsignᚗruᚋroyalcatᚋtstorᚋserverᚋsrcᚋdeliveryᚋfilterᚐIntFilter(ctx context.Context, v any) (*filter.IntFilter, error) {
if v == nil {
return nil, nil
}

View file

@ -3,16 +3,9 @@
package model
import (
"time"
"git.kmsign.ru/royalcat/tstor/server/src/delivery/filter"
)
type Dir interface {
IsFsEntry()
IsDir()
GetName() string
GetEntries() []FsEntry
}
type File interface {
IsFsEntry()
IsFile()
@ -20,21 +13,12 @@ type File interface {
GetSize() int64
}
type FsEntry interface {
IsFsEntry()
GetName() string
}
type Progress interface {
IsProgress()
GetCurrent() int64
GetTotal() int64
}
type BooleanFilter struct {
Eq *bool `json:"eq,omitempty"`
}
type CleanupResponse struct {
Count int64 `json:"count"`
Hashes []string `json:"hashes"`
@ -45,23 +29,6 @@ type CleanupUnregistredResponse struct {
Hashes []string `json:"hashes"`
}
type DateTimeFilter struct {
Eq *time.Time `json:"eq,omitempty"`
Gt *time.Time `json:"gt,omitempty"`
Lt *time.Time `json:"lt,omitempty"`
Gte *time.Time `json:"gte,omitempty"`
Lte *time.Time `json:"lte,omitempty"`
}
type IntFilter struct {
Eq *int64 `json:"eq,omitempty"`
Gt *int64 `json:"gt,omitempty"`
Lt *int64 `json:"lt,omitempty"`
Gte *int64 `json:"gte,omitempty"`
Lte *int64 `json:"lte,omitempty"`
In []int64 `json:"in,omitempty"`
}
type Mutation struct {
}
@ -73,68 +40,11 @@ type Pagination struct {
type Query struct {
}
type ResolverFs struct {
Name string `json:"name"`
Entries []FsEntry `json:"entries"`
}
func (ResolverFs) IsDir() {}
func (this ResolverFs) GetName() string { return this.Name }
func (this ResolverFs) GetEntries() []FsEntry {
if this.Entries == nil {
return nil
}
interfaceSlice := make([]FsEntry, 0, len(this.Entries))
for _, concrete := range this.Entries {
interfaceSlice = append(interfaceSlice, concrete)
}
return interfaceSlice
}
func (ResolverFs) IsFsEntry() {}
type Schema struct {
Query *Query `json:"query,omitempty"`
Mutation *Mutation `json:"mutation,omitempty"`
}
type SimpleDir struct {
Name string `json:"name"`
Entries []FsEntry `json:"entries"`
}
func (SimpleDir) IsDir() {}
func (this SimpleDir) GetName() string { return this.Name }
func (this SimpleDir) GetEntries() []FsEntry {
if this.Entries == nil {
return nil
}
interfaceSlice := make([]FsEntry, 0, len(this.Entries))
for _, concrete := range this.Entries {
interfaceSlice = append(interfaceSlice, concrete)
}
return interfaceSlice
}
func (SimpleDir) IsFsEntry() {}
type SimpleFile struct {
Name string `json:"name"`
Size int64 `json:"size"`
}
func (SimpleFile) IsFile() {}
func (this SimpleFile) GetName() string { return this.Name }
func (this SimpleFile) GetSize() int64 { return this.Size }
func (SimpleFile) IsFsEntry() {}
type StringFilter struct {
Eq *string `json:"eq,omitempty"`
Substr *string `json:"substr,omitempty"`
In []string `json:"in,omitempty"`
}
type Torrent struct {
Name string `json:"name"`
Hash string `json:"hash"`
@ -142,5 +52,5 @@ type Torrent struct {
}
type TorrentFilter struct {
SourcesCount *IntFilter `json:"sourcesCount,omitempty"`
SourcesCount *filter.IntFilter `json:"sourcesCount,omitempty"`
}

View file

@ -2,31 +2,23 @@ package resolver
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.68
// Code generated by github.com/99designs/gqlgen version v0.17.70
import (
"context"
"fmt"
graphql1 "git.kmsign.ru/royalcat/tstor/plugins/qbittorrent/delivery/graphql"
"git.kmsign.ru/royalcat/tstor/plugins/qbittorrent/delivery/graphql/model"
"git.kmsign.ru/royalcat/tstor/server/src/delivery/graphql/fs"
)
// Entries is the resolver for the entries field.
func (r *resolverFSResolver) Entries(ctx context.Context, obj *model.ResolverFs) ([]model.FsEntry, error) {
panic(fmt.Errorf("not implemented: Entries - entries"))
func (r *resolverFSResolver) Entries(ctx context.Context, obj *fs.ResolverFs) ([]fs.FsEntry, error) {
return obj.ResolverEntries(ctx)
}
// Entries is the resolver for the entries field.
func (r *simpleDirResolver) Entries(ctx context.Context, obj *model.SimpleDir) ([]model.FsEntry, error) {
panic(fmt.Errorf("not implemented: Entries - entries"))
func (r *simpleDirResolver) Entries(ctx context.Context, obj *fs.SimpleDir) ([]fs.FsEntry, error) {
return obj.SimpleDirEntries(ctx)
}
// ResolverFS returns graphql1.ResolverFSResolver implementation.
func (r *Resolver) ResolverFS() graphql1.ResolverFSResolver { return &resolverFSResolver{r} }
// SimpleDir returns graphql1.SimpleDirResolver implementation.
func (r *Resolver) SimpleDir() graphql1.SimpleDirResolver { return &simpleDirResolver{r} }
type resolverFSResolver struct{ *Resolver }
type simpleDirResolver struct{ *Resolver }

View file

@ -2,11 +2,10 @@ package resolver
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.68
// Code generated by github.com/99designs/gqlgen version v0.17.72
import (
"context"
"fmt"
graphql1 "git.kmsign.ru/royalcat/tstor/plugins/qbittorrent/delivery/graphql"
"git.kmsign.ru/royalcat/tstor/plugins/qbittorrent/delivery/graphql/model"
@ -14,12 +13,26 @@ import (
// Cleanup is the resolver for the cleanup field.
func (r *mutationResolver) Cleanup(ctx context.Context, run bool) (*model.CleanupResponse, error) {
panic(fmt.Errorf("not implemented: Cleanup - cleanup"))
hahses, err := r.QBitTorrentDaemon.Cleanup(ctx, run)
if err != nil {
return nil, err
}
return &model.CleanupResponse{
Count: int64(len(hahses)),
Hashes: hahses,
}, nil
}
// CleanupUnregistred is the resolver for the cleanupUnregistred field.
func (r *mutationResolver) CleanupUnregistred(ctx context.Context, run bool) (*model.CleanupUnregistredResponse, error) {
panic(fmt.Errorf("not implemented: CleanupUnregistred - cleanupUnregistred"))
hahses, err := r.QBitTorrentDaemon.CleanupUnregistred(ctx, run)
if err != nil {
return nil, err
}
return &model.CleanupUnregistredResponse{
Count: int64(len(hahses)),
Hashes: hahses,
}, nil
}
// Mutation returns graphql1.MutationResolver implementation.

View file

@ -2,11 +2,12 @@ package resolver
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.68
// Code generated by github.com/99designs/gqlgen version v0.17.72
import (
"context"
"fmt"
"slices"
graphql1 "git.kmsign.ru/royalcat/tstor/plugins/qbittorrent/delivery/graphql"
"git.kmsign.ru/royalcat/tstor/plugins/qbittorrent/delivery/graphql/model"
@ -14,19 +15,38 @@ import (
// Torrents is the resolver for the torrents field.
func (r *queryResolver) Torrents(ctx context.Context, filter *model.TorrentFilter) ([]*model.Torrent, error) {
panic(fmt.Errorf("not implemented: Torrents - torrents"))
}
info, err := r.QBitTorrentDaemon.ListTorrents(ctx)
if err != nil {
return nil, fmt.Errorf("error listing torrents: %w", err)
}
// SourceFiles is the resolver for the sourceFiles field.
func (r *torrentResolver) SourceFiles(ctx context.Context, obj *model.Torrent) ([]string, error) {
panic(fmt.Errorf("not implemented: SourceFiles - sourceFiles"))
out := make([]*model.Torrent, len(info))
for i, v := range info {
out[i] = &model.Torrent{
Name: v.Name,
Hash: v.Hash,
}
}
if filter != nil {
if filter.SourcesCount != nil {
for _, t := range out {
srcs, err := r.QBitTorrentDaemon.SourceFiles(ctx, t.Hash)
if err != nil {
return nil, fmt.Errorf("hash %s failed listing source files: %w", t.Hash, err)
}
t.SourceFiles = srcs
}
out = slices.DeleteFunc(out, func(t *model.Torrent) bool {
return !filter.SourcesCount.Include(int64(len(t.SourceFiles)))
})
}
}
return out, nil
}
// Query returns graphql1.QueryResolver implementation.
func (r *Resolver) Query() graphql1.QueryResolver { return &queryResolver{r} }
// Torrent returns graphql1.TorrentResolver implementation.
func (r *Resolver) Torrent() graphql1.TorrentResolver { return &torrentResolver{r} }
type queryResolver struct{ *Resolver }
type torrentResolver struct{ *Resolver }

View file

@ -1,7 +1,22 @@
package resolver
import (
"context"
"git.kmsign.ru/royalcat/tstor/plugins/qbittorrent/pkg/qbittorrent"
)
// This file will not be regenerated automatically.
//
// It serves as dependency injection for your app, add any dependencies you require here.
type Resolver struct{}
type Resolver struct {
QBitTorrentDaemon QBitTorrentDaemon
}
type QBitTorrentDaemon interface {
ListTorrents(ctx context.Context) ([]*qbittorrent.TorrentInfo, error)
SourceFiles(ctx context.Context, hash string) ([]string, error)
Cleanup(ctx context.Context, run bool) ([]string, error)
CleanupUnregistred(ctx context.Context, run bool) ([]string, error)
}