mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-25 12:04:44 +03:00
5ebc8adb19
hostEndpoints and subscriptionHostVariants returned the same empty result for an inbound with no enabled hosts and for one whose enabled hosts are all excluded from the requested format. The second case therefore fell back to the inbound's bare address, the address the operator had hidden. The all-excluded case is now reported separately and renders nothing in raw, json and clash, in both sort modes, in the link export and in the panel's own host selection. Traffic accounting and the usage header are kept. Inbounds with no hosts, or only disabled ones, render as before.
81 lines
1.9 KiB
Go
81 lines
1.9 KiB
Go
package sub
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
|
"github.com/mhsanaei/3x-ui/v3/internal/web/service"
|
|
)
|
|
|
|
type LinkProvider struct {
|
|
settingService service.SettingService
|
|
}
|
|
|
|
func NewLinkProvider() *LinkProvider {
|
|
return &LinkProvider{}
|
|
}
|
|
|
|
func (p *LinkProvider) build(host string) *SubService {
|
|
remarkTemplate, _ := p.settingService.GetRemarkTemplate()
|
|
svc := NewSubService(remarkTemplate)
|
|
svc.PrepareForRequest(host)
|
|
return svc
|
|
}
|
|
|
|
func (p *LinkProvider) SubLinksForSubId(host, subId string) ([]string, error) {
|
|
svc := p.build(host)
|
|
links, _, _, _, err := svc.GetSubs(subId, host)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := make([]string, 0, len(links))
|
|
for _, l := range links {
|
|
out = append(out, splitLinkLines(l)...)
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (p *LinkProvider) LinksForClient(host string, inbound *model.Inbound, email string) []string {
|
|
svc := p.build(host)
|
|
svc.projectThroughFallbackMaster(inbound)
|
|
baseEps, closed := svc.hostEndpoints(inbound, "raw")
|
|
if closed {
|
|
return nil
|
|
}
|
|
if client, ok := svc.clientForLink(inbound, email); ok {
|
|
effectiveEps, bound := svc.clientHostEndpoints(inbound, client, "raw", baseEps)
|
|
if bound && len(effectiveEps) == 0 {
|
|
return nil
|
|
}
|
|
if len(effectiveEps) > 0 {
|
|
if link := svc.linkFromHosts(inbound, client, effectiveEps); link != "" {
|
|
return splitLinkLines(link)
|
|
}
|
|
}
|
|
}
|
|
return splitLinkLines(svc.GetLink(inbound, email))
|
|
}
|
|
|
|
func (p *LinkProvider) LinksForInbounds(host string, inbounds []*model.Inbound) []string {
|
|
svc := p.build(host)
|
|
var out []string
|
|
for _, inbound := range inbounds {
|
|
out = append(out, svc.inboundLinks(inbound)...)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func splitLinkLines(raw string) []string {
|
|
if raw == "" {
|
|
return nil
|
|
}
|
|
parts := strings.Split(raw, "\n")
|
|
out := make([]string, 0, len(parts))
|
|
for _, p := range parts {
|
|
if p = strings.TrimSpace(p); p != "" {
|
|
out = append(out, p)
|
|
}
|
|
}
|
|
return out
|
|
}
|