-
-
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
10 changed files
with
88 additions
and
109 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
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,56 +1,20 @@ | ||
package fileproc | ||
|
||
import ( | ||
"context" | ||
"path/filepath" | ||
|
||
"github.com/rusq/slackdump/v2/internal/chunk" | ||
"github.com/rusq/slackdump/v2/internal/structures/files" | ||
"github.com/slack-go/slack" | ||
) | ||
|
||
// DumpSubproc is a file subprocessor that downloads all files to the local | ||
// filesystem using underlying downloader. | ||
type DumpSubproc struct { | ||
baseSubproc | ||
} | ||
|
||
// NewDumpSubproc returns a new Dump File Subprocessor. | ||
func NewDumpSubproc(dl Downloader) DumpSubproc { | ||
return DumpSubproc{ | ||
baseSubproc: baseSubproc{ | ||
dcl: dl, | ||
}, | ||
} | ||
} | ||
|
||
func (d DumpSubproc) Files(ctx context.Context, channel *slack.Channel, m slack.Message, ff []slack.File) error { | ||
for _, f := range ff { | ||
if !isDownloadable(&f) { | ||
continue | ||
} | ||
if err := d.dcl.Download(d.filepath(channel.ID, &f), f.URLPrivateDownload); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// PathUpdateFunc updates the path in URLDownload and URLPrivateDownload of every | ||
// file in the given message slice to point to the physical downloaded file | ||
// location. It can be plugged in the pipeline of Dump. | ||
func (d DumpSubproc) PathUpdateFunc(channelID, threadTS string, mm []slack.Message) error { | ||
for i := range mm { | ||
for j := range mm[i].Files { | ||
path := d.filepath(channelID, &mm[i].Files[j]) | ||
if err := files.UpdatePathFn(path)(&mm[i].Files[j]); err != nil { | ||
return err | ||
} | ||
} | ||
func NewDumpSubproc(dl Downloader) Subprocessor { | ||
return Subprocessor{ | ||
dcl: dl, | ||
filepath: DumpFilepath, | ||
} | ||
return nil | ||
} | ||
|
||
func (d DumpSubproc) filepath(channelID string, f *slack.File) string { | ||
return filepath.Join(chunk.ToFileID(channelID, "", false).String(), f.ID+"-"+f.Name) | ||
func DumpFilepath(ci *slack.Channel, f *slack.File) string { | ||
return filepath.Join(chunk.ToFileID(ci.ID, "", false).String(), f.ID+"-"+f.Name) | ||
} |
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