2023-08-27 21:30:19 +02:00
|
|
|
package backblaze
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/kurin/blazer/b2"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type BackBlaze struct {
|
2023-10-01 14:35:50 +02:00
|
|
|
logger *logrus.Logger
|
|
|
|
b2Client *b2.Client
|
|
|
|
bbID string
|
|
|
|
bbKey string
|
|
|
|
options BackBlazeOptions
|
2023-08-27 21:30:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewBackBlaze initializes a new BackBlaze struct with given BackBlaze ID and Key.
|
|
|
|
func NewBackBlaze(ctx context.Context, logger *logrus.Logger, bbID, bbKey string) (*BackBlaze, error) {
|
|
|
|
b2Client, err := b2.NewClient(ctx, bbID, bbKey)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("b2.NewClient %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &BackBlaze{
|
2023-10-01 14:35:50 +02:00
|
|
|
logger: logger,
|
|
|
|
b2Client: b2Client,
|
|
|
|
bbID: bbID,
|
|
|
|
bbKey: bbKey,
|
2023-08-27 21:30:19 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-10-01 14:35:50 +02:00
|
|
|
type BackBlazeOptions struct {
|
|
|
|
Bucket string
|
|
|
|
Dir string
|
|
|
|
FilePath string
|
|
|
|
MaxWorkers int
|
|
|
|
ConcurrentUploads int
|
2023-08-27 21:30:19 +02:00
|
|
|
}
|
2023-10-01 14:35:50 +02:00
|
|
|
|
|
|
|
func (b *BackBlaze) WithOptions(options BackBlazeOptions) *BackBlaze {
|
|
|
|
b.options = options
|
2023-08-27 21:30:19 +02:00
|
|
|
return b
|
|
|
|
}
|