mirror of
https://github.com/tiny-craft/tiny-rdm.git
synced 2026-04-23 00:17:09 +08:00
feat: add web edition
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
//go:build web
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"tinyrdm/backend/services"
|
||||
"tinyrdm/backend/types"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func registerPreferencesRoutes(rg *gin.RouterGroup) {
|
||||
g := rg.Group("/preferences")
|
||||
|
||||
g.GET("/get", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, services.Preferences().GetPreferences())
|
||||
})
|
||||
|
||||
g.POST("/set", func(c *gin.Context) {
|
||||
var pf types.Preferences
|
||||
if err := c.ShouldBindJSON(&pf); err != nil {
|
||||
c.JSON(http.StatusBadRequest, types.JSResp{Msg: "invalid request"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, services.Preferences().SetPreferences(pf))
|
||||
})
|
||||
|
||||
g.POST("/update", func(c *gin.Context) {
|
||||
var value map[string]any
|
||||
if err := c.ShouldBindJSON(&value); err != nil {
|
||||
c.JSON(http.StatusBadRequest, types.JSResp{Msg: "invalid request"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, services.Preferences().UpdatePreferences(value))
|
||||
})
|
||||
|
||||
g.POST("/restore", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, services.Preferences().RestorePreferences())
|
||||
})
|
||||
|
||||
g.GET("/font-list", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, services.Preferences().GetFontList())
|
||||
})
|
||||
|
||||
g.GET("/buildin-decoder", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, services.Preferences().GetBuildInDecoder())
|
||||
})
|
||||
|
||||
g.GET("/version", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, services.Preferences().GetAppVersion())
|
||||
})
|
||||
|
||||
g.GET("/check-update", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, services.Preferences().CheckForUpdate())
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user