-
-
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
7 changed files
with
108 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,6 @@ open an issue on Github. | |
CmdEzTest, | ||
CmdThread, | ||
CmdObfuscate, | ||
CmdRecord, | ||
}, | ||
} |
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,66 @@ | ||
package diag | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"io" | ||
"os" | ||
"time" | ||
|
||
"github.com/rusq/slackdump/v2" | ||
"github.com/rusq/slackdump/v2/auth" | ||
"github.com/rusq/slackdump/v2/cmd/slackdump/internal/cfg" | ||
"github.com/rusq/slackdump/v2/cmd/slackdump/internal/golang/base" | ||
"github.com/rusq/slackdump/v2/internal/processors" | ||
) | ||
|
||
var CmdRecord = &base.Command{ | ||
UsageLine: "slackdump diag record [options] <channel>", | ||
Short: "dump slack data in a event record format", | ||
FlagMask: cfg.OmitBaseLocFlag | cfg.OmitDownloadFlag, | ||
PrintFlags: true, | ||
RequireAuth: true, | ||
} | ||
|
||
func init() { | ||
// break init cycle | ||
CmdRecord.Run = runRecord | ||
} | ||
|
||
var output = CmdRecord.Flag.String("output", "", "output file") | ||
|
||
func runRecord(ctx context.Context, cmd *base.Command, args []string) error { | ||
if len(args) == 0 { | ||
return errors.New("missing channel argument") | ||
} | ||
|
||
prov, err := auth.FromContext(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
sess, err := slackdump.New(ctx, prov, cfg.SlackConfig) | ||
if err != nil { | ||
return err | ||
} | ||
defer sess.Close() | ||
|
||
var w io.Writer | ||
if *output == "" { | ||
w = os.Stdout | ||
} else { | ||
f, err := os.Create("output.jsonl") | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
w = f | ||
} | ||
|
||
rec := processors.NewRecorder(w) | ||
defer rec.Close() | ||
|
||
if err := sess.Stream(ctx, args[0], rec, time.Time{}, time.Time{}); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
Binary file not shown.
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,25 @@ | ||
package fixtures | ||
|
||
import ( | ||
"bytes" | ||
"compress/gzip" | ||
_ "embed" | ||
"io" | ||
) | ||
|
||
// To generate the events.jsonl.gz file: | ||
// 1. Record events from slackdump | ||
// 2. Obfuscate them with ./cmd/slackdump diag obfuscate -i clear.jsonl -o events.jsonl | ||
// 3. Compress them with gzip -9 -c events.jsonl > events.jsonl.gz | ||
|
||
//go:embed assets/events.jsonl.gz | ||
var eventsJsonlGz []byte | ||
|
||
// EventsJSONL returns a reader for the events.jsonl.gz file. | ||
func EventsJSONL() io.ReadCloser { | ||
gz, err := gzip.NewReader(bytes.NewReader(eventsJsonlGz)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return gz | ||
} |
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