refactor: 更新 PullCodeHandler、BuildBotHandler 和 RestartBotHandler,简化响应逻辑并添加 AllInOneHandler 以支持批量操作

This commit is contained in:
lixiangwuxian 2025-05-03 23:30:05 +08:00
parent f5ad785c2e
commit 9ba0b0f241

View File

@ -173,8 +173,10 @@ func PullCodeHandler(c *gin.Context) {
log.Println("拉取代码...")
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "拉取代码成功"})
c.Status(http.StatusOK)
// c.JSON(http.StatusOK, gin.H{"message": "拉取代码成功"})
}
func BuildBotHandler(c *gin.Context) {
@ -182,8 +184,10 @@ func BuildBotHandler(c *gin.Context) {
log.Println("构建程序...")
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "构建成功"})
c.Status(http.StatusOK)
// c.JSON(http.StatusOK, gin.H{"message": "构建成功"})
}
func RestartBotHandler(c *gin.Context) {
@ -197,5 +201,17 @@ func RestartBotHandler(c *gin.Context) {
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
}
c.JSON(http.StatusOK, gin.H{"message": "重启成功"})
c.Status(http.StatusOK)
// c.JSON(http.StatusOK, gin.H{"message": "重启成功"})
}
func AllInOneHandler(c *gin.Context) {
PullCodeHandler(c)
BuildBotHandler(c)
RestartBotHandler(c)
if c.Writer.Status() != http.StatusOK {
c.JSON(http.StatusInternalServerError, gin.H{"error": "unauthorized"})
return
}
c.JSON(http.StatusOK, gin.H{"message": "全部操作成功"})
}