mirror of https://github.com/dnomd343/XProxy.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.7 KiB
51 lines
1.7 KiB
package assets
|
|
|
|
import (
|
|
"XProxy/next/logger"
|
|
"os"
|
|
)
|
|
|
|
// updateRemoteAsset will download remote asset via the optional proxy and
|
|
// save them locally. Local files will be overwritten if they exist.
|
|
func updateRemoteAsset(file string, url string, proxy string) error {
|
|
logger.Debugf("Start downloading remote asset `%s` to `%s`", url, file)
|
|
asset, date, err := downloadAsset(url, proxy)
|
|
if err != nil {
|
|
logger.Errorf("Failed to download remote asset `%s`", url)
|
|
return err
|
|
}
|
|
asset, err = tryExtract(asset)
|
|
|
|
fp, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
|
if err != nil {
|
|
logger.Errorf("Failed to open file `%s` -> %v", file, err)
|
|
return err
|
|
}
|
|
defer fp.Close()
|
|
_, err = fp.Write(asset)
|
|
if err != nil {
|
|
logger.Errorf("Failed to save file `%s` -> %v", file, err)
|
|
return err
|
|
}
|
|
|
|
if err := os.Chtimes(file, *date, *date); err != nil {
|
|
logger.Warnf("Failed to change asset modification time")
|
|
} else {
|
|
logger.Debugf("Change `%s` modification time to `%v`", file, date)
|
|
}
|
|
logger.Infof("Successfully obtained remote asset `%s`", file)
|
|
return nil
|
|
}
|
|
|
|
func Demo() {
|
|
//raw, t, _ := download("https://github.com/Loyalsoldier/v2ray-rules-dat/releases/download/202309082208/geosite.dat", "")
|
|
//raw, t, _ := download("https://cdn.dnomd343.top/v2ray-rules-dat/geosite.dat", "")
|
|
//raw, t, _ := download("https://cdn.dnomd343.top/v2ray-rules-dat/geosite.dat", "socks5://192.168.2.2:1084")
|
|
//raw, t, _ := download("https://cdn.dnomd343.top/v2ray-rules-dat/geosite.dat.xz", "")
|
|
//logger.Infof("%v", t)
|
|
//ret, _ := tryExtract(raw)
|
|
//logger.Debugf("content size -> %d", len(ret))
|
|
|
|
updateRemoteAsset("geosite.dat", "http://cdn.dnomd343.top/v2ray-rules-dat/geosite.dat.xz", "")
|
|
|
|
}
|
|
|