add config api
This commit is contained in:
parent
87eacc6cb2
commit
50696a3c96
|
|
@ -44,6 +44,9 @@ func RegisterRouter(router *gin.Engine) {
|
||||||
c.Redirect(http.StatusMovedPermanently, "/web")
|
c.Redirect(http.StatusMovedPermanently, "/web")
|
||||||
})
|
})
|
||||||
router.StaticFS("/web", http.Dir("./public"))
|
router.StaticFS("/web", http.Dir("./public"))
|
||||||
|
router.POST("/api/check", service.CheckBeancount)
|
||||||
|
router.GET("/api/config", service.QueryServerConfig)
|
||||||
|
router.POST("/api/config", service.UpdateServerConfig)
|
||||||
router.POST("/api/ledger", service.OpenOrCreateLedger)
|
router.POST("/api/ledger", service.OpenOrCreateLedger)
|
||||||
authorized := router.Group("/api/auth/")
|
authorized := router.Group("/api/auth/")
|
||||||
authorized.Use(AuthorizedHandler())
|
authorized.Use(AuthorizedHandler())
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,28 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func CheckBeancount(c *gin.Context) {
|
||||||
|
cmd := exec.Command("bean-query", "--version")
|
||||||
|
output, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
InternalError(c, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
OK(c, string(output))
|
||||||
|
}
|
||||||
|
|
||||||
|
func QueryServerConfig(c *gin.Context) {
|
||||||
|
OK(c, script.GetServerConfig())
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateServerConfig(c *gin.Context) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
type LoginForm struct {
|
type LoginForm struct {
|
||||||
Mail string `form:"mail" binding:"required"`
|
Mail string `form:"mail" binding:"required"`
|
||||||
Secret string `form:"secret" binding:"required"`
|
Secret string `form:"secret" binding:"required"`
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue