2024-03-27 14:20:45 +00:00
|
|
|
// Package uploader defines the interface to implement when building
|
|
|
|
// uploaders
|
|
|
|
package uploader
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/Luzifer/go_helpers/v2/fieldcollection"
|
|
|
|
"github.com/cheggaaa/pb/v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
2024-04-01 11:02:07 +00:00
|
|
|
// Uploader defines the interface to implement on new uploaders
|
2024-03-27 14:20:45 +00:00
|
|
|
Uploader interface {
|
2024-04-01 11:02:07 +00:00
|
|
|
// Prepare is used to check authorizations, re-authorize uploaders
|
|
|
|
// and do preflight-checks in before the real upload is started
|
|
|
|
Prepare(ctx context.Context, opts Opts) error
|
|
|
|
// UploadFile is executed after Prepare and ValidateConfig and
|
|
|
|
// can concentrate on uploading the file to the respective target
|
|
|
|
UploadFile(ctx context.Context, opts Opts) error
|
|
|
|
// ValidateConfig is called before Prepare and UploadFile and
|
|
|
|
// must make sure the settings given are complete and valid
|
2024-03-27 14:20:45 +00:00
|
|
|
ValidateConfig(config *fieldcollection.FieldCollection) error
|
|
|
|
}
|
|
|
|
|
2024-04-01 11:02:07 +00:00
|
|
|
// Opts contains the require arguments for an Uploader
|
|
|
|
// to do its job
|
|
|
|
Opts struct {
|
2024-03-27 14:20:45 +00:00
|
|
|
Name string
|
|
|
|
Config *fieldcollection.FieldCollection
|
|
|
|
|
|
|
|
Filename string
|
|
|
|
Content io.Reader
|
|
|
|
Size int64
|
|
|
|
|
|
|
|
ProgressBar *pb.ProgressBar
|
|
|
|
FinalMessage func(format string, opts ...any)
|
|
|
|
}
|
|
|
|
)
|