feat: add all internals and cmd

This commit is contained in:
sajadMRjl
2026-01-28 02:54:04 +03:30
parent e07bf30cc5
commit 5b5b992754
9 changed files with 382 additions and 30 deletions

View File

@@ -1,9 +1,8 @@
package parser
import (
"encoding/json"
"fmt"
"net"
"strconv"
"strings"
"find-me-internet/internal/model"
@@ -11,44 +10,61 @@ import (
"github.com/gvcgo/vpnparser/pkgs/outbound"
)
// ParseLink converts a raw proxy string (vless://, vmess://) into our internal Model
// tempConfig allows us to extract deep fields from the Sing-box JSON
type tempConfig struct {
Transport struct {
Type string `json:"type"`
} `json:"transport"`
TLS struct {
ServerName string `json:"server_name"`
} `json:"tls"`
}
func ParseLink(raw string) (*model.Proxy, error) {
raw = strings.TrimSpace(raw)
if raw == "" {
return nil, fmt.Errorf("empty link")
}
// 1. Use vpnparser to decode the link
item, err := outbound.ParseRawUriToProxyItem(raw, outbound.ClientTypeSingBox)
if err != nil {
return nil, fmt.Errorf("parse failed: %w", err)
}
// 1. Parse Raw Link
// We omit the second argument to let the library use default parsing
item := outbound.ParseRawUriToProxyItem(raw)
if item == nil {
return nil, fmt.Errorf("unknown protocol or invalid link")
}
// 2. Map to our Internal Model
// The library returns a ProxyItem struct. We extract what we need for the "Cheap Checks".
// 2. Initialize Proxy Model
p := &model.Proxy{
RawLink: raw,
Address: item.Address,
Port: item.Port,
Network: item.Network,
SNI: item.Sni,
}
// 3. Determine Protocol (The library stores this in Protocol field)
switch strings.ToLower(item.Protocol) {
// 3. Extract SNI and Network from the Outbound JSON
// The library packs the details into 'item.Outbound' string
if item.Outbound != "" {
var cfg tempConfig
if err := json.Unmarshal([]byte(item.Outbound), &cfg); err == nil {
p.Network = cfg.Transport.Type
p.SNI = cfg.TLS.ServerName
}
}
// Fallback: If JSON extraction failed but we have a generic "Host" (sometimes used as SNI)
// Note: 'item.Host' doesn't exist either, so we rely solely on JSON extraction above.
// 4. Map Protocol (Library uses 'Scheme')
switch strings.ToLower(item.Scheme) {
case "vless":
p.Type = model.TypeVLESS
if strings.Contains(raw, "reality") {
p.Type = model.TypeVLESS // We treat Reality as VLESS with special TLS options
p.Type = model.TypeVLESS // Reality is technically VLESS
}
case "vmess":
p.Type = model.TypeVMess
case "trojan":
p.Type = model.TypeTrojan
case "shadowsocks":
case "shadowsocks", "ss":
p.Type = model.TypeShadowsocks
default:
p.Type = model.TypeUnknown