mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-10-26 03:20:01 +08:00
One `updating` flag guarded thirteen handlers, reads included: while a subscription update or a latency test ran, GET /touch answered REQUEST_IN_PROGRESS, so refreshing the page during a test failed at random. A touch is a database read and needs no turn. The flag becomes a turn that only the state-changing handlers take, and a handler that finds it taken waits up to five seconds before answering REQUEST_IN_PROGRESS instead of refusing at once; a client that leaves while waiting is not answered.
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package controller
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/v2rayA/v2rayA/common"
|
|
"github.com/v2rayA/v2rayA/db/configure"
|
|
"github.com/v2rayA/v2rayA/kernel/touch"
|
|
"github.com/v2rayA/v2rayA/kernel/v2ray"
|
|
"github.com/v2rayA/v2rayA/server/service"
|
|
)
|
|
|
|
func GetTouch(ctx *gin.Context) {
|
|
getTouch(ctx)
|
|
}
|
|
func getTouch(ctx *gin.Context) {
|
|
running := v2ray.ProcessManager.ServiceRunning()
|
|
networkPaused := v2ray.ProcessManager.NetworkPaused()
|
|
t := touch.GenerateTouch()
|
|
common.ResponseSuccess(ctx, gin.H{
|
|
"running": running,
|
|
"networkPaused": networkPaused,
|
|
"touch": t,
|
|
})
|
|
}
|
|
|
|
func DeleteTouch(ctx *gin.Context) {
|
|
release, ok := beginMutation(ctx)
|
|
if !ok {
|
|
return
|
|
}
|
|
defer release()
|
|
|
|
var ws configure.Whiches
|
|
err := ctx.ShouldBindJSON(&ws)
|
|
if err != nil {
|
|
common.ResponseError(ctx, badRequest("touches", "request body must be {\"touches\": [...]} of server or subscription items"))
|
|
return
|
|
}
|
|
err = service.DeleteWhich(ws.Get())
|
|
if err != nil {
|
|
common.ResponseError(ctx, logError(err))
|
|
return
|
|
}
|
|
getTouch(ctx)
|
|
}
|