Skip to content

Commit

Permalink
record->archive, auth->workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Apr 2, 2024
1 parent 7f84890 commit 421e4f4
Show file tree
Hide file tree
Showing 17 changed files with 736 additions and 60 deletions.
33 changes: 33 additions & 0 deletions cmd/slackdump/internal/archive/assets/record.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Archive Command

The archive command archives the Slack workspace into a directory of files.
By default, it will perform the archiving of the full workspace that is accessible
to your user.

Optionally, one can select channels, groups and DMs to archive. For this, one
needs to specify the URLs or IDs of the channels.

The workspace is archived in the "Chunk" format, that can be viewed with the
`view` command, or converted to other supported formats, such as native Slack
Export format.

## What is contained in the archive?

"Archive" behaves similarly to the Slackdump export feature, the output of a
successful run contains the following:
- channels.json.gz - list of channels in the workspace (full archives only);
- users.json.gz - list of users in the workspace;
- CXXXXXXX.json.gz - channel or group conversation messages, where XXXXXXX is
the channel ID;
- DXXXXXXX.json.gz - direct messages, where XXXXXXX is the user ID;

Output format:

- Each file is a JSONL file compressed with GZIP.

Please note that "archive" can not create ZIP files, but you can zip the output
directory manually.

## What is chunk file format?

Run `slackdump help chunk` for the format specification.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package record
package archive

import (
"context"
Expand All @@ -19,13 +19,13 @@ import (
)

//go:embed assets/record.md
var mdRecord string
var mdArchive string

var CmdRecord = &base.Command{
Run: RunRecord,
UsageLine: "slackdump record [flags] [link1[ link 2[ link N]]]",
Short: "record the dump of the workspace or individual conversations",
Long: mdRecord,
UsageLine: "slackdump archive [flags] [link1[ link 2[ link N]]]",
Short: "archive the workspace or individual conversations on disk",
Long: mdArchive,
FlagMask: cfg.OmitUserCacheFlag | cfg.OmitCacheDir,
RequireAuth: true,
PrintFlags: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package record
package archive

import (
"context"
Expand Down
4 changes: 2 additions & 2 deletions cmd/slackdump/internal/diag/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (

"github.com/rusq/slack"
"github.com/rusq/slackdump/v3/auth"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/archive"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/record"
"github.com/rusq/slackdump/v3/internal/chunk"
"github.com/rusq/slackdump/v3/internal/chunk/dirproc"
"github.com/rusq/slackdump/v3/internal/network"
Expand Down Expand Up @@ -141,7 +141,7 @@ func runSearchConvert(ctx context.Context, _ *base.Command, args []string) error
defer f.Close()
r = f
}
cfg.Output = record.StripZipExt(cfg.Output)
cfg.Output = archive.StripZipExt(cfg.Output)
if cfg.Output == "" {
return errors.New("output is empty")
}
Expand Down
25 changes: 0 additions & 25 deletions cmd/slackdump/internal/record/assets/record.md

This file was deleted.

7 changes: 7 additions & 0 deletions cmd/slackdump/internal/view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"path"
"strings"

br "github.com/pkg/browser"
"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"
Expand Down Expand Up @@ -65,6 +66,11 @@ func RunView(ctx context.Context, cmd *base.Command, args []string) error {
lg := logger.FromContext(ctx)

lg.Printf("listening on %s", listenAddr)
go func() {
if err := br.OpenURL(fmt.Sprintf("http://%s", listenAddr)); err != nil {
lg.Printf("unable to open browser: %s", err)
}
}()
if err := v.ListenAndServe(); err != nil {
if errors.Is(err, http.ErrServerClosed) {
lg.Print("bye")
Expand All @@ -73,6 +79,7 @@ func RunView(ctx context.Context, cmd *base.Command, args []string) error {
base.SetExitStatus(base.SApplicationError)
return err
}

return nil
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package authcmd
package workspace

import (
"context"
Expand All @@ -14,31 +14,31 @@ import (
"github.com/rusq/slackdump/v3/internal/cache"
)

const baseCommand = "slackdump auth"
const baseCommand = "slackdump workspace"

var flagmask = cfg.OmitAll

var CmdWorkspace = &base.Command{
Run: nil,
Wizard: nil,
UsageLine: baseCommand,
Short: "authenticate or choose already authenticated workspace to run on",
Short: "add or choose already existing workspace to run on",
Long: `
# Auth Command
# Workspace Command
Slackdump supports working with multiple Slack Workspaces without the need
to authenticate again (unless login credentials are expired or became invalid
due to some other reason).
**Auth** command allows to authenticate in a **new** Slack Workspace,
**list** already authenticated workspaces, **select** a workspace that you have
previously logged in to, or **del**ete an existing workspace.
**Workspace** command allows to **add** a new Slack Workspace, **list** already
authenticated workspaces, **select** a workspace that you have previously
logged in to, or **del**ete an existing workspace.
To learn more about different login options, run:
slackdump help auth
slackdump help workspace
Workspaces are stored on this device in the Cache directory, which is
Workspaces are stored on this device in the system Cache directory, which is
automatically detected to be:
` + cfg.CacheDir() + `
`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package authcmd
package workspace

import "testing"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package authcmd
package workspace

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package authcmd
package workspace

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package authcmd
package workspace

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package authcmd
package workspace

import (
"context"
Expand Down
12 changes: 6 additions & 6 deletions cmd/slackdump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

"github.com/rusq/slackdump/v3/auth"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/apiconfig"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/authcmd"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/archive"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/convertcmd"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/diag"
Expand All @@ -30,9 +30,9 @@ import (
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/help"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/list"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/man"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/record"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/view"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/wizard"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/workspace"
"github.com/rusq/slackdump/v3/logger"
)

Expand All @@ -43,12 +43,12 @@ func init() {
wizard.CmdWizard,
export.CmdExport,
dump.CmdDump,
record.CmdRecord,
record.CmdSearch,
archive.CmdRecord,
archive.CmdSearch,
convertcmd.CmdConvert,
list.CmdList,
emoji.CmdEmoji,
authcmd.CmdWorkspace,
workspace.CmdWorkspace,
diag.CmdDiag,
apiconfig.CmdConfig,
format.CmdFormat,
Expand Down Expand Up @@ -183,7 +183,7 @@ func invoke(cmd *base.Command, args []string) error {
if cmd.RequireAuth {
trace.Logf(ctx, "invoke", "command %s requires auth", cmd.Name())
var err error
prov, err := authcmd.AuthCurrent(ctx, cfg.CacheDir(), cfg.Workspace, cfg.LegacyBrowser)
prov, err := workspace.AuthCurrent(ctx, cfg.CacheDir(), cfg.Workspace, cfg.LegacyBrowser)
if err != nil {
trace.Logf(ctx, "invoke", "auth error: %s", err)
base.SetExitStatus(base.SAuthError)
Expand Down
Loading

0 comments on commit 421e4f4

Please sign in to comment.