Skip to content

Commit

Permalink
move search under controller and init file downloaded that does nothi…
Browse files Browse the repository at this point in the history
…ng because there's no files
  • Loading branch information
rusq committed Mar 31, 2024
1 parent 8e7c303 commit 49a5ce0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
20 changes: 17 additions & 3 deletions cmd/slackdump/internal/record/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import (
"errors"
"strings"

"github.com/rusq/fsadapter"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base"
"github.com/rusq/slackdump/v3/internal/chunk"
"github.com/rusq/slackdump/v3/internal/chunk/control"
"github.com/rusq/slackdump/v3/internal/chunk/transform/fileproc"
"github.com/rusq/slackdump/v3/logger"
)

var CmdSearch = &base.Command{
Expand Down Expand Up @@ -47,9 +50,20 @@ func runSearch(ctx context.Context, cmd *base.Command, args []string) error {
}
defer cd.Close()

stream := sess.Stream()
ctrl := control.NewSearch(cd, stream)

lg := logger.FromContext(ctx)
dl, stop := fileproc.NewDownloader(
ctx,
cfg.DownloadFiles,
sess.Client(),
fsadapter.NewDirectory(cd.Name()),
lg,
)
defer stop()
var (
subproc = fileproc.NewExport(fileproc.STmattermost, dl)
stream = sess.Stream()
ctrl = control.New(cd, stream, control.WithLogger(lg), control.WithFiler(subproc))
)
if err := ctrl.Search(ctx, query); err != nil {
base.SetExitStatus(base.SApplicationError)
return err
Expand Down
15 changes: 1 addition & 14 deletions internal/chunk/control/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,10 @@ import (
"context"
"time"

"github.com/rusq/slackdump/v3"
"github.com/rusq/slackdump/v3/internal/chunk"
"github.com/rusq/slackdump/v3/logger"
"golang.org/x/sync/errgroup"
)

type Search struct {
cd *chunk.Directory
s *slackdump.Stream
lg logger.Interface
}

func NewSearch(cd *chunk.Directory, s *slackdump.Stream) *Search {
return &Search{cd: cd, s: s, lg: logger.Default}
}

func (s *Search) Search(ctx context.Context, query string) error {
func (s *Controller) Search(ctx context.Context, query string) error {
var eg errgroup.Group
start := time.Now()
eg.Go(func() error {
Expand Down

0 comments on commit 49a5ce0

Please sign in to comment.