-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api.FSI): initial FSI api methods
- Loading branch information
Showing
6 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
util "github.com/qri-io/apiutil" | ||
"github.com/qri-io/qri/lib" | ||
) | ||
|
||
|
||
// FSIHandlers connects HTTP requests to the FSI subsystem | ||
type FSIHandlers struct { | ||
lib.FSIMethods | ||
ReadOnly bool | ||
} | ||
|
||
// NewFSIHandlers creates handlers that talk to qri's filesystem integration | ||
func NewFSIHandlers(inst *lib.Instance, readOnly bool) FSIHandlers { | ||
return FSIHandlers{ | ||
FSIMethods: *lib.NewFSIMethods(inst), | ||
ReadOnly: readOnly, | ||
} | ||
} | ||
|
||
|
||
// StatusHandler is the endpoint for getting the status of a linked dataset | ||
func (h *FSIHandlers) StatusHandler(w http.ResponseWriter, r *http.Request) { | ||
switch r.Method { | ||
case "OPTIONS": | ||
util.EmptyOkHandler(w, r) | ||
case "GET": | ||
if h.ReadOnly { | ||
readOnlyResponse(w, "/status") | ||
return | ||
} | ||
h.statusHandler(w, r) | ||
case "POST": | ||
h.statusHandler(w, r) | ||
default: | ||
util.NotFoundHandler(w, r) | ||
} | ||
} | ||
|
||
func (h *FSIHandlers) statusHandler(w http.ResponseWriter, r *http.Request) { | ||
ref, err := DatasetRefFromPath(r.URL.Path[len("/dsstatus"):]) | ||
if err != nil { | ||
util.WriteErrResponse(w, http.StatusBadRequest, fmt.Errorf("bad reference: %s", err.Error())) | ||
return | ||
} | ||
|
||
alias := ref.AliasString() | ||
res := []lib.StatusItem{} | ||
if err = h.AliasStatus(&alias, &res); err != nil { | ||
util.WriteErrResponse(w, http.StatusInternalServerError, fmt.Errorf("error getting status: %s", err.Error())) | ||
return | ||
} | ||
util.WriteResponse(w, res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters