mirror of
https://github.com/zu1k/nali.git
synced 2025-01-22 13:19:02 +08:00
mod qqwry download
This commit is contained in:
parent
e6268057bb
commit
176c3d699e
@ -25,18 +25,13 @@ func NewQQwry(filePath string) QQwry {
|
||||
_, err := os.Stat(filePath)
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
log.Println("文件不存在,尝试从网络获取最新纯真 IP 库")
|
||||
fileData, err = Download()
|
||||
fileData, err = Download(filePath)
|
||||
if err != nil {
|
||||
log.Printf("纯真IP库下载失败,请手动下载解压后保存到本地: %s \n", filePath)
|
||||
log.Println("下载链接: https://qqwry.mirror.noc.one/qqwry.rar")
|
||||
os.Exit(1)
|
||||
} else {
|
||||
if err := ioutil.WriteFile(filePath, fileData, 0644); err == nil {
|
||||
log.Printf("已将最新的 纯真IP库 保存到本地: %s ", filePath)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 打开文件句柄
|
||||
fileInfo.FileBase, err = os.OpenFile(filePath, os.O_RDONLY, 0400)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -5,23 +5,38 @@ import (
|
||||
"compress/zlib"
|
||||
"encoding/binary"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"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")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
key, err := getCopyWriteKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
return unRar(body, key)
|
||||
|
Loading…
Reference in New Issue
Block a user