transform

package
v3.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("transformer is closed")

Functions

func ExportChanName

func ExportChanName(ch *slack.Channel) string

ExportChanName returns the channel name, or the channel ID if it is a DM.

Types

type COption

type COption func(*Coordinator)

func WithIDChan

func WithIDChan(idC chan chunk.FileID) COption

WithIDChan allows to use an external ID channel.

type Converter

type Converter interface {
	// Convert should convert the chunk to the Converters' output format.
	Convert(ctx context.Context, id chunk.FileID) error
}

Converter is the interface that defines a set of methods for transforming chunks to some output format.

type Coordinator

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

Coordinator coordinates the conversion of chunk files to the desired format. It is used to convert files in parallel.

func NewCoordinator

func NewCoordinator(ctx context.Context, cvt Converter, opts ...COption) *Coordinator

NewCoordinator creates a new Coordinator.

func (*Coordinator) Transform

func (s *Coordinator) Transform(ctx context.Context, id chunk.FileID) error

func (*Coordinator) Wait

func (s *Coordinator) Wait() (err error)

Wait closes the transformer.

type ExpConverter

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

func NewExpConverter

func NewExpConverter(cd *chunk.Directory, fsa fsadapter.FS, opt ...ExpCvtOption) *ExpConverter

func (*ExpConverter) Convert

func (e *ExpConverter) Convert(ctx context.Context, id chunk.FileID) error

Convert is the chunk file export converter. It transforms the chunk file for the channel with ID into a slack export format. It expects the chunk file to be in the <srcdir>/<id>.json.gz file, and the attachments to be in the <srcdir>/<id> directory.

func (*ExpConverter) HasUsers

func (t *ExpConverter) HasUsers() bool

func (*ExpConverter) SetUsers

func (e *ExpConverter) SetUsers(users []slack.User)

func (*ExpConverter) WriteIndex

func (t *ExpConverter) WriteIndex() error

WriteIndex generates and writes the export index files. It must be called once all transformations are done, because it might require to read channel files.

type ExpCvtOption

type ExpCvtOption func(*ExpConverter)

func ExpWithMsgUpdateFunc

func ExpWithMsgUpdateFunc(fn ...func(*slack.Channel, *slack.Message) error) ExpCvtOption

func ExpWithUsers

func ExpWithUsers(users []slack.User) ExpCvtOption

type ExpOption

type ExpOption func(*ExportCoordinator)

ExpOption is a function that configures the Export instance.

func WithBufferSize

func WithBufferSize(n int) ExpOption

WithBufferSize sets the size of the channel IDs buffer. This is the number of channel IDs that will be queued without blocking before the transform.Export is started.

func WithUsers

func WithUsers(users []slack.User) ExpOption

WithUsers allows to pass a list of users to the transform.

type ExportCoordinator

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

ExportCoordinator is a takes the chunks produced by the processor and transforms them into a Slack Export format. It is suitable for async processing, in which case, OnFinalise function is passed to the processor, the finalisation requests will be queued (up to a [bufferSz]) and will be processed once Start or StartWithUsers is called.

Please note, that transform requires users to be passed either through options or through StartWithUsers. If users are not passed, the ExportCoordinator.Start will return an error.

The asynchronous pattern to run the transform is as follows:

  1. Create the transform instance.
  2. Defer its Close method.
  3. In goroutine: Start user processing, and in the same goroutine, after all users are fetched, call ExportCoordinator.StartWithUsers, passing the fetched users slice.
  4. In another goroutine, start the ExportCoordinator Conversation processor, passing the transformer's OnFinalise function as the Finaliser option. It will be called by export processor for each channel that was completed.

func NewExportCoordinator

func NewExportCoordinator(ctx context.Context, cvt UserConverter, tfopt ...ExpOption) *ExportCoordinator

NewExportCoordinator creates a new ExportCoordinator instance.

func (*ExportCoordinator) Close

func (t *ExportCoordinator) Close() (err error)

Close closes the coordinator. It must be called once it is guaranteed that [Transform] will not be called anymore, otherwise the call to Transform will panic with "send on the closed channel". If the coordinator is already closed, it will return nil.

func (*ExportCoordinator) Start

func (t *ExportCoordinator) Start(ctx context.Context) error

Start starts the coordinator, the users must have been initialised with the WithUsers option. Otherwise, use ExportCoordinator.StartWithUsers method. The function doesn't check if coordinator was already started or not.

func (*ExportCoordinator) StartWithUsers

func (t *ExportCoordinator) StartWithUsers(ctx context.Context, users []slack.User) error

StartWithUsers starts the Transform processor with the provided list of users. Users are used to populate each message with the user profile, as per Slack original export format.

func (*ExportCoordinator) Transform

func (t *ExportCoordinator) Transform(ctx context.Context, id chunk.FileID) error

Transform is the function that should be passed to the Channel processor. It will not block if the internal buffer is full. Buffer size can be set with the WithBufferSize option. The caller is allowed to call OnFinalise even if the processor is not started, in which case the channel ID will be queued for processing once the processor is started. If the export worker is closed, it will return ErrClosed.

type StdConverter

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

StdConverter is a converter of chunk files into the Slackdump format.

func NewStandard

func NewStandard(fsa fsadapter.FS, cd *chunk.Directory, opts ...StdOption) (*StdConverter, error)

NewStandard creates a new standard dump converter.

func (*StdConverter) Convert

func (s *StdConverter) Convert(ctx context.Context, id chunk.FileID) error

Convert converts the chunk file to Slackdump json format.

type StdOption

type StdOption func(*StdConverter)

func StdWithLogger

func StdWithLogger(log *slog.Logger) StdOption

func StdWithPipeline

func StdWithPipeline(f ...func(channelID string, threadTS string, mm []slack.Message) error) StdOption

StdWithPipeline adds a pipeline function to the transformer, that will be called for each message slice, before it is written to the filesystem.

func StdWithTemplate

func StdWithTemplate(tmpl Templater) StdOption

type Templater

type Templater interface {
	Execute(c *types.Conversation) string
}

type UserConverter

type UserConverter interface {
	Converter
	SetUsers([]slack.User)
	HasUsers() bool
}

Directories

Path Synopsis
Package fileproc is the file processor that can be used in conjunction with the transformer.
Package fileproc is the file processor that can be used in conjunction with the transformer.

Jump to

Keyboard shortcuts

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