2020-07-18 14:18:54 +08:00
|
|
|
|
package cdn
|
|
|
|
|
|
|
|
|
|
import (
|
2020-07-22 07:25:01 +08:00
|
|
|
|
"log"
|
|
|
|
|
|
|
|
|
|
"github.com/zu1k/nali/pkg/common"
|
2020-07-18 14:18:54 +08:00
|
|
|
|
)
|
|
|
|
|
|
2020-07-30 07:18:06 +08:00
|
|
|
|
const (
|
|
|
|
|
githubUrl = "https://raw.githubusercontent.com/SukkaLab/cdn/master/dist/cdn.json"
|
|
|
|
|
jsdelivrUrl = "https://cdn.jsdelivr.net/gh/SukkaLab/cdn/dist/cdn.json"
|
|
|
|
|
)
|
|
|
|
|
|
2022-03-02 12:34:11 +08:00
|
|
|
|
func Download(filePath ...string) (data []byte, err error) {
|
|
|
|
|
data, err = common.GetHttpClient().Get(jsdelivrUrl, githubUrl)
|
2020-07-18 14:18:54 +08:00
|
|
|
|
if err != nil {
|
2022-03-02 12:34:11 +08:00
|
|
|
|
log.Printf("CDN数据库下载失败,请手动下载解压后保存到本地: %s \n", filePath)
|
|
|
|
|
log.Println("下载链接:", githubUrl)
|
|
|
|
|
return
|
2020-07-30 07:18:06 +08:00
|
|
|
|
}
|
2020-07-18 14:18:54 +08:00
|
|
|
|
|
2022-03-02 12:34:11 +08:00
|
|
|
|
if len(filePath) == 1 {
|
|
|
|
|
if err := common.SaveFile(filePath[0], data); err == nil {
|
|
|
|
|
log.Printf("已将最新的 CDN数据库 保存到本地: %s \n", filePath)
|
|
|
|
|
}
|
2020-07-18 14:18:54 +08:00
|
|
|
|
}
|
2022-03-02 12:34:11 +08:00
|
|
|
|
return
|
2020-07-18 14:18:54 +08:00
|
|
|
|
}
|