pinsvcapi: fix some basic bugs
This commit is contained in:
parent
333b933cd3
commit
ab33ec668c
|
@ -25,7 +25,7 @@ func init() {
|
||||||
// occurs. It implements the error interface.
|
// occurs. It implements the error interface.
|
||||||
type APIError struct {
|
type APIError struct {
|
||||||
Reason string `json:"reason"`
|
Reason string `json:"reason"`
|
||||||
Details string `json:"string"`
|
Details string `json:"details"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (apiErr APIError) Error() string {
|
func (apiErr APIError) Error() string {
|
||||||
|
@ -180,13 +180,16 @@ type ListOptions struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lo *ListOptions) FromQuery(q url.Values) error {
|
func (lo *ListOptions) FromQuery(q url.Values) error {
|
||||||
for _, cstr := range strings.Split(q.Get("cid"), ",") {
|
cidq := q.Get("cid")
|
||||||
|
if len(cidq) > 0 {
|
||||||
|
for _, cstr := range strings.Split(cidq, ",") {
|
||||||
c, err := cid.Decode(cstr)
|
c, err := cid.Decode(cstr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error decoding cid %s: %w", cstr, err)
|
return fmt.Errorf("error decoding cid %s: %w", cstr, err)
|
||||||
}
|
}
|
||||||
lo.Cids = append(lo.Cids, c)
|
lo.Cids = append(lo.Cids, c)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lo.Name = q.Get("name")
|
lo.Name = q.Get("name")
|
||||||
lo.Match = MatchFromString(q.Get("match"))
|
lo.Match = MatchFromString(q.Get("match"))
|
||||||
|
|
|
@ -109,9 +109,8 @@ func globalPinInfoToSvcPinStatus(
|
||||||
|
|
||||||
status.Info = map[string]string{
|
status.Info = map[string]string{
|
||||||
"source": "IPFS cluster API",
|
"source": "IPFS cluster API",
|
||||||
"warning1": "disregard created time",
|
"warning1": "CID used for requestID. Conflicts possible",
|
||||||
"warning2": "CID used for requestID. Conflicts possible",
|
"warning2": "experimental",
|
||||||
"warning3": "experimental",
|
|
||||||
}
|
}
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
@ -144,6 +143,12 @@ func NewAPIWithHost(ctx context.Context, cfg *Config, h host.Host) (*API, error)
|
||||||
func (api *API) routes(c *rpc.Client) []common.Route {
|
func (api *API) routes(c *rpc.Client) []common.Route {
|
||||||
api.rpcClient = c
|
api.rpcClient = c
|
||||||
return []common.Route{
|
return []common.Route{
|
||||||
|
{
|
||||||
|
Name: "ListPins",
|
||||||
|
Method: "GET",
|
||||||
|
Pattern: "/pins",
|
||||||
|
HandlerFunc: api.listPins,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "AddPin",
|
Name: "AddPin",
|
||||||
Method: "POST",
|
Method: "POST",
|
||||||
|
@ -168,12 +173,6 @@ func (api *API) routes(c *rpc.Client) []common.Route {
|
||||||
Pattern: "/pins/{requestID}",
|
Pattern: "/pins/{requestID}",
|
||||||
HandlerFunc: api.removePin,
|
HandlerFunc: api.removePin,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Name: "ListPins",
|
|
||||||
Method: "GET",
|
|
||||||
Pattern: "/pins",
|
|
||||||
HandlerFunc: api.listPins,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,7 +350,7 @@ func (api *API) listPins(w http.ResponseWriter, r *http.Request) {
|
||||||
"",
|
"",
|
||||||
"Cluster",
|
"Cluster",
|
||||||
"StatusAll",
|
"StatusAll",
|
||||||
opts.Status,
|
tst,
|
||||||
&globalPinInfos,
|
&globalPinInfos,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user