pinsvcapi: fix some basic bugs

This commit is contained in:
Hector Sanjuan 2022-03-11 00:46:39 +01:00
parent 333b933cd3
commit ab33ec668c
2 changed files with 18 additions and 16 deletions

View File

@ -25,7 +25,7 @@ func init() {
// occurs. It implements the error interface.
type APIError struct {
Reason string `json:"reason"`
Details string `json:"string"`
Details string `json:"details"`
}
func (apiErr APIError) Error() string {
@ -180,12 +180,15 @@ type ListOptions struct {
}
func (lo *ListOptions) FromQuery(q url.Values) error {
for _, cstr := range strings.Split(q.Get("cid"), ",") {
c, err := cid.Decode(cstr)
if err != nil {
return fmt.Errorf("error decoding cid %s: %w", cstr, err)
cidq := q.Get("cid")
if len(cidq) > 0 {
for _, cstr := range strings.Split(cidq, ",") {
c, err := cid.Decode(cstr)
if err != nil {
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")

View File

@ -109,9 +109,8 @@ func globalPinInfoToSvcPinStatus(
status.Info = map[string]string{
"source": "IPFS cluster API",
"warning1": "disregard created time",
"warning2": "CID used for requestID. Conflicts possible",
"warning3": "experimental",
"warning1": "CID used for requestID. Conflicts possible",
"warning2": "experimental",
}
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 {
api.rpcClient = c
return []common.Route{
{
Name: "ListPins",
Method: "GET",
Pattern: "/pins",
HandlerFunc: api.listPins,
},
{
Name: "AddPin",
Method: "POST",
@ -168,12 +173,6 @@ func (api *API) routes(c *rpc.Client) []common.Route {
Pattern: "/pins/{requestID}",
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",
"StatusAll",
opts.Status,
tst,
&globalPinInfos,
)
if err != nil {