mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 06:14:22 +01:00
catch panics on nsfw image detection.
This commit is contained in:
@@ -27,6 +27,13 @@ var nsfwPredictor = func() *nsfw.Predictor {
|
||||
var tempFileLocks = [3]sync.Mutex{{}, {}, {}}
|
||||
|
||||
func isImageNSFW(url string) bool {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Error().Interface("err", r).Str("url", url).Msg("panic while checking nsfw")
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
if is, ok := nsfwCache.Get(url); ok {
|
||||
return is
|
||||
}
|
||||
|
||||
@@ -118,6 +118,7 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
for _, url := range allUrls {
|
||||
url = strings.Split(strings.Split(url, "?")[0], "#")[0]
|
||||
if imageExtensionMatcher.MatchString(url) {
|
||||
if isImageNSFW(url) {
|
||||
log.Warn().Str("url", url).Str("event", data.nevent).Msg("detect nsfw image")
|
||||
|
||||
Reference in New Issue
Block a user