mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
65 lines
1.8 KiB
Go
65 lines
1.8 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/server/service"
|
|
)
|
|
|
|
/*修改Remarks*/
|
|
func PatchSubscription(ctx *gin.Context) {
|
|
release, ok := beginMutation(ctx)
|
|
if !ok {
|
|
return
|
|
}
|
|
defer release()
|
|
|
|
var data struct {
|
|
Subscription touch.Subscription `json:"subscription"`
|
|
}
|
|
err := ctx.ShouldBindJSON(&data)
|
|
s := data.Subscription
|
|
index := s.ID - 1
|
|
if err != nil || s.TYPE != configure.SubscriptionType || index < 0 || index >= configure.GetLenSubscriptions() {
|
|
common.ResponseError(ctx, badRequest("subscription", "request body must be a subscription item with _type \"subscription\" and an existing positive id"))
|
|
return
|
|
}
|
|
err = service.ModifySubscriptionRemark(s)
|
|
if err != nil {
|
|
common.ResponseError(ctx, logError(err))
|
|
return
|
|
}
|
|
getTouch(ctx)
|
|
}
|
|
|
|
/*更新订阅*/
|
|
func PutSubscription(ctx *gin.Context) {
|
|
release, ok := beginMutation(ctx)
|
|
if !ok {
|
|
return
|
|
}
|
|
defer release()
|
|
|
|
var data struct {
|
|
configure.NodeRef
|
|
// BypassProxy selects a direct route for this one subscription fetch.
|
|
// It records the user's consent to go direct; the server does not
|
|
// check that the proxy route is actually unavailable.
|
|
BypassProxy bool `json:"bypassProxy"`
|
|
}
|
|
err := ctx.ShouldBindJSON(&data)
|
|
index := data.ID - 1
|
|
if err != nil || data.TYPE != configure.SubscriptionType || index < 0 || index >= configure.GetLenSubscriptions() {
|
|
common.ResponseError(ctx, badRequest("subscription", "request body must be a subscription item with _type \"subscription\" and an existing positive id"))
|
|
return
|
|
}
|
|
err = service.UpdateSubscriptionWithOptions(index, false, service.SubscriptionFetchOptions{BypassProxy: data.BypassProxy})
|
|
if err != nil {
|
|
common.ResponseError(ctx, logError(err))
|
|
return
|
|
}
|
|
getTouch(ctx)
|
|
}
|