Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
feat: add pin removal api call
Browse files Browse the repository at this point in the history
  • Loading branch information
postables committed May 1, 2020
1 parent 6369551 commit 4259d56
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ func (api *API) setupRoutes(debug bool) error {
{
pin.POST("/:hash", api.pinToHostedIPFSNetwork)
pin.GET("/check/:hash/:networkName", api.checkLocalNodeForPinForHostedIPFSNetwork)
pin.DELETE("/remove/:hash", api.removePin)
}
// file upload routes
file := private.Group("/file")
Expand Down
20 changes: 20 additions & 0 deletions api/v2/routes_rtfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v2
import (
"bytes"
"errors"
"fmt"
"html"
"io"
"io/ioutil"
Expand Down Expand Up @@ -394,3 +395,22 @@ func (api *API) extendPin(c *gin.Context) {
// return
Respond(c, http.StatusOK, gin.H{"response": "pin time successfully extended"})
}

func (api *API) removePin(c *gin.Context) {
username, err := GetAuthenticatedUserFromContext(c)
if err != nil {
api.LogError(c, err, eh.NoAPITokenError)(http.StatusBadRequest)
return
}
// validate hash
hash := c.Param("hash")
if _, err := gocid.Decode(hash); err != nil {
Fail(c, err)
return
}
if err := api.upm.RemovePin(username, hash, "public"); err != nil {
api.LogError(c, err, fmt.Sprint(eh.PinRemovalError+"hash: "+hash))(http.StatusBadRequest)
return
}
Respond(c, http.StatusOK, gin.H{"response": "pin successfuly removed with partial cost refunded"})
}
2 changes: 2 additions & 0 deletions eh/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,6 @@ const (
MaxHoldTimeError = "a hold time of this long would result in a longer maximum pin time than what your account allow, please reduce your hold time and try again"
// HostNameNotFoundError is an error message when api server has not hostname
HostNameNotFoundError = "an api host has not hostname, please set hostname"
// PinRemovalError is an error message when we failed to remove a pin
PinRemovalError = "failed to remove pin and refund partial cost"
)

0 comments on commit 4259d56

Please sign in to comment.