mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-16 16:20:59 +00:00
feat(inbounds): add a narrow endpoint for subscription sort order (#6179)
* feat(inbounds): add a narrow endpoint for subscription sort order Changing an inbound's position in subscription output currently goes through /update/:id, which takes a whole inbound: the caller has to send settings and the entire client list back, and whatever it read before the edit is what gets written. Two people reordering and editing clients in the same inbound race on one blob, and the reorder wins by overwriting. Mirror the existing /setEnable/:id shape. The handler takes only the index and the service reads the stored inbound, so nothing in the request can reach the settings JSON. Node-owned inbounds are marked dirty in the same transaction and pushed through the existing runtime update. * fix(nodes): scope sub sort index updates --------- Co-authored-by: n0ctal <293235942+n0ctal@users.noreply.github.com>
This commit is contained in:
@@ -1264,6 +1264,54 @@ func (s *InboundService) GetInboundDetail(id int) (*model.Inbound, error) {
|
||||
return inbound, nil
|
||||
}
|
||||
|
||||
// SetInboundSubSortIndex changes only the subscription sort order, so a
|
||||
// reorder cannot carry a stale settings/client payload over another edit.
|
||||
func (s *InboundService) SetInboundSubSortIndex(id int, index int) error {
|
||||
index = normalizeSubSortIndex(index)
|
||||
inbound, err := s.GetInbound(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if inbound.SubSortIndex == index {
|
||||
return nil
|
||||
}
|
||||
|
||||
db := database.GetDB()
|
||||
if err := db.Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Model(model.Inbound{}).Where("id = ?", id).
|
||||
Update("sub_sort_index", index).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if inbound.NodeID != nil {
|
||||
return (&NodeService{}).MarkNodeDirtyTx(tx, *inbound.NodeID)
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
inbound.SubSortIndex = index
|
||||
|
||||
if inbound.NodeID == nil {
|
||||
return nil
|
||||
}
|
||||
rt, push, _, perr := s.nodePushPlan(inbound)
|
||||
if perr != nil {
|
||||
return perr
|
||||
}
|
||||
if push {
|
||||
narrow, ok := rt.(interface {
|
||||
SetInboundSubSortIndex(context.Context, *model.Inbound, int) error
|
||||
})
|
||||
if !ok {
|
||||
return fmt.Errorf("runtime %s does not support narrow subscription ordering updates", rt.Name())
|
||||
}
|
||||
if err := narrow.SetInboundSubSortIndex(context.Background(), inbound, index); err != nil {
|
||||
logger.Warning("SetInboundSubSortIndex: remote metadata update on", rt.Name(), "failed:", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *InboundService) SetInboundEnable(id int, enable bool) (bool, error) {
|
||||
inbound, err := s.GetInbound(id)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user