add image checker, web vulnerability

This commit is contained in:
YouROK
2022-03-16 18:36:59 +03:00
parent 0e9378ea5d
commit 9dc219739d
2 changed files with 31 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package torr
import ( import (
"encoding/json" "encoding/json"
"server/torr/utils"
"time" "time"
"server/settings" "server/settings"
@@ -29,7 +30,9 @@ func AddTorrentDB(torr *Torrent) {
} else { } else {
t.Data = torr.Data t.Data = torr.Data
} }
if utils.CheckImgUrl(torr.Poster) {
t.Poster = torr.Poster t.Poster = torr.Poster
}
t.Size = torr.Size t.Size = torr.Size
if t.Size == 0 && torr.Torrent != nil { if t.Size == 0 && torr.Torrent != nil {
t.Size = torr.Torrent.Length() t.Size = torr.Torrent.Length()

View File

@@ -0,0 +1,27 @@
package utils
import (
"image"
_ "image/jpeg"
_ "image/png"
"net/http"
"server/log"
)
func CheckImgUrl(link string) bool {
if link == "" {
return false
}
resp, err := http.Get(link)
if err != nil {
log.TLogln("Error check image:", err)
return false
}
defer resp.Body.Close()
_, _, err = image.Decode(resp.Body)
if err != nil {
log.TLogln("Error decode image:", err)
return false
}
return err == nil
}