mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-06 05:04:22 +00:00
- Update go.mod module path from mhsanaei/3x-ui/v3 to saeederamy/3x-ui/v3 - Update all 73 Go files' import paths accordingly - Fix README.fa_IR.md install command to point to fork's main branch The fork was referencing the original repo's module path in go.mod and all Go source imports, making it dependent on MHSanaei's namespace at build time. https://claude.ai/code/session_01M6d5atbWjuLTj6UwRHoK5m
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package sub
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/saeederamy/3x-ui/v3/database/model"
|
|
"github.com/saeederamy/3x-ui/v3/web/service"
|
|
)
|
|
|
|
type LinkProvider struct {
|
|
settingService service.SettingService
|
|
}
|
|
|
|
func NewLinkProvider() *LinkProvider {
|
|
return &LinkProvider{}
|
|
}
|
|
|
|
func (p *LinkProvider) build(host string) *SubService {
|
|
showInfo, _ := p.settingService.GetSubShowInfo()
|
|
rModel, err := p.settingService.GetRemarkModel()
|
|
if err != nil {
|
|
rModel = "-ieo"
|
|
}
|
|
svc := NewSubService(showInfo, rModel)
|
|
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)
|
|
return splitLinkLines(svc.GetLink(inbound, email))
|
|
}
|
|
|
|
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
|
|
}
|