-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupload.go
More file actions
46 lines (39 loc) · 1.09 KB
/
upload.go
File metadata and controls
46 lines (39 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package mobile
import (
"bytes"
"context"
"io"
beelite "github.com/Solar-Punk-Ltd/bee-lite"
"github.com/ethersphere/bee/v2/pkg/file/redundancy"
"github.com/ethersphere/bee/v2/pkg/swarm"
)
type UploadManager struct {
beeClient *beelite.Beelite
}
func NewUploadManager(beeClient *beelite.Beelite) *UploadManager {
return &UploadManager{beeClient: beeClient}
}
func (um *UploadManager) Upload(batchIdHex, filename, contentType string,
act bool,
historyAddress swarm.Address,
encrypt bool,
rLevel byte,
reader []byte) (reference swarm.Address, newHistoryAddress swarm.Address, err error) {
byteReader := bytes.NewReader(reader)
redundancyLevel := getRedundancyLevel(rLevel)
return um.beeClient.AddFileBzz(context.Background(), batchIdHex, filename, contentType, act, historyAddress, encrypt, redundancyLevel, io.Reader(byteReader))
}
func getRedundancyLevel(rLevel byte) redundancy.Level {
switch rLevel {
case 1:
return redundancy.MEDIUM
case 2:
return redundancy.STRONG
case 3:
return redundancy.INSANE
case 4:
return redundancy.PARANOID
default:
return redundancy.NONE
}
}