feat(sub): auto-detect subscription formats

This commit is contained in:
Tomilla
2026-07-06 10:02:18 +08:00
parent 8bb9a8c6d5
commit 99072457d1
8 changed files with 668 additions and 66 deletions
+2 -3
View File
@@ -57,7 +57,7 @@ func NewSubJsonService(mux string, rules string, finalMask string, subService *S
}
// GetJson generates a JSON subscription configuration for the given subscription ID and host.
func (s *SubJsonService) GetJson(subId string, host string) (string, string, error) {
func (s *SubJsonService) GetJson(subId string, host string, alwaysReturnArray bool) (string, string, error) {
subReq := s.SubService.ForRequest(host)
subReq.subscriptionBody = true
inbounds, err := subReq.getInboundsBySubId(subId)
@@ -124,9 +124,8 @@ func (s *SubJsonService) GetJson(subId string, host string) (string, string, err
}
traffic, _ := subReq.AggregateTrafficByEmails(emails)
// Combile outbounds
var finalJson []byte
if len(configArray) == 1 {
if len(configArray) == 1 && !alwaysReturnArray {
finalJson, _ = json.MarshalIndent(configArray[0], "", " ")
} else {
finalJson, _ = json.MarshalIndent(configArray, "", " ")