mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-28 00:24:19 +00:00
439245d42b
Export-all now renders links through the subscription engine via a new GET /panel/api/inbounds/allLinks endpoint, so the configured remark template (name-only display part) is applied per client -- matching the client info/QR pages. Previously it generated links client-side with a hardcoded inbound-email remark. Host-aware: managed Host endpoints win over the plain link, so HOST and per-host variants render; duplicate client JSON entries are deduped by email and the list is scoped to the logged-in user.
66 lines
1.5 KiB
Go
66 lines
1.5 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)
|
|
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
|
|
}
|