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