From be03a6c6867f305529af90e6206a0597bb84f015 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 9 Jun 2023 07:39:43 -0400 Subject: [PATCH] feat: add PostPinBy controller endpoint for pinning a file --- controller/files.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/controller/files.go b/controller/files.go index 02a39a5..a78a11c 100644 --- a/controller/files.go +++ b/controller/files.go @@ -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) {