-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
265 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dump | ||
|
||
import ( | ||
"context" | ||
_ "embed" | ||
"testing" | ||
) | ||
|
||
func Test_reconstruct(t *testing.T) { | ||
if err := reconstruct(context.Background(), nil, "../../../../tmp", namer{}); err != nil { | ||
t.Fatal(err) | ||
} | ||
t.Fatal("x") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package fetch | ||
|
||
import ( | ||
"compress/gzip" | ||
"context" | ||
"fmt" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"github.com/rusq/dlog" | ||
"github.com/rusq/slackdump/v2" | ||
"github.com/rusq/slackdump/v2/internal/event/processor" | ||
"github.com/rusq/slackdump/v2/internal/structures" | ||
"github.com/slack-go/slack" | ||
) | ||
|
||
type Parameters struct { | ||
Oldest time.Time | ||
Latest time.Time | ||
List *structures.EntityList | ||
DumpFiles bool | ||
} | ||
|
||
func Fetch(ctx context.Context, sess *slackdump.Session, dir string, p *Parameters) error { | ||
if p == nil { | ||
return fmt.Errorf("nil parameters") | ||
} | ||
|
||
dlog.Printf("using %s as temporary directory", dir) | ||
|
||
for _, link := range p.List.Include { | ||
if err := dumpOne(ctx, sess, dir, link, p); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
type streamer interface { | ||
Client() *slack.Client | ||
Stream(context.Context, processor.Processor, string, time.Time, time.Time) error | ||
} | ||
|
||
var replacer = strings.NewReplacer("/", "-", ":", "-") | ||
|
||
func dumpOne(ctx context.Context, sess streamer, dir string, link string, p *Parameters) error { | ||
var pattern = fmt.Sprintf("%s-*.jsonl.gz", replacer.Replace(link)) | ||
f, err := os.CreateTemp(dir, pattern) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
|
||
gz := gzip.NewWriter(f) | ||
defer gz.Close() | ||
|
||
pr, err := processor.NewStandard(ctx, gz, sess.Client(), dir, processor.DumpFiles(p.DumpFiles)) | ||
if err != nil { | ||
return err | ||
} | ||
defer pr.Close() | ||
|
||
if err := sess.Stream(ctx, pr, link, p.Oldest, p.Latest); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.