Skip to content

Commit

Permalink
feat(api): init fsi endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
b5 committed Jul 26, 2019
1 parent 56fae3b commit 7613302
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ func NewServerRoutes(s Server) *http.ServeMux {
m.Handle("/fsi/", s.middleware(fsih.DatasetHandler))
m.Handle("/fsi/body/", s.middleware(fsih.BodyHandler))
m.Handle("/fsi/save/", s.middleware(fsih.SaveHandler))
m.Handle("/fsi/init/", s.middleware(fsih.InitHandler))

renderh := NewRenderHandlers(node.Repo)
m.Handle("/render/", s.middleware(renderh.RenderHandler))
Expand Down
33 changes: 33 additions & 0 deletions api/fsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,36 @@ func (h *FSIHandlers) saveHandler(w http.ResponseWriter, r *http.Request) {

util.WriteResponse(w, res)
}

// InitHandler creates a new FSI-linked dataset
func (h *FSIHandlers) InitHandler(w http.ResponseWriter, r *http.Request) {
if h.ReadOnly {
readOnlyResponse(w, "/fsi/init")
return
}

switch r.Method {
case "OPTIONS":
util.EmptyOkHandler(w, r)
case "POST":
h.initHandler(w, r)
default:
util.NotFoundHandler(w, r)
}
}

func (h *FSIHandlers) initHandler(w http.ResponseWriter, r *http.Request) {
p := &lib.InitFSIDatasetParams{
Filepath: r.FormValue("filepath"),
Name: r.FormValue("name"),
Format: r.FormValue("format"),
}

var name string
if err := h.InitDataset(p, &name); err != nil {
util.WriteErrResponse(w, http.StatusBadRequest, err)
return
}

util.WriteResponse(w, map[string]string{"ref": name})
}

0 comments on commit 7613302

Please sign in to comment.