Files
bitmagnet/internal/app/cmd/processcmd/command.go
T
mgdigital c16f76130c Classifier rewrite (#213)
The classifier has been re-implemented and now uses a DSL allowing for full customisation. Several bugs have also been fixed.

- Closes https://github.com/bitmagnet-io/bitmagnet/issues/182
- Closes https://github.com/bitmagnet-io/bitmagnet/issues/70
- Closes https://github.com/bitmagnet-io/bitmagnet/issues/68
- Hopefully fixes https://github.com/bitmagnet-io/bitmagnet/issues/126
2024-04-21 16:24:10 +01:00

55 lines
1.1 KiB
Go

package processcmd
import (
"github.com/bitmagnet-io/bitmagnet/internal/boilerplate/lazy"
"github.com/bitmagnet-io/bitmagnet/internal/processor"
"github.com/bitmagnet-io/bitmagnet/internal/protocol"
"github.com/urfave/cli/v2"
"go.uber.org/fx"
"go.uber.org/zap"
)
type Params struct {
fx.In
Processor lazy.Lazy[processor.Processor]
Logger *zap.SugaredLogger
}
type Result struct {
fx.Out
Command *cli.Command `group:"commands"`
}
func New(p Params) (Result, error) {
return Result{Command: &cli.Command{
Name: "process",
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "infoHash",
},
},
Action: func(ctx *cli.Context) error {
pr, err := p.Processor.Get()
if err != nil {
return err
}
var infoHashes []protocol.ID
for _, infoHash := range ctx.StringSlice("infoHash") {
id, err := protocol.ParseID(infoHash)
if err != nil {
return err
}
infoHashes = append(infoHashes, id)
}
if err != nil {
return err
}
return pr.Process(ctx.Context, processor.MessageParams{
ClassifyMode: processor.ClassifyModeRematch,
InfoHashes: infoHashes,
})
},
},
}, nil
}