Ignore invalid image URLs

This commit is contained in:
marmei
2019-08-03 14:20:26 +02:00
parent 0063dcc523
commit c9bc4aedbc
7 changed files with 49 additions and 22 deletions

View File

@@ -113,6 +113,7 @@ func Init() (err error) {
}
showInfo(fmt.Sprintf("Version:%s Build: %s", System.Version, System.Build))
showInfo(fmt.Sprintf("Database Version:%s", System.DBVersion))
showInfo(fmt.Sprintf("System IP Addresses:IPv4: %d | IPv6: %d", len(System.IPAddressesV4), len(System.IPAddressesV6)))
showInfo("Hostname:" + System.Hostname)
showInfo(fmt.Sprintf("System Folder:%s", getPlatformPath(System.Folder.Config)))

View File

@@ -6,24 +6,41 @@ import (
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
)
func getCacheImageURL(url string) (cacheImageURL string) {
func getCacheImageURL(imageURL string) (cacheImageURL string) {
url = strings.Trim(url, "\r\n")
if Settings.CacheImages == false {
return imageURL
}
var urlMD5 = getMD5(url)
var fileExtension = filepath.Ext(url)
imageURL = strings.Trim(imageURL, "\r\n")
p, err := url.Parse(imageURL)
if err != nil {
// URL konnte nicht geparst werden, die ursprüngliche image url wird zurückgegeben
showInfo(fmt.Sprintf("Image Caching:Image URL: %s", imageURL))
showWarning(4101)
return imageURL
}
var urlMD5 = getMD5(imageURL)
var fileExtension = filepath.Ext(p.Path)
if len(fileExtension) == 0 {
// Keine Dateierweiterung vorhanden, die ursprüngliche image url wird zurückgegeben
return imageURL
}
if indexOfString(urlMD5+fileExtension, Data.Cache.ImagesFiles) == -1 {
Data.Cache.ImagesFiles = append(Data.Cache.ImagesFiles, urlMD5+fileExtension)
}
if Settings.CacheImages == false || System.ImageCachingInProgress == 1 {
return url
if System.ImageCachingInProgress == 1 {
return imageURL
}
if indexOfString(urlMD5+fileExtension, Data.Cache.ImagesCache) != -1 {
@@ -32,15 +49,15 @@ func getCacheImageURL(url string) (cacheImageURL string) {
} else {
if strings.Contains(url, System.Domain+"/images/") == false {
if strings.Contains(imageURL, System.Domain+"/images/") == false {
if indexOfString(url, Data.Cache.ImagesURLS) == -1 {
Data.Cache.ImagesURLS = append(Data.Cache.ImagesURLS, url)
if indexOfString(imageURL, Data.Cache.ImagesURLS) == -1 {
Data.Cache.ImagesURLS = append(Data.Cache.ImagesURLS, imageURL)
}
}
cacheImageURL = url
cacheImageURL = imageURL
}
@@ -57,10 +74,10 @@ func cachingImages() {
showInfo("Image Caching:Images are cached")
for _, url := range Data.Cache.ImagesURLS {
for _, imageURL := range Data.Cache.ImagesURLS {
if len(url) > 0 {
cacheImage(url)
if len(imageURL) > 0 {
cacheImage(imageURL)
}
}
@@ -94,16 +111,16 @@ func cachingImages() {
return
}
func cacheImage(url string) {
func cacheImage(imageURL string) {
var debug string
var urlMD5 = getMD5(url)
var fileExtension = filepath.Ext(url)
var urlMD5 = getMD5(imageURL)
var fileExtension = filepath.Ext(imageURL)
debug = fmt.Sprintf("Image Caching:File: %s Download: %s", urlMD5+fileExtension, url)
debug = fmt.Sprintf("Image Caching:File: %s Download: %s", urlMD5+fileExtension, imageURL)
showDebug(debug, 1)
resp, err := http.Get(url)
resp, err := http.Get(imageURL)
if err != nil {
return
}

View File

@@ -351,6 +351,8 @@ func getErrMsg(errCode int) (errMsg string) {
// Caching
case 4100:
errMsg = fmt.Sprintf("Unknown content type for downloaded image")
case 4101:
errMsg = fmt.Sprintf("Invalid URL, original URL is used for this image")
// API
case 5000:

View File

@@ -15,6 +15,7 @@ type SystemStruct struct {
Build string
Compatibility string
ConfigurationWizard bool
DBVersion string
Dev bool
DeviceID string
Domain string

View File

@@ -133,7 +133,7 @@ func loadSettings() (settings SettingsStrcut, err error) {
defaults["update"] = []string{"0000"}
defaults["user.agent"] = System.Name
defaults["uuid"] = createUUID()
defaults["version"] = System.Version
defaults["version"] = System.DBVersion
defaults["xteveAutoUpdate"] = true
defaults["temp.path"] = System.Folder.Temp
@@ -159,6 +159,8 @@ func loadSettings() (settings SettingsStrcut, err error) {
showInfo(fmt.Sprintf("Git Branch:Switching Git Branch to -> %s", settings.Branch))
}
settings.Version = System.DBVersion
err = saveSettings(settings)
return

View File

@@ -189,7 +189,7 @@ checkVersion:
var newFilterMap = convertToNewFilter(oldFilter)
settingsMap["filter"] = newFilterMap
settingsMap["version"] = "1.9.0"
settingsMap["version"] = "2.0.0"
err = saveMapToJSONFile(System.File.Settings, settingsMap)
if err != nil {
@@ -203,7 +203,7 @@ checkVersion:
return
}
case "1.9.0":
case "2.0.0":
// Falls es in einem späteren Update Änderungen an der Datenbank gibt, geht es hier weiter
break