-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
15 changed files
with
188 additions
and
137 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 |
---|---|---|
@@ -1,16 +1,114 @@ | ||
package dump | ||
|
||
import ( | ||
"context" | ||
_ "embed" | ||
"encoding/json" | ||
"errors" | ||
"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/fsadapter" | ||
"github.com/rusq/slackdump/v2/internal/app/config" | ||
"github.com/rusq/slackdump/v2/internal/structures" | ||
"github.com/rusq/slackdump/v2/types" | ||
) | ||
|
||
//go:embed assets/dump.md | ||
var dumpLong string | ||
var mdDump string | ||
|
||
var CmdDump = &base.Command{ | ||
UsageLine: "slackdump dump [flags] <IDs or URLs>", | ||
Short: "dump individual conversations or threads", | ||
Long: base.Render(dumpLong), | ||
UsageLine: "slackdump dump [flags] <IDs or URLs>", | ||
Short: "dump individual conversations or threads", | ||
Long: base.Render(mdDump), | ||
RequireAuth: true, | ||
PrintFlags: true, | ||
} | ||
|
||
var ErrNothingToDo = errors.New("no conversations to dump, seek help") | ||
|
||
type options struct { | ||
Oldest time.Time | ||
Latest time.Time | ||
NameTemplate string | ||
} | ||
|
||
var opts options | ||
|
||
func ptr[T any](a T) *T { | ||
return &a | ||
} | ||
|
||
func init() { | ||
CmdDump.Run = runDump | ||
CmdDump.Flag.Var(ptr(config.TimeValue(opts.Oldest)), "from", "timestamp of the oldest message to fetch") | ||
CmdDump.Flag.Var(ptr(config.TimeValue(opts.Latest)), "to", "timestamp of the newest message to fetch") | ||
CmdDump.Flag.StringVar(&opts.NameTemplate, "ft", "{{.ID}}{{ if .ThreadTS}}-{{.ThreadTS}}{{end}}", "output file naming template.") | ||
} | ||
|
||
func runDump(ctx context.Context, cmd *base.Command, args []string) error { | ||
if len(args) == 0 { | ||
base.SetExitStatus(base.SInvalidParameters) | ||
return ErrNothingToDo | ||
} | ||
|
||
list, err := structures.NewEntityList(args) | ||
if err != nil { | ||
base.SetExitStatus(base.SInvalidParameters) | ||
return err | ||
} | ||
if list.IsEmpty() { | ||
base.SetExitStatus(base.SInvalidParameters) | ||
return ErrNothingToDo | ||
} | ||
|
||
prov, err := auth.FromContext(ctx) | ||
if err != nil { | ||
base.SetExitStatus(base.SApplicationError) | ||
return err | ||
} | ||
|
||
if fs, err := fsadapter.New(cfg.BaseLoc); err != nil { | ||
base.SetExitStatus(base.SApplicationError) | ||
return err | ||
} else { | ||
cfg.SlackOptions.Filesystem = fs | ||
defer fsadapter.Close(fs) | ||
} | ||
|
||
sess, err := slackdump.NewWithOptions(ctx, prov, cfg.SlackOptions) | ||
if err != nil { | ||
base.SetExitStatus(base.SApplicationError) | ||
return err | ||
} | ||
|
||
for _, link := range list.Include { | ||
conv, err := sess.Dump(ctx, link, opts.Oldest, opts.Latest) | ||
if err != nil { | ||
base.SetExitStatus(base.SApplicationError) | ||
return err | ||
} | ||
if err := saveConversation(cfg.SlackOptions.Filesystem, "test.json", conv); err != nil { | ||
return err | ||
} | ||
|
||
} | ||
return nil | ||
} | ||
|
||
func saveConversation(fs fsadapter.FS, filename string, conv *types.Conversation) error { | ||
f, err := fs.Create(filename) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
enc := json.NewEncoder(f) | ||
enc.SetIndent("", " ") | ||
if err := enc.Encode(conv); 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,46 @@ | ||
# v2.3.0 | ||
|
||
## Breaking changes | ||
|
||
- legacy command line interface moved under "v1" command, so if you need to | ||
use the old CLI, instead of `./slackdump`, run `./slackdump v1`. The | ||
legacy CLI will be phased out: deprecated in v2.4.0, and removed in v2.5.0. | ||
- download flag is set to "true" by default. | ||
use the old CLI, instead of `./slackdump`, run `./slackdump v1`. The legacy | ||
CLI will be phased out: deprecated in v2.4.0, and removed in v2.5.0; | ||
- `-download` flag renamed to `-files` and is set to "true" by default; | ||
- `-r` flag that allowed to generate text files was moved to | ||
`slackdump convert` command. | ||
|
||
## New features | ||
|
||
- Completely rewritten CLI, based on `go` command source code (see | ||
[Licenses][1]). | ||
- Default API limits can be overridden with configuration file (use | ||
`-config <file>`). | ||
- Slack Workspaces: | ||
- Slackdump remembers credentials for multiple Slack Workspaces; | ||
- It is possible to select the "_Current_" Workspace using the | ||
`workspace select` command; | ||
- The "_Current_" workspace can be overridden by providing the `-w <name>` flag. | ||
- Slackdump remembers credentials for multiple Slack Workspaces; | ||
- It is possible to select the "_Current_" Workspace using the | ||
`workspace select` command; | ||
- The "_Current_" workspace can be overridden by providing the `-w <name>` | ||
flag. | ||
|
||
## Changes | ||
|
||
- Default output location (**BASE_LOC** environment variable), if not set by the | ||
user, defaults to the ZIP file "slackdump_YYYYMMDD_HHmmSS.zip", where | ||
`YYYYMMDD` is the current date (for example `20221103`) and `HHmmSS` is the | ||
current time with seconds (for example `185803`). | ||
`YYYYMMDD` is the current date (for example `20221103`) and `HHmmSS` is the | ||
current time with seconds (for example `185803`). | ||
|
||
## Licenses | ||
# Library changes | ||
|
||
## Deprecation of Dump* functions | ||
|
||
## Slackdump Core | ||
|
||
- `Options` reorganised, API limits are extracted into a Limits variable. Tier | ||
limits are extracted to TierLimits, and are accessible via `Limits.Tier2` and | ||
`Limits.Tier3` variables. Requests limits are accessible via | ||
`Limits.Request`. | ||
- `Session.SetFS` method is removed, set the filesystem in `Options.Filesystem`. | ||
|
||
## Licenses | ||
|
||
[1]: #licenses | ||
[1]: #licenses |
This file was deleted.
Oops, something went wrong.
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.