/
virtual_fs_api.go
155 lines (107 loc) · 3.73 KB
/
virtual_fs_api.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package rest
/* -- need to get rid of this as FUSE is unlikely to be used in future versions
import (
"fmt"
"net/http"
"github.com/hyper-ml/hyperml/server/pkg/base"
ws "github.com/hyper-ml/hyperml/server/pkg/workspace"
"github.com/hyper-ml/hyperml/server/pkg/base/structs"
)
func (h *Handler) handleListDir() error {
var response map[string]interface{}
repo_name := h.getQuery("repoName")
branch_name := h.getQuery("branchName")
commit_id := h.getQuery("commitId")
dir_path := h.getQuery("path")
base.Info("[Handler.handleListDir]: %s %s %s", repo_name, commit_id, dir_path)
if repo_name == "" {
return base.HTTPErrorf(http.StatusInternalServerError, "Invalid repo param - repoName")
}
if commit_id == "" {
base.Debug("No Commit Id passed. This request will use open commit.")
}
finfo_map, err := h.server.vfsAPI.ListDir(repo_name, branch_name, commit_id, dir_path)
if err != nil {
base.Log("[handleListDir] Failed to retrieve file in dir: %s %s %s %s", repo_name, branch_name, commit_id, dir_path)
return err
}
info_map := &ws.FileAttrsMap{Entries: finfo_map}
if err == nil {
response = structs.Map(info_map)//map[string]interface{} {
// finfo_map, // structs.Map(finfo_map)
//}
} else {
return err
}
fmt.Println("response on handleListDir: ", response)
h.writeJSON(response)
return nil
}
func (h *Handler) handleFileLookup() error {
var response map[string]interface{}
repo_name := h.getQuery("repoName")
branch_name := h.getQuery("branchName")
commit_id := h.getQuery("commitId")
fpath := h.getQuery("path")
if repo_name == "" {
return base.HTTPErrorf(http.StatusInternalServerError, "Invalid repo param - repoName")
}
if branch_name == "" {
base.Warn("[Handler.handleFileLookup] No branch_name passed in request")
}
if commit_id == "" {
base.Warn("[Handler.handleFileLookup] No Commit Id passed. This request will use open commit.")
}
finfo, err := h.server.vfsAPI.Lookup(repo_name, branch_name, commit_id, fpath)
if err != nil {
base.Warn("[Handler.handleFileLookup] Failed to retrieve file in dir: %s %s %s", repo_name, commit_id, fpath)
return err
}
if finfo != nil {
response = structs.Map(finfo)
} else {
//TODO: get last element and check if file. return empty file or error
dummy := ws.NewDirInfo(nil, "", 0)
response = structs.Map(dummy)
}
base.Debug("[Handler.handleFileLookup] Response on handleFileLookup: ", response)
h.writeJSON(response)
return nil
}
func (h *Handler) handleVfsPutFile() error {
if (h.rq.Method != "PUT") {
return base.HTTPErrorf(http.StatusMethodNotAllowed, "handleVfsPutFile(): Invalid method %s", h.rq.Method)
}
var response map[string]interface{}
var file_attrs *ws.FileAttrs
var err error
var written int64
repo_name := h.getQuery("repoName")
branch_name := h.getQuery("branchName")
commit_id := h.getQuery("commitId")
file_path := h.getQuery("path")
object_hash := h.getQuery("hash")
if h.rq.Body == nil {
h.writeJSON(response)
return nil
}
if object_hash == "" {
file_attrs, written, err = h.server.wsAPI.PutFile(repo_name, branch_name, commit_id, file_path, h.rq.Body)
} else {
written, err = h.server.vfsAPI.PutFileByHash(object_hash, h.rq.Body)
}
if err != nil {
base.Error("[Handler.handleVfsPutFile] Failed to write file on to server:", object_hash, repo_name, commit_id, file_path, err)
return base.HTTPErrorf(http.StatusBadRequest, err.Error())
}
response = map[string]interface{}{
"file_attrs" : structs.Map(file_attrs),
"written" : written,
}
h.writeJSON(response)
return nil
}
func (h *Handler) handleVfsGetFile() error {
return h.handleGetObject()
}
*/