github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/web/instances/config.go (about) 1 package instances 2 3 import ( 4 "encoding/json" 5 "net/http" 6 7 "github.com/cozy/cozy-stack/model/instance" 8 "github.com/cozy/cozy-stack/model/job" 9 "github.com/cozy/cozy-stack/pkg/assets" 10 "github.com/cozy/cozy-stack/pkg/assets/model" 11 "github.com/labstack/echo/v4" 12 ) 13 14 func rebuildRedis(c echo.Context) error { 15 instances, err := instance.List() 16 if err != nil { 17 return wrapError(err) 18 } 19 if err = job.System().CleanRedis(); err != nil { 20 return wrapError(err) 21 } 22 for _, i := range instances { 23 err = job.System().RebuildRedis(i) 24 if err != nil { 25 return wrapError(err) 26 } 27 } 28 return c.NoContent(http.StatusNoContent) 29 } 30 31 // Renders the assets list loaded in memory and served by the cozy 32 func assetsInfos(c echo.Context) error { 33 assetsMap, err := assets.List() 34 if err != nil { 35 return err 36 } 37 38 return c.JSON(http.StatusOK, assetsMap) 39 } 40 41 func addAssets(c echo.Context) error { 42 var unmarshaledAssets []model.AssetOption 43 if err := json.NewDecoder(c.Request().Body).Decode(&unmarshaledAssets); err != nil { 44 return err 45 } 46 47 err := assets.Add(unmarshaledAssets) 48 if err != nil { 49 return c.JSON(http.StatusBadRequest, echo.Map{"error": err.Error()}) 50 } 51 return nil 52 } 53 54 func deleteAssets(c echo.Context) error { 55 context := c.Param("context") 56 name := c.Param("*") 57 58 err := assets.Remove(name, context) 59 if err != nil { 60 return wrapError(err) 61 } 62 return c.NoContent(http.StatusNoContent) 63 }