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")
|
||||
})
|
||||
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)
|
||||
authorized := router.Group("/api/auth/")
|
||||
authorized.Use(AuthorizedHandler())
|
||||
|
|
|
|||
|
|
@ -8,9 +8,28 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"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 {
|
||||
Mail string `form:"mail" binding:"required"`
|
||||
Secret string `form:"secret" binding:"required"`
|
||||
|
|
@ -93,7 +112,7 @@ func copyFile(sourceFilePath string, targetFilePath string, ledgerConfig script.
|
|||
return err
|
||||
}
|
||||
err = script.WriteFile(newTargetFilePath, strings.ReplaceAll(strings.ReplaceAll(string(fileContent), "%startDate%", ledgerConfig.StartDate), "%operatingCurrency%", ledgerConfig.OperatingCurrency))
|
||||
script.LogInfo(ledgerConfig.Mail, "Success create file " + newTargetFilePath)
|
||||
script.LogInfo(ledgerConfig.Mail, "Success create file "+newTargetFilePath)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
Loading…
Reference in New Issue