mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
Improve downloadImage()
This commit is contained in:
parent
8ebb158765
commit
d090e9c860
@ -35,11 +35,7 @@ func downloadImage(client *http.Client, url string) (*bytes.Buffer, string, erro
|
|||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("downloadImage() error for url [%s]: %s\n", url, err.Error())
|
fmt.Printf("downloadImage() error for url [%s]: %s\n", url, err.Error())
|
||||||
if strings.Contains(err.Error(), "EOF") || strings.Contains(err.Error(), "no such host") || strings.Contains(err.Error(), "did not properly respond after a period of time") || strings.Contains(err.Error(), "unrecognized name") {
|
|
||||||
return nil, "", nil
|
return nil, "", nil
|
||||||
} else {
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
@ -58,6 +54,8 @@ func downloadImage(client *http.Client, url string) (*bytes.Buffer, string, erro
|
|||||||
|
|
||||||
if strings.Contains(contentType, "text/html") {
|
if strings.Contains(contentType, "text/html") {
|
||||||
fileExtension = ".html"
|
fileExtension = ".html"
|
||||||
|
} else if contentType == "image/vnd.microsoft.icon" {
|
||||||
|
fileExtension = ".ico"
|
||||||
} else {
|
} else {
|
||||||
fileExtensions, err := mime.ExtensionsByType(contentType)
|
fileExtensions, err := mime.ExtensionsByType(contentType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -186,10 +186,47 @@ func parseSize(sizes string) []int {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var publicEmailDomains = map[string]int{
|
||||||
|
"gmail.com": 1,
|
||||||
|
"163.com": 1,
|
||||||
|
"qq.com": 1,
|
||||||
|
"yahoo.com": 1,
|
||||||
|
"hotmail.com": 1,
|
||||||
|
"outlook.com": 1,
|
||||||
|
"icloud.com": 1,
|
||||||
|
"mail.com": 1,
|
||||||
|
"aol.com": 1,
|
||||||
|
"live.com": 1,
|
||||||
|
"yandex.com": 1,
|
||||||
|
"yahoo.co.jp": 1,
|
||||||
|
"yahoo.co.in": 1,
|
||||||
|
"yahoo.co.uk": 1,
|
||||||
|
"me.com": 1,
|
||||||
|
"msn.com": 1,
|
||||||
|
"comcast.net": 1,
|
||||||
|
"sbcglobal.net": 1,
|
||||||
|
"verizon.net": 1,
|
||||||
|
"earthlink.net": 1,
|
||||||
|
"cox.net": 1,
|
||||||
|
"rediffmail.com": 1,
|
||||||
|
"in.com": 1,
|
||||||
|
"hotmail.co.uk": 1,
|
||||||
|
"hotmail.fr": 1,
|
||||||
|
"zoho.com": 1,
|
||||||
|
"gmx.com": 1,
|
||||||
|
"gmx.de": 1,
|
||||||
|
"gmx.net": 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
func isPublicEmailDomain(domain string) bool {
|
||||||
|
_, exists := publicEmailDomains[domain]
|
||||||
|
return exists
|
||||||
|
}
|
||||||
|
|
||||||
func getFaviconFileBuffer(client *http.Client, email string) (*bytes.Buffer, string, error) {
|
func getFaviconFileBuffer(client *http.Client, email string) (*bytes.Buffer, string, error) {
|
||||||
tokens := strings.Split(email, "@")
|
tokens := strings.Split(email, "@")
|
||||||
domain := tokens[1]
|
domain := tokens[1]
|
||||||
if domain == "gmail.com" || domain == "163.com" || domain == "qq.com" {
|
if isPublicEmailDomain(domain) {
|
||||||
return nil, "", nil
|
return nil, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user