mirror of https://github.com/dnomd343/XProxy.git
Dnomd343
1 year ago
4 changed files with 89 additions and 40 deletions
@ -1,29 +1,75 @@ |
|||||
package assets |
package assets |
||||
|
|
||||
|
import ( |
||||
|
"XProxy/next/logger" |
||||
|
urlpkg "net/url" |
||||
|
"strings" |
||||
|
"sync" |
||||
|
) |
||||
|
|
||||
var buildinAssets = map[string]string{ |
var buildinAssets = map[string]string{ |
||||
"geoip.dat": "geoip.dat.xz", |
"geoip.dat": "/geoip.dat.xz", |
||||
"geosite.dat": "geosite.dat.xz", |
"geosite.dat": "/geosite.dat.xz", |
||||
|
} |
||||
|
|
||||
|
type UpdateSettings struct { |
||||
|
cron string |
||||
|
mutex sync.Mutex |
||||
|
proxy *urlpkg.URL |
||||
|
assets map[string]string |
||||
} |
} |
||||
|
|
||||
func Demo() { |
var update UpdateSettings |
||||
|
|
||||
remoteAssets := map[string]string{ |
func assetsClone(raw map[string]string) map[string]string { |
||||
"geoip.dat": "https://cdn.dnomd343.top/v2ray-rules-dat/geoip.dat.xz", |
assets := make(map[string]string, len(raw)) |
||||
"geosite.dat": "https://cdn.dnomd343.top/v2ray-rules-dat/geosite.dat.xz", |
for file, url := range raw { |
||||
|
assets[file] = strings.Clone(url) |
||||
} |
} |
||||
|
return assets |
||||
|
} |
||||
|
|
||||
//updateLocalAssets(buildinAssets, true)
|
func SetCron(cron string) error { |
||||
//updateLocalAssets(buildinAssets, false)
|
// TODO: setting up crond service
|
||||
|
return nil |
||||
|
} |
||||
|
|
||||
updateRemoteAssets(remoteAssets, "", true) |
func GetProxy() string { |
||||
//updateRemoteAssets(remoteAssets, "", false)
|
update.mutex.Lock() |
||||
//updateRemoteAssets(remoteAssets, "socks5://192.168.2.2:1084", true)
|
proxy := update.proxy.String() |
||||
//updateRemoteAssets(remoteAssets, "socks5://192.168.2.2:1084", false)
|
update.mutex.Unlock() |
||||
|
return proxy |
||||
|
} |
||||
|
|
||||
//time.Sleep(10 * time.Second)
|
func SetProxy(proxy string) error { |
||||
|
var proxyUrl *urlpkg.URL // clear proxy by empty string
|
||||
|
if proxy != "" { |
||||
|
url, err := urlpkg.Parse(proxy) |
||||
|
if err != nil { |
||||
|
logger.Errorf("Invalid proxy url `%s` -> %v", proxy, err) |
||||
|
return err |
||||
|
} |
||||
|
proxyUrl = url |
||||
|
} |
||||
|
update.mutex.Lock() |
||||
|
update.proxy = proxyUrl |
||||
|
update.mutex.Unlock() |
||||
|
return nil |
||||
|
} |
||||
|
|
||||
//updateRemoteAsset("geosite.dat", "http://cdn.dnomd343.top/v2ray-rules-dat/geosite.dat.xz", "")
|
func SetAssets(assets map[string]string) { |
||||
//updateRemoteAsset("geosite.dat", "http://cdn.dnomd343.top/v2ray-rules-dat/geosite.dat.xz", "socks5://192.168.2.2:1084")
|
update.mutex.Lock() |
||||
//updateLocalAsset("geosite.dat", "geosite.dat.xz")
|
update.assets = assetsClone(assets) |
||||
|
update.mutex.Unlock() |
||||
|
} |
||||
|
|
||||
|
func GetAssets() map[string]string { |
||||
|
update.mutex.Lock() |
||||
|
assets := assetsClone(update.assets) |
||||
|
update.mutex.Unlock() |
||||
|
return assets |
||||
|
} |
||||
|
|
||||
|
func LoadBuildin() { |
||||
|
updateLocalAssets(buildinAssets, true) |
||||
} |
} |
||||
|
Loading…
Reference in new issue