Skip to content

Commit

Permalink
✏️ 修复 fortune 无法下载
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Nov 9, 2021
1 parent e2032cd commit eace561
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions plugin_fortune/fortune.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func init() {
dlmu.Lock()
if file.IsNotExist(mikuji) {
ctx.SendChain(message.Text("正在下载签文文件,请稍后..."))
err := file.DownloadTo(site+"运势签文.json", mikuji)
err := file.DownloadTo(site+"运势签文.json", mikuji, false)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
Expand All @@ -98,7 +98,7 @@ func init() {
dlmu.Lock()
if file.IsNotExist(ttf) {
ctx.SendChain(message.Text("正在下载字体文件,请稍后..."))
err := file.DownloadTo(site+"sakura.ttf", ttf)
err := file.DownloadTo(site+"sakura.ttf", ttf, false)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
Expand Down Expand Up @@ -126,7 +126,7 @@ func init() {
ctx.SendChain(message.Text("正在下载背景图片,请稍后..."))
zipfile := kind + ".zip"
zipcache := base + zipfile
err := file.DownloadTo(site+zipfile, zipcache)
err := file.DownloadTo(site+zipfile, zipcache, false)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
Expand Down
18 changes: 16 additions & 2 deletions utils/file/dl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@
package file

import (
"crypto/tls"
"io"
"net/http"
"os"
)

var (
tr = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
nochkcrtcli = &http.Client{Transport: tr}
)

// DownloadTo 下载到路径
func DownloadTo(url, file string) error {
resp, err := http.Get(url)
func DownloadTo(url, file string, chkcrt bool) error {
var resp *http.Response
var err error
if chkcrt {
resp, err = http.Get(url)
} else {
resp, err = nochkcrtcli.Get(url)
}
if err == nil {
var f *os.File
f, err = os.Create(file)
Expand Down

0 comments on commit eace561

Please sign in to comment.