mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 05:26:09 +05:00
add image checker, web vulnerability
This commit is contained in:
@@ -2,6 +2,7 @@ package torr
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"server/torr/utils"
|
||||
"time"
|
||||
|
||||
"server/settings"
|
||||
@@ -29,7 +30,9 @@ func AddTorrentDB(torr *Torrent) {
|
||||
} else {
|
||||
t.Data = torr.Data
|
||||
}
|
||||
t.Poster = torr.Poster
|
||||
if utils.CheckImgUrl(torr.Poster) {
|
||||
t.Poster = torr.Poster
|
||||
}
|
||||
t.Size = torr.Size
|
||||
if t.Size == 0 && torr.Torrent != nil {
|
||||
t.Size = torr.Torrent.Length()
|
||||
|
||||
27
server/torr/utils/webImageChecker.go
Normal file
27
server/torr/utils/webImageChecker.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user