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.
63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
package service
|
|
|
|
import (
|
|
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
|
"github.com/mhsanaei/3x-ui/v3/internal/util/common"
|
|
)
|
|
|
|
type SubLinkProvider interface {
|
|
SubLinksForSubId(host, subId string) ([]string, error)
|
|
LinksForClient(host string, inbound *model.Inbound, email string) []string
|
|
LinksForInbounds(host string, inbounds []*model.Inbound) []string
|
|
}
|
|
|
|
var registeredSubLinkProvider SubLinkProvider
|
|
|
|
func RegisterSubLinkProvider(p SubLinkProvider) {
|
|
registeredSubLinkProvider = p
|
|
}
|
|
|
|
func (s *InboundService) GetSubLinks(host, subId string) ([]string, error) {
|
|
if registeredSubLinkProvider == nil {
|
|
return nil, common.NewError("sub link provider not registered")
|
|
}
|
|
return registeredSubLinkProvider.SubLinksForSubId(host, subId)
|
|
}
|
|
|
|
func (s *InboundService) GetAllInboundLinks(host string, userId int) ([]string, error) {
|
|
if registeredSubLinkProvider == nil {
|
|
return nil, common.NewError("sub link provider not registered")
|
|
}
|
|
inbounds, err := s.GetInbounds(userId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return registeredSubLinkProvider.LinksForInbounds(host, inbounds), nil
|
|
}
|
|
|
|
func (s *InboundService) GetAllClientLinks(host string, email string) ([]string, error) {
|
|
if email == "" {
|
|
return nil, common.NewError("client email is required")
|
|
}
|
|
if registeredSubLinkProvider == nil {
|
|
return nil, common.NewError("sub link provider not registered")
|
|
}
|
|
rec, err := s.clientService.GetRecordByEmail(nil, email)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
inboundIds, err := s.clientService.GetInboundIdsForRecord(rec.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var links []string
|
|
for _, ibId := range inboundIds {
|
|
inbound, getErr := s.GetInbound(ibId)
|
|
if getErr != nil {
|
|
return nil, getErr
|
|
}
|
|
links = append(links, registeredSubLinkProvider.LinksForClient(host, inbound, email)...)
|
|
}
|
|
return links, nil
|
|
}
|