link tweaks

This commit is contained in:
simon987 2020-04-11 15:01:20 -04:00
parent e22bdc44bc
commit 6cb9b3b758
2 changed files with 26 additions and 21 deletions

20
core.go
View File

@ -26,9 +26,7 @@ var ImageSuffixes = []string{
".bmp", ".webp", ".bmp", ".webp",
} }
var ImageBlackList = []string{ var ImageBlackList = []string{}
}
var Rdb *redis.Client var Rdb *redis.Client
var Pgdb *pgx.ConnPool var Pgdb *pgx.ConnPool
@ -97,22 +95,6 @@ func isHttpOk(code int) bool {
return code >= 200 && code < 300 return code >= 200 && code < 300
} }
func IsImageLink(link string) bool {
u, err := url.Parse(link)
if err != nil {
return false
}
path := strings.ToLower(u.Path)
for _, suffix := range ImageSuffixes {
if strings.HasSuffix(path, suffix) {
return true
}
}
return false
}
func FetchJson(link string, v interface{}, raw *[]byte, headers ...[]string) error { func FetchJson(link string, v interface{}, raw *[]byte, headers ...[]string) error {
body, err := Fetch(link, headers...) body, err := Fetch(link, headers...)

27
link.go
View File

@ -2,7 +2,9 @@ package imhashdb
import ( import (
"go.uber.org/zap" "go.uber.org/zap"
"net/url"
"regexp" "regexp"
"strings"
"time" "time"
) )
@ -14,15 +16,36 @@ type ImgurImgResp struct {
} }
type ImgurImg struct { type ImgurImg struct {
Link string `json:"link"` Link string `json:"link"`
} }
type ImgurAlbumResp struct { type ImgurAlbumResp struct {
Data struct { Data struct {
Images []ImgurImg `json:"images"` Images []ImgurImg `json:"images"`
} `json:"data"` } `json:"data"`
} }
func IsImageLink(link string) bool {
if strings.HasPrefix(link, "https://i.reddituploads.com") {
return true
}
u, err := url.Parse(link)
if err != nil {
return false
}
path := strings.ToLower(u.Path)
for _, suffix := range ImageSuffixes {
if strings.HasSuffix(path, suffix) {
return true
}
}
return false
}
func handleImgurLink(link string, meta *[]Meta) []string { func handleImgurLink(link string, meta *[]Meta) []string {
if ReImgurImg.MatchString(link) { if ReImgurImg.MatchString(link) {