feat: add PostPinBy controller endpoint for pinning a file

This commit is contained in:
Derrick Hammer 2023-06-09 07:39:43 -04:00
parent 29d6db2009
commit be03a6c686
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 19 additions and 0 deletions

View File

@ -112,6 +112,25 @@ func (f *FilesController) GetStatusBy(cidString string) {
f.respondJSON(&response.StatusResponse{Status: statusCode})
}
func (f *FilesController) PostPinBy(cidString string) {
ctx := f.Ctx
hashHex, valid := validateCid(cidString, true, ctx)
if !valid {
return
}
err := files.Pin(hashHex, getCurrentUserId(ctx))
if internalError(ctx, err) {
logger.Get().Error(err.Error())
return
}
f.Ctx.StatusCode(iris.StatusCreated)
}
func validateCid(cidString string, validateStatus bool, ctx iris.Context) (string, bool) {
_, err := cid.Valid(cidString)
if sendError(ctx, err, iris.StatusBadRequest) {