EnsureDataFiles 确保所有数据文件存在且最新
()
| 40 | |
| 41 | // EnsureDataFiles 确保所有数据文件存在且最新 |
| 42 | func (d *Downloader) EnsureDataFiles() error { |
| 43 | printTimestampedMessage("检查数据文件...") |
| 44 | |
| 45 | // 定义需要下载的文件 |
| 46 | files := []DataFile{ |
| 47 | { |
| 48 | Name: "cdn_keywords.txt", |
| 49 | URL: "https://raw.githubusercontent.com/V2RaySSR/RealityChecker/main/data/cdn_keywords.txt", |
| 50 | LocalPath: "data/cdn_keywords.txt", |
| 51 | }, |
| 52 | { |
| 53 | Name: "hot_websites.txt", |
| 54 | URL: "https://raw.githubusercontent.com/V2RaySSR/RealityChecker/main/data/hot_websites.txt", |
| 55 | LocalPath: "data/hot_websites.txt", |
| 56 | }, |
| 57 | { |
| 58 | Name: "gfwlist.conf", |
| 59 | URL: "https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/gfw.txt", |
| 60 | LocalPath: "data/gfwlist.conf", |
| 61 | }, |
| 62 | { |
| 63 | Name: "Country.mmdb", |
| 64 | URL: "https://github.com/Loyalsoldier/geoip/releases/latest/download/Country.mmdb", |
| 65 | LocalPath: "data/Country.mmdb", |
| 66 | }, |
| 67 | } |
| 68 | |
| 69 | // 确保data目录存在 |
| 70 | if err := os.MkdirAll("data", 0755); err != nil { |
| 71 | return fmt.Errorf("创建data目录失败: %v", err) |
| 72 | } |
| 73 | |
| 74 | // 检查并下载每个文件 |
| 75 | for _, file := range files { |
| 76 | if err := d.ensureFile(file); err != nil { |
| 77 | return err |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | printTimestampedMessage("数据文件检查完成。") |
| 82 | return nil |
| 83 | } |
| 84 | |
| 85 | // ensureFile 确保单个文件存在且最新 |
| 86 | func (d *Downloader) ensureFile(file DataFile) error { |
no test coverage detected