mirror of
https://github.com/Alvin-Zilverstand/Twitter-X-Media-Batch-Downloader.git
synced 2026-12-02 02:51:29 +01:00
v4.1
This commit is contained in:
1 parent
2d913d987f
commit
aa87cce538
25 files changed
+3835
-1574
No files matched your search
@@ -1,8 +1,12 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetDefaultDownloadPath() string {
|
||||
@@ -16,3 +20,57 @@ func GetDefaultDownloadPath() string {
|
||||
// Return path to user's Pictures folder
|
||||
return filepath.Join(homeDir, "Pictures")
|
||||
}
|
||||
|
||||
// GetProxyURL gets proxy URL from environment variables or custom proxy setting
|
||||
// Priority: customProxy > HTTP_PROXY/HTTPS_PROXY > http_proxy/https_proxy
|
||||
func GetProxyURL(customProxy string) (*url.URL, error) {
|
||||
// First, check custom proxy setting
|
||||
if customProxy != "" {
|
||||
proxyURL, err := url.Parse(customProxy)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid custom proxy URL: %v", err)
|
||||
}
|
||||
return proxyURL, nil
|
||||
}
|
||||
|
||||
// Check environment variables (case-insensitive on Windows)
|
||||
proxyEnv := os.Getenv("HTTPS_PROXY")
|
||||
if proxyEnv == "" {
|
||||
proxyEnv = os.Getenv("https_proxy")
|
||||
}
|
||||
if proxyEnv == "" {
|
||||
proxyEnv = os.Getenv("HTTP_PROXY")
|
||||
}
|
||||
if proxyEnv == "" {
|
||||
proxyEnv = os.Getenv("http_proxy")
|
||||
}
|
||||
|
||||
if proxyEnv != "" {
|
||||
proxyURL, err := url.Parse(proxyEnv)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid proxy URL from environment: %v", err)
|
||||
}
|
||||
return proxyURL, nil
|
||||
}
|
||||
|
||||
return nil, nil // No proxy
|
||||
}
|
||||
|
||||
// CreateHTTPClient creates an HTTP client with proxy support
|
||||
func CreateHTTPClient(customProxy string, timeout time.Duration) (*http.Client, error) {
|
||||
proxyURL, err := GetProxyURL(customProxy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
transport := &http.Transport{
|
||||
Proxy: http.ProxyURL(proxyURL),
|
||||
}
|
||||
|
||||
client := &http.Client{
|
||||
Transport: transport,
|
||||
Timeout: timeout,
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
Reference in new issue
Block a user