/
internal.go
72 lines (56 loc) · 1.46 KB
/
internal.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package storage
import (
"time"
. "github.com/infrago/base"
)
func (this *Module) UploadTo(base string, path string, metadata Map) (File, Files, error) {
if inst, ok := this.instances[base]; ok {
return inst.connect.Upload(path, metadata)
}
return nil, nil, errInvalidConnection
}
func (this *Module) Upload(path string, metadata Map) (File, Files, error) {
//这里自动分配一个存储
base := this.hashring.Locate(path)
return this.UploadTo(base, path, metadata)
}
func (this *Module) Download(code string) (string, error) {
info, err := decode(code)
if err != nil {
return "", errInvalidCode
}
if inst, ok := this.instances[info.Base()]; ok {
file, err := inst.connect.Download(info)
if err != nil {
return "", err
}
// info.file = file
// info.name = path.Base(info.file)
return file, nil
}
return "", errInvalidConnection
}
func (this *Module) Remove(code string) error {
info, err := decode(code)
if err != nil {
return errInvalidCode
}
if inst, ok := this.instances[info.Base()]; ok {
return inst.connect.Remove(info)
}
return errInvalidConnection
}
func (this *Module) Browse(code string, query Map, expires ...time.Duration) (string, error) {
exp := time.Duration(0)
if len(expires) > 0 {
exp = expires[0]
}
info, err := decode(code)
if err != nil {
return "", errInvalidCode
}
if inst, ok := this.instances[info.Base()]; ok {
return inst.connect.Browse(info, query, exp)
}
return "", errInvalidConnection
}