fileproc

package
v3.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2025 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package fileproc is the file processor that can be used in conjunction with the transformer. It downloads files to the local filesystem using the provided downloader. Probably it's a good idea to use the downloader.Client for this.

Index

Constants

This section is empty.

Variables

View Source
var StorageTypeFuncs = map[StorageType]func(_ *slack.Channel, f *slack.File) string{
	STmattermost: MattermostFilepath,
	STstandard:   StdFilepath,
	STnone:       func(_ *slack.Channel, f *slack.File) string { return "" },
}

Functions

func AvatarPath added in v3.0.4

func AvatarPath(u *slack.User) string

func DumpFilepath

func DumpFilepath(ci *slack.Channel, f *slack.File) string

func ExportTokenUpdateFn

func ExportTokenUpdateFn(token string) func(msg *slack.Message) error

ExportTokenUpdateFn returns a function that appends the token to every file URL in the given message.

func IsValid

func IsValid(f *slack.File) bool

IsValid returns true if the file can be downloaded and is valid.

func IsValidWithReason

func IsValidWithReason(f *slack.File) error

func MattermostFilepath

func MattermostFilepath(_ *slack.Channel, f *slack.File) string

MattermostFilepath returns the path to the file within the __uploads directory.

func MattermostFilepathWithDir

func MattermostFilepathWithDir(dir string) func(*slack.Channel, *slack.File) string

MattermostFilepathWithDir returns the path to the file within the given directory, but it follows the mattermost naming pattern.

func New added in v3.0.4

func New(dl Downloader) processor.Filer

New creates a new file processor that uses mattermost file naming pattern.

func NewExport

func NewExport(typ StorageType, dl Downloader) processor.Filer

NewExport initialises an export file subprocessor based on the given export type. This subprocessor can be later plugged into the [expproc.Conversations] processor.

func StdFilepath

func StdFilepath(ci *slack.Channel, f *slack.File) string

Types

type AvatarProc added in v3.0.4

type AvatarProc struct {
	// contains filtered or unexported fields
}

func NewAvatarProc added in v3.0.4

func NewAvatarProc(dl Downloader) AvatarProc

func (AvatarProc) Avatars added in v3.0.4

func (a AvatarProc) Avatars(ctx context.Context, users []slack.User) error

func (AvatarProc) Close added in v3.0.4

func (a AvatarProc) Close() error

type Downloader

type Downloader interface {
	// Download should download the file at the given URL and save it to the
	// given path.
	Download(fullpath string, url string) error
	Stop()
}

Downloader is the interface that wraps the Download method.

func NewDownloader

func NewDownloader(ctx context.Context, enabled bool, cl FileGetter, fsa fsadapter.FS, lg *slog.Logger) (sdl Downloader)

NewDownloader initializes the downloader and returns it, along with a function that should be called to stop it.

type FileGetter

type FileGetter interface {
	// GetFile retrieves a given file from its private download URL
	GetFileContext(ctx context.Context, downloadURL string, writer io.Writer) error
}

type FileProcessor added in v3.0.4

type FileProcessor struct {
	// contains filtered or unexported fields
}

FileProcessor is the file processor, that downloads files to the path returned by the filepath function. Zero value of this type is not usable.

func NewDump added in v3.0.4

func NewDump(dl Downloader) FileProcessor

NewDump returns a new Dump File FileProcessor.

func NewWithPathFn added in v3.0.4

func NewWithPathFn(dl Downloader, fp func(ci *slack.Channel, f *slack.File) string) FileProcessor

NewWithPathFn initialises the file processor.

func (FileProcessor) Close added in v3.0.4

func (b FileProcessor) Close() error

func (FileProcessor) Files added in v3.0.4

func (b FileProcessor) Files(_ context.Context, channel *slack.Channel, _ slack.Message, ff []slack.File) error

func (FileProcessor) PathUpdateFunc added in v3.0.4

func (b FileProcessor) PathUpdateFunc(channelID, threadTS string, mm []slack.Message) error

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.

type NoopDownloader

type NoopDownloader struct{}

func (NoopDownloader) Download

func (NoopDownloader) Download(fullpath string, url string) error

func (NoopDownloader) Stop added in v3.0.4

func (NoopDownloader) Stop()

type StorageType

type StorageType uint8
const (
	STnone StorageType = iota
	// STstandard is the storage type for the standard file storage.
	STstandard
	// STmattermost is the storage type for Mattermost.
	STmattermost
)

func (*StorageType) Set

func (e *StorageType) Set(v string) error

Set translates the string value into the ExportType, satisfies flag.Value interface. It is based on the declarations generated by stringer.

func (StorageType) String

func (i StorageType) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL