working commit
This commit is contained in:
+4
-1
@@ -108,6 +108,9 @@ func (hand *Handler) DeleteFile(rctx *router.Context) {
|
||||
func (hand *Handler) ListFiles(rctx *router.Context) {
|
||||
|
||||
filepath, _ := rctx.GetSubpath("filepath")
|
||||
if filepath == "" {
|
||||
filepath = "/"
|
||||
}
|
||||
params := &operator.ListFilesParams{
|
||||
Filepath: filepath,
|
||||
}
|
||||
@@ -119,5 +122,5 @@ func (hand *Handler) ListFiles(rctx *router.Context) {
|
||||
rctx.SetStatus(code)
|
||||
return
|
||||
}
|
||||
rctx.SendJSON(code, res)
|
||||
rctx.SendJSON(code, res.Files)
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"mstore/app/operator"
|
||||
"mstore/app/router"
|
||||
)
|
||||
@@ -19,6 +17,5 @@ import (
|
||||
func (hand *Handler) SendHello(rctx *router.Context) {
|
||||
params := &operator.SendHelloParams{}
|
||||
res, _ := hand.oper.SendHello(params)
|
||||
rctx.SetStatus(http.StatusOK)
|
||||
hand.SendResult(rctx, res)
|
||||
}
|
||||
|
||||
@@ -253,13 +253,13 @@ type ListFilesParams struct {
|
||||
Filepath string
|
||||
}
|
||||
type ListFilesResult struct {
|
||||
FileDescrs []descr.File
|
||||
Files []descr.File `json:"files,omitempty"`
|
||||
}
|
||||
|
||||
func (oper *Operator) ListFiles(ctx context.Context, param *ListFilesParams) (int, *ListFilesResult, error) {
|
||||
var err error
|
||||
res := &ListFilesResult{
|
||||
FileDescrs: make([]descr.File, 0),
|
||||
Files: make([]descr.File, 0),
|
||||
}
|
||||
|
||||
// TODO: convert file path to a unified and secure state
|
||||
@@ -276,7 +276,7 @@ func (oper *Operator) ListFiles(ctx context.Context, param *ListFilesParams) (in
|
||||
return code, res, err
|
||||
}
|
||||
for _, item := range fileDescrs {
|
||||
res.FileDescrs = append(res.FileDescrs, item)
|
||||
res.Files = append(res.Files, item)
|
||||
}
|
||||
code := http.StatusOK
|
||||
return code, res, err
|
||||
|
||||
@@ -70,15 +70,16 @@ func (svc *Service) Build() error {
|
||||
svc.rout.Use(router.NewCorsMiddleware())
|
||||
svc.rout.Use(svc.hand.AuthMiddleware)
|
||||
|
||||
svc.rout.Get("/v3/api/service/hello", svc.hand.SendHello)
|
||||
svc.rout.Get(`/v3/api/service/hello`, svc.hand.SendHello)
|
||||
|
||||
svc.rout.Head("/v3/api/file/{filepath}", svc.hand.FileExists)
|
||||
svc.rout.Put("/v3/api/file/{filepath}", svc.hand.PutFile)
|
||||
svc.rout.Get("/v3/api/file/{filepath}", svc.hand.GetFile)
|
||||
svc.rout.Delete("/v3/api/file/{filepath}", svc.hand.DeleteFile)
|
||||
svc.rout.Get("/v3/api/files/{filepath}", svc.hand.ListFiles)
|
||||
svc.rout.Head(`/v3/api/file/{filepath}`, svc.hand.FileExists)
|
||||
svc.rout.Put(`/v3/api/file/{filepath}`, svc.hand.PutFile)
|
||||
svc.rout.Get(`/v3/api/file/{filepath}`, svc.hand.GetFile)
|
||||
svc.rout.Delete(`/v3/api/file/{filepath}`, svc.hand.DeleteFile)
|
||||
svc.rout.Get(`/v3/api/files/{filepath}`, svc.hand.ListFiles)
|
||||
svc.rout.Get(`/v3/api/files/`, svc.hand.ListFiles)
|
||||
|
||||
svc.rout.Get("/v2/", svc.hand.GetVersion)
|
||||
svc.rout.Get(`/v2/`, svc.hand.GetVersion)
|
||||
|
||||
svc.rout.Head(`/v2/{name}/manifests/{reference}`, svc.hand.ManifestExists)
|
||||
svc.rout.Put(`/v2/{name}/manifests/{reference}`, svc.hand.PutManifest)
|
||||
|
||||
Reference in New Issue
Block a user