feat: replace http polling with webscoket notify in sd image page

This commit is contained in:
RockYang
2024-02-26 15:45:54 +08:00
parent 37392f2bb2
commit 2ef07574ae
8 changed files with 189 additions and 124 deletions

View File

@@ -156,6 +156,11 @@ func (h *SdJobHandler) Image(c *gin.Context) {
UserId: userId,
})
client := h.pool.Clients.Get(uint(job.UserId))
if client != nil {
_ = client.Send([]byte("Task Updated"))
}
// update user's img calls
h.db.Model(&model.User{}).Where("id = ?", job.UserId).UpdateColumn("img_calls", gorm.Expr("img_calls - ?", 1))
@@ -229,6 +234,7 @@ func (h *SdJobHandler) JobList(c *gin.Context) {
func (h *SdJobHandler) Remove(c *gin.Context) {
var data struct {
Id uint `json:"id"`
UserId uint `json:"user_id"`
ImgURL string `json:"img_url"`
}
if err := c.ShouldBindJSON(&data); err != nil {
@@ -249,6 +255,11 @@ func (h *SdJobHandler) Remove(c *gin.Context) {
logger.Error("remove image failed: ", err)
}
client := h.pool.Clients.Get(data.UserId)
if client != nil {
_ = client.Send([]byte("Task Updated"))
}
resp.SUCCESS(c)
}