// @api patch /admin/api/options/{key} 修改设置项的值 // @apiParam key string 需要修改项的key // @apiGroup admin // // @apiRequest json // @apiHeader Authorization xxx // @apiParam value string 新值 // @apiExample json // { "value": "abcdef" } // @apiSuccess 204 no content func adminPatchOption(w http.ResponseWriter, r *http.Request) { key, ok := util.ParamString(w, r, "key") if !ok { return } if _, found := app.GetOption(key); !found { util.RenderJSON(w, http.StatusNotFound, nil, nil) return } data := &struct { Value string `json:"value"` }{} if !util.ReadJSON(w, r, data) { return } if err := app.SetOption(key, data.Value, false); err != nil { logs.Error("adminPatchOption:", err) util.RenderJSON(w, http.StatusInternalServerError, nil, nil) return } lastUpdated() util.RenderJSON(w, http.StatusNoContent, nil, nil) }
// @api get /admin/api/options/{key} 获取设置项的值,不能获取password字段。 // @apiParam key string 名称 // // @apiRequest json // @apiHeader Authorization xxx // // @apiSuccess 200 ok // @api value any 设置项的值 // @apiExample json // { "value": "20" } func adminGetOption(w http.ResponseWriter, r *http.Request) { key, ok := util.ParamString(w, r, "key") if !ok { return } if key == "password" { util.RenderJSON(w, http.StatusNotFound, nil, nil) return } val, found := app.GetOption(key) if !found { util.RenderJSON(w, http.StatusNotFound, nil, nil) return } util.RenderJSON(w, http.StatusOK, map[string]interface{}{"value": val}, nil) }