[feat] download singbox config #938 #957

This commit is contained in:
Alireza Ahmadi
2026-01-04 17:36:47 +01:00
parent 94cc29edf5
commit 0ef5db4846
3 changed files with 21 additions and 1 deletions
+2
View File
@@ -95,6 +95,8 @@ func (a *APIHandler) getHandler(c *gin.Context) {
a.ApiService.GetDb(c) a.ApiService.GetDb(c)
case "tokens": case "tokens":
a.ApiService.GetTokens(c) a.ApiService.GetTokens(c)
case "singbox-config":
a.ApiService.GetSingboxConfig(c)
default: default:
jsonMsg(c, "failed", common.NewError("unknown action: ", action)) jsonMsg(c, "failed", common.NewError("unknown action: ", action))
} }
+18
View File
@@ -378,3 +378,21 @@ func (a *ApiService) DeleteToken(c *gin.Context) {
err := a.UserService.DeleteToken(tokenId) err := a.UserService.DeleteToken(tokenId)
jsonMsg(c, "", err) jsonMsg(c, "", err)
} }
func (a *ApiService) GetSingboxConfig(c *gin.Context) {
config, err := a.ConfigService.GetConfig("")
if err != nil {
c.Status(400)
c.Writer.WriteString(err.Error())
return
}
rawConfig, err := json.MarshalIndent(config, "", " ")
if err != nil {
c.Status(400)
c.Writer.WriteString(err.Error())
return
}
c.Header("Content-Type", "application/json")
c.Header("Content-Disposition", "attachment; filename=config_"+time.Now().Format("20060102-150405")+".json")
c.Writer.Write(rawConfig)
}