1
0
mirror of https://github.com/zu1k/nali.git synced 2025-01-23 13:49:02 +08:00

mod qqwry download

This commit is contained in:
zu1k 2020-07-22 06:40:02 +08:00
parent 11dd415c35
commit 342e49a642
2 changed files with 20 additions and 10 deletions

View File

@ -25,18 +25,13 @@ func NewQQwry(filePath string) QQwry {
_, err := os.Stat(filePath) _, err := os.Stat(filePath)
if err != nil && os.IsNotExist(err) { if err != nil && os.IsNotExist(err) {
log.Println("文件不存在,尝试从网络获取最新纯真 IP 库") log.Println("文件不存在,尝试从网络获取最新纯真 IP 库")
fileData, err = Download() fileData, err = Download(filePath)
if err != nil { if err != nil {
log.Printf("纯真IP库下载失败请手动下载解压后保存到本地: %s \n", filePath) log.Printf("纯真IP库下载失败请手动下载解压后保存到本地: %s \n", filePath)
log.Println("下载链接: https://qqwry.mirror.noc.one/qqwry.rar") log.Println("下载链接: https://qqwry.mirror.noc.one/qqwry.rar")
os.Exit(1) os.Exit(1)
} else {
if err := ioutil.WriteFile(filePath, fileData, 0644); err == nil {
log.Printf("已将最新的 纯真IP库 保存到本地: %s ", filePath)
}
} }
} else { } else {
// 打开文件句柄
fileInfo.FileBase, err = os.OpenFile(filePath, os.O_RDONLY, 0400) fileInfo.FileBase, err = os.OpenFile(filePath, os.O_RDONLY, 0400)
if err != nil { if err != nil {
panic(err) panic(err)

View File

@ -5,23 +5,38 @@ import (
"compress/zlib" "compress/zlib"
"encoding/binary" "encoding/binary"
"io/ioutil" "io/ioutil"
"log"
"net/http" "net/http"
) )
func Download() (data []byte, err error) { func Download(filePath string) (data []byte, err error) {
data, err = getData()
if err != nil {
log.Printf("纯真IP库下载失败请手动下载解压后保存到本地: %s \n", filePath)
log.Println("下载链接: https://qqwry.mirror.noc.one/qqwry.rar")
return
}
if err = ioutil.WriteFile(filePath, data, 0644); err == nil {
log.Printf("已将最新的 纯真IP库 保存到本地: %s ", filePath)
}
return
}
func getData() (data []byte, err error) {
resp, err := http.Get("https://qqwry.mirror.noc.one/qqwry.rar") resp, err := http.Get("https://qqwry.mirror.noc.one/qqwry.rar")
if err != nil { if err != nil {
return nil, err return
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return
} }
key, err := getCopyWriteKey() key, err := getCopyWriteKey()
if err != nil { if err != nil {
return nil, err return
} }
return unRar(body, key) return unRar(body, key)