One-click configuration: Vless Encryption + XHTTP

This commit is contained in:
心隨緣動 2025-09-19 19:37:49 +08:00 committed by GitHub
parent e8b51569ed
commit 6301c9ac56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -56,6 +56,8 @@ func (a *ServerController) initRouter(g *gin.RouterGroup) {
g.POST("/xraylogs/:count", a.getXrayLogs)
g.POST("/importDB", a.importDB)
g.POST("/getNewEchCert", a.getNewEchCert)
g.POST("/history/save", a.saveHistory)
g.GET("/history/load", a.loadHistory)
}
func (a *ServerController) refreshStatus() {
@ -295,3 +297,39 @@ func (a *ServerController) getNewmlkem768(c *gin.Context) {
}
jsonObj(c, out, nil)
}
func (a *ServerController) saveHistory(c *gin.Context) {
/* 中文注释: 旧的错误代码因为它期望一个 JSON 请求体但前端发送的是表单数据
var req struct {
Type string `json:"type"`
Link string `json:"link"`
}
if err := c.ShouldBindJSON(&req); err != nil {
jsonMsg(c, "Invalid request", err)
return
}
err := a.serverService.SaveLinkHistory(req.Type, req.Link)
*/
// 【中文注释】: 修改后的新代码,直接从 POST 表单中获取 'type' 和 'link' 参数
// 【中文注释】: 这与其他 POST 方法(如 getLogs, getXrayLogs的处理方式保持一致解决了数据格式不匹配的问题。
historyType := c.PostForm("type")
link := c.PostForm("link")
// 【中文注释】: 调用服务层方法来保存历史记录
err := a.serverService.SaveLinkHistory(historyType, link)
if err != nil {
jsonMsg(c, "Failed to save history", err)
return
}
jsonMsg(c, "History saved successfully", nil)
}
func (a *ServerController) loadHistory(c *gin.Context) {
history, err := a.serverService.LoadLinkHistory()
if err != nil {
jsonMsg(c, "Failed to load history", err)
return
}
jsonObj(c, history, nil)
}