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 |
|||
|
|||
import ( |
|||
"XProxy/cmd/common" |
|||
"github.com/robfig/cron" |
|||
log "github.com/sirupsen/logrus" |
|||
"XProxy/cmd/common" |
|||
"github.com/robfig/cron" |
|||
log "github.com/sirupsen/logrus" |
|||
) |
|||
|
|||
func updateAssets(urls map[string]string, assetDir string) { |
|||
if len(urls) != 0 { |
|||
log.Info("Start update assets") |
|||
for file, url := range urls { |
|||
common.DownloadFile(url, assetDir+"/"+file) |
|||
} |
|||
} |
|||
type Config struct { |
|||
Cron string `yaml:"cron" json:"cron"` |
|||
Url map[string]string `yaml:"url" json:"url"` |
|||
} |
|||
|
|||
func AutoUpdate(updateCron string, updateUrls map[string]string, assetDir string) { |
|||
autoUpdate := cron.New() |
|||
_ = autoUpdate.AddFunc(updateCron, func() { |
|||
updateAssets(updateUrls, assetDir) |
|||
}) |
|||
autoUpdate.Start() |
|||
func updateAsset(urls map[string]string, assetDir string) { |
|||
if len(urls) != 0 { |
|||
log.Info("Start update assets") |
|||
for file, url := range urls { |
|||
common.DownloadFile(url, assetDir+"/"+file) |
|||
} |
|||
} |
|||
} |
|||
|
|||
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