mirror of https://github.com/dnomd343/XProxy.git
dnomd343
2 years ago
6 changed files with 58 additions and 65 deletions
@ -0,0 +1,21 @@ |
|||||
|
package asset |
||||
|
|
||||
|
import ( |
||||
|
"XProxy/cmd/common" |
||||
|
log "github.com/sirupsen/logrus" |
||||
|
) |
||||
|
|
||||
|
func extractFile(archive string, geoFile string, targetDir string) { |
||||
|
if common.IsFileExist(targetDir + "/" + geoFile) { |
||||
|
log.Debugf("Asset %s exist -> skip extract", geoFile) |
||||
|
return |
||||
|
} |
||||
|
log.Infof("Extract asset file -> %s", targetDir+"/"+geoFile) |
||||
|
common.RunCommand("tar", "xvf", archive, "./"+geoFile, "-C", targetDir) |
||||
|
} |
||||
|
|
||||
|
func Load(assetFile string, assetDir string) { |
||||
|
common.CreateFolder(assetDir) |
||||
|
extractFile(assetFile, "geoip.dat", assetDir) |
||||
|
extractFile(assetFile, "geosite.dat", assetDir) |
||||
|
} |
@ -1,25 +0,0 @@ |
|||||
package asset |
|
||||
|
|
||||
import ( |
|
||||
"XProxy/cmd/common" |
|
||||
log "github.com/sirupsen/logrus" |
|
||||
) |
|
||||
|
|
||||
func extractGeoFile(archivePath string, geoFile string, targetDir string) { |
|
||||
if common.IsFileExist(targetDir + "/" + geoFile) { |
|
||||
log.Debugf("Asset %s exist -> skip extract", geoFile) |
|
||||
return |
|
||||
} |
|
||||
log.Infof("Extract asset file -> %s", targetDir+"/"+geoFile) |
|
||||
common.RunCommand("tar", "xvf", archivePath, "./"+geoFile, "-C", targetDir) |
|
||||
} |
|
||||
|
|
||||
func LoadGeoIp(assetFile string, assetDir string) { |
|
||||
common.CreateFolder(assetDir) |
|
||||
extractGeoFile(assetFile, "geoip.dat", assetDir) |
|
||||
} |
|
||||
|
|
||||
func LoadGeoSite(assetFile string, assetDir string) { |
|
||||
common.CreateFolder(assetDir) |
|
||||
extractGeoFile(assetFile, "geosite.dat", assetDir) |
|
||||
} |
|
@ -1,24 +1,29 @@ |
|||||
package asset |
package asset |
||||
|
|
||||
import ( |
import ( |
||||
"XProxy/cmd/common" |
"XProxy/cmd/common" |
||||
"github.com/robfig/cron" |
"github.com/robfig/cron" |
||||
log "github.com/sirupsen/logrus" |
log "github.com/sirupsen/logrus" |
||||
) |
) |
||||
|
|
||||
func updateAssets(urls map[string]string, assetDir string) { |
type Config struct { |
||||
if len(urls) != 0 { |
Cron string `yaml:"cron" json:"cron"` |
||||
log.Info("Start update assets") |
Url map[string]string `yaml:"url" json:"url"` |
||||
for file, url := range urls { |
|
||||
common.DownloadFile(url, assetDir+"/"+file) |
|
||||
} |
|
||||
} |
|
||||
} |
} |
||||
|
|
||||
func AutoUpdate(updateCron string, updateUrls map[string]string, assetDir string) { |
func updateAsset(urls map[string]string, assetDir string) { |
||||
autoUpdate := cron.New() |
if len(urls) != 0 { |
||||
_ = autoUpdate.AddFunc(updateCron, func() { |
log.Info("Start update assets") |
||||
updateAssets(updateUrls, assetDir) |
for file, url := range urls { |
||||
}) |
common.DownloadFile(url, assetDir+"/"+file) |
||||
autoUpdate.Start() |
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func AutoUpdate(update *Config, assetDir string) { |
||||
|
autoUpdate := cron.New() |
||||
|
_ = autoUpdate.AddFunc(update.Cron, func() { |
||||
|
updateAsset(update.Url, assetDir) |
||||
|
}) |
||||
|
autoUpdate.Start() |
||||
} |
} |
||||
|
Loading…
Reference in new issue