-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathdir.go
41 lines (36 loc) · 1.02 KB
/
dir.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
package elevengo
import (
"context"
"os"
"strings"
"github.com/deadblue/elevengo/lowlevel/api"
)
// DirMake makes directory under parentId, and returns its ID.
func (a *Agent) DirMake(parentId string, name string) (dirId string, err error) {
spec := (&api.DirCreateSpec{}).Init(parentId, name)
if err = a.llc.CallApi(spec, context.Background()); err == nil {
dirId = spec.Result
}
return
}
// DirSetOrder sets how files under the directory be ordered.
func (a *Agent) DirSetOrder(dirId string, order FileOrder, asc bool) (err error) {
spec := (&api.DirSetOrderSpec{}).Init(
dirId, getOrderName(order), asc,
)
return a.llc.CallApi(spec, context.Background())
}
// DirGetId retrieves directory ID from full path.
func (a *Agent) DirGetId(path string) (dirId string, err error) {
path = strings.TrimPrefix(path, "/")
spec := (&api.DirLocateSpec{}).Init(path)
if err = a.llc.CallApi(spec, context.Background()); err != nil {
return
}
if spec.Result == "0" {
err = os.ErrNotExist
} else {
dirId = spec.Result
}
return
}