更新v1.2.1
Squashed commit of the following: commit 146f106fbece251606f358141bda3d9c524c3e93 Author: Sun <95302870@qq.com> Date: Thu Dec 28 19:39:36 2023 +0800 修改默认宽度 commit 827197e295b2b0997902b8f965d14ab2598c5c1b Author: Sun <95302870@qq.com> Date: Thu Dec 28 17:54:25 2023 +0800 修复升级掉登录的问题 commit 2e54326f5fe2b8fac4eed488a14b04b8133c41bb Author: Sun <95302870@qq.com> Date: Thu Dec 28 17:21:49 2023 +0800 优化边距等提示 commit 469c6fd644a2a23d96405d15456980edfdfb17b0 Author: Sun <95302870@qq.com> Date: Thu Dec 28 17:21:34 2023 +0800 搜索栏选择搜索引擎后关闭选择器 commit 632da9635a4a434d361495dfcb83f8b650cb4a3c Author: Sun <95302870@qq.com> Date: Thu Dec 28 16:54:28 2023 +0800 增加 内容左右边距和最大宽度 commit f1cc3dce2a51ec60c1b04f21954b99b284b2df61 Author: Sun <95302870@qq.com> Date: Thu Dec 28 14:24:23 2023 +0800 分组标题增加阴影 commit 7615a29678037362c18632f38caad72e07a32d1a Author: Sun <95302870@qq.com> Date: Thu Dec 28 14:18:41 2023 +0800 更改版本号1.2.1 commit b605374e951d3fb2ca52d36bd0fa82aec4a5e89b Author: Sun <95302870@qq.com> Date: Thu Dec 28 14:11:06 2023 +0800 优化小部分网站图标获取失败的问题 commit c8141184a14fb02f941bbec03ac98f59f8b12d4b Author: Sun <95302870@qq.com> Date: Thu Dec 28 13:00:56 2023 +0800 优化上传管理界面
This commit is contained in:
@@ -1 +1 @@
|
||||
7|1.2.0
|
||||
8|1.2.1
|
||||
@@ -2,7 +2,6 @@ package siteFavicon
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
@@ -13,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func IsHTTPURL(url string) bool {
|
||||
httpPattern := `^(http://|https://)`
|
||||
httpPattern := `^(http://|https://|//)`
|
||||
match, err := regexp.MatchString(httpPattern, url)
|
||||
if err != nil {
|
||||
return false
|
||||
@@ -24,7 +23,6 @@ func IsHTTPURL(url string) bool {
|
||||
func GetOneFaviconURL(urlStr string) (string, bool) {
|
||||
iconURLs, err := getFaviconURL(urlStr)
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
return "", false
|
||||
}
|
||||
|
||||
@@ -44,10 +42,20 @@ func GetOneFaviconURL(urlStr string) (string, bool) {
|
||||
func getFaviconURL(url string) ([]string, error) {
|
||||
var icons []string
|
||||
icons = make([]string, 0)
|
||||
resp, err := http.Get(url)
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return icons, err
|
||||
}
|
||||
|
||||
// 设置User-Agent头字段,模拟浏览器请求
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3")
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return icons, err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
@@ -71,7 +79,7 @@ func getFaviconURL(url string) ([]string, error) {
|
||||
})
|
||||
|
||||
if len(icons) == 0 {
|
||||
return icons, fmt.Errorf("favicon not found on the page")
|
||||
return icons, errors.New("favicon not found on the page")
|
||||
}
|
||||
|
||||
return icons, nil
|
||||
|
||||
Reference in New Issue
Block a user