Documentation
¶
Overview ¶
Package profile parses vmess://, vless://, trojan://, ss:// share links into Server profiles, and persists the saved server list as JSON.
Index ¶
- func IsSubscriptionURL(input string) bool
- func ShareLink(s Server) (string, error)
- func SupportURL(h http.Header) string
- type Server
- type Store
- func (s *Store) Add(server Server) (Server, error)
- func (s *Store) Delete(id string) error
- func (s *Store) Get(id string) (Server, error)
- func (s *Store) List() ([]Server, error)
- func (s *Store) ReplaceWhere(drop func(Server) bool, added []Server) ([]Server, error)
- func (s *Store) Update(server Server) error
- func (s *Store) UpdateWhere(match func(Server) bool, fn func(*Server)) (int, error)
- type SubscriptionUsage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsSubscriptionURL ¶
IsSubscriptionURL reports whether input looks like a subscription URL (http/https) rather than a single vmess/vless/trojan/ss share link.
func ShareLink ¶
ShareLink turns a saved server back into a standard share link, so it can be copied into another client (or another Kite) and parsed by ParseLink.
func SupportURL ¶ added in v0.22.1
SupportURL returns the provider's support link from a subscription response: the Support-URL header (Profile-Web-Page-URL as a fallback). Telegram handles ("@name") become t.me links; only http(s) and tg: links are accepted, so a subscription can't make the UI open anything else.
Types ¶
type Server ¶
type Server struct {
ID string `json:"id"`
Name string `json:"name"`
Protocol string `json:"protocol"` // vmess, vless, trojan, shadowsocks
Address string `json:"address"`
Port int `json:"port"`
UUID string `json:"uuid,omitempty"` // vmess/vless
Password string `json:"password,omitempty"` // trojan/ss
Method string `json:"method,omitempty"` // ss cipher
Extra map[string]string `json:"extra,omitempty"` // network, tls, sni, path, etc.
}
Server is one saved proxy profile, storage- and UI-agnostic.
func ParseSubscription ¶
ParseSubscription parses the body of a subscription URL, which is conventionally either:
- a base64-encoded blob that decodes to a newline-separated list of share links (the near-universal "subscription" format used by V2RayN/V2RayNG/Shadowrocket/Clash-compatible clients), or
- a plain newline-separated list of share links, uncompressed.
Lines that fail to parse are skipped rather than failing the whole subscription, since a subscription commonly mixes supported and unsupported (e.g. ss2022, vmess with unusual fields) entries. Many providers also throw in a few non-functional "info" entries disguised as real links -- e.g. a vless:// whose host is literally "dontUseThis" -- just to surface plan/expiry/traffic details inside clients that list every node. Those are recognized by isInfoNode and dropped rather than imported as dead servers.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists the server list as a single JSON file under the user's config directory. Sqlite is deferred until v1 needs querying beyond a flat list.
func (*Store) Add ¶
Add persists a new server, assigning it an ID if it doesn't already have one, and returns the stored copy (with that ID set) so the caller can hand back something actually usable by Get/Connect -- the server passed in is a value, so its own ID field is never visible to the caller otherwise.
func (*Store) ReplaceWhere ¶
ReplaceWhere removes every stored server matching drop, appends added (assigning IDs), and writes the file once -- so importing or refreshing a subscription with hundreds of servers isn't hundreds of full rewrites.
type SubscriptionUsage ¶
type SubscriptionUsage struct {
UploadBytes int64 `json:"uploadBytes"`
DownloadBytes int64 `json:"downloadBytes"`
TotalBytes int64 `json:"totalBytes"`
ExpireUnix int64 `json:"expireUnix"` // 0 if not reported
}
SubscriptionUsage is traffic/expiry info a subscription provider can report via the (informal but widely adopted) "Subscription-Userinfo" response header, e.g.:
Subscription-Userinfo: upload=123; download=456; total=10737418240; expire=1780000000
func ParseSubscriptionUserinfo ¶
func ParseSubscriptionUserinfo(header string) (SubscriptionUsage, bool)
ParseSubscriptionUserinfo parses a Subscription-Userinfo header value. Returns false if the header was empty or carried none of the known fields.