Fix Telegram proxy URL format (tg://proxy)
This commit is contained in:
parent
ab25511f6e
commit
1217034551
|
|
@ -3,6 +3,7 @@ package telegram
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
|
@ -11,17 +12,32 @@ import (
|
|||
// ConfigureProxy opens Telegram's proxy configuration URL.
|
||||
// Returns true if successful, false otherwise.
|
||||
func ConfigureProxy(host string, port int, username, password string) bool {
|
||||
// Build tg:// proxy URL
|
||||
url := fmt.Sprintf("tg://socks?server=%s&port=%d", host, port)
|
||||
// Build tg:// proxy URL with proper encoding
|
||||
// Format: tg://proxy?server=host&port=port&user=username&pass=password
|
||||
params := url.Values{}
|
||||
params.Set("server", host)
|
||||
params.Set("port", fmt.Sprintf("%d", port))
|
||||
|
||||
if username != "" {
|
||||
url += fmt.Sprintf("&user=%s", username)
|
||||
params.Set("user", username)
|
||||
}
|
||||
if password != "" {
|
||||
url += fmt.Sprintf("&pass=%s", password)
|
||||
params.Set("pass", password)
|
||||
}
|
||||
|
||||
return openURL(url)
|
||||
|
||||
// Try both formats
|
||||
urls := []string{
|
||||
fmt.Sprintf("tg://proxy?%s", params.Encode()),
|
||||
fmt.Sprintf("tg://socks?%s", params.Encode()),
|
||||
}
|
||||
|
||||
for _, testURL := range urls {
|
||||
if openURL(testURL) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// openURL opens a URL in the default browser/application.
|
||||
|
|
|
|||
Loading…
Reference in New Issue