/
external.go
102 lines (87 loc) · 2.14 KB
/
external.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package storage
import (
"errors"
"fmt"
"time"
. "github.com/infrago/base"
)
func ThumbnailConfig() string {
return module.config.Thumbnail
}
func PreviewConfig() string {
return module.config.Preview
}
func SaltConfig() string {
return module.config.Salt
}
func Upload(from Any, metadatas ...Map) (File, Files, error) {
path := ""
switch vv := from.(type) {
case string:
path = vv
case Map:
if file, ok := vv["file"].(string); ok {
path = file
} else {
return nil, nil, errors.New("invalid target")
}
default:
path = fmt.Sprintf("%v", vv)
}
var metadata Map
if len(metadatas) > 0 {
metadata = metadatas[0]
}
return module.Upload(path, metadata)
}
func UploadFile(path Any, metadatas ...Map) (File, error) {
file, _, err := Upload(path, metadatas...)
return file, err
}
func UploadPath(path Any, metadatas ...Map) (Files, error) {
_, files, err := Upload(path, metadatas...)
return files, err
}
func UploadTo(base string, from Any, metadatas ...Map) (File, Files, error) {
path := ""
switch vv := from.(type) {
case string:
path = vv
case Map:
if file, ok := vv["file"].(string); ok {
path = file
} else {
return nil, nil, errors.New("invalid target")
}
default:
path = fmt.Sprintf("%v", vv)
}
var metadata Map
if len(metadatas) > 0 {
metadata = metadatas[0]
}
return module.UploadTo(base, path, metadata)
}
func UploadFileTo(base string, path Any, metadatas ...Map) (File, error) {
file, _, err := UploadTo(base, path, metadatas...)
return file, err
}
func UploadPathTo(base string, path Any, metadatas ...Map) (Files, error) {
_, files, err := UploadTo(base, path, metadatas...)
return files, err
}
func Download(code string) (string, error) {
return module.Download(code)
}
func Remove(code string) error {
return module.Remove(code)
}
func Browse(code string, query Map, expires ...time.Duration) (string, error) {
return module.Browse(code, query, expires...)
}
func Thumbnail(code string, width, height, pos int64) (string, error) {
return module.Thumbnail(code, width, height, pos)
}
func Preview(code string, width, height int64) (string, error) {
return module.Preview(code, width, height, 0)
}