修正圖像初始化錯誤
This commit is contained in:
		@@ -2,6 +2,7 @@ package models
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"image"
 | 
			
		||||
	"io"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net/http"
 | 
			
		||||
@@ -20,13 +21,15 @@ type Image struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 初始化图片
 | 
			
		||||
func (img *Image) Init(content string) {
 | 
			
		||||
func (img *Image) Init(content string) (err error) {
 | 
			
		||||
	var body io.ReadCloser
 | 
			
		||||
 | 
			
		||||
	if len(regexp.MustCompile(`image.gameuiux.cn`).FindStringSubmatch(content)) > 0 {
 | 
			
		||||
		key := regexp.MustCompile(`^https?://image.gameuiux.cn/`).ReplaceAllString(content, "")
 | 
			
		||||
 | 
			
		||||
		// 从OSS中读取图片
 | 
			
		||||
		bucket := GetBucket("gameui-image2")
 | 
			
		||||
		body, err := bucket.GetObject(key)
 | 
			
		||||
		body, err = bucket.GetObject(key)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Println("读取图片失败", err)
 | 
			
		||||
			return
 | 
			
		||||
@@ -52,8 +55,9 @@ func (img *Image) Init(content string) {
 | 
			
		||||
		}
 | 
			
		||||
		return
 | 
			
		||||
	} else {
 | 
			
		||||
		var resp *http.Response
 | 
			
		||||
		log.Println("直接从网络下载图片:", content)
 | 
			
		||||
		resp, err := http.Get(content)
 | 
			
		||||
		resp, err = http.Get(content)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Println("下载图片失败", err)
 | 
			
		||||
			return
 | 
			
		||||
@@ -78,6 +82,7 @@ func (img *Image) Init(content string) {
 | 
			
		||||
			log.Println("解码图像失败", err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user