mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 03:26:37 +08:00
bug处理
bug处理
This commit is contained in:
@@ -82,14 +82,37 @@ func (p *ImageProxy) fetchRemoteImageOnce(ctx context.Context, raw, host string,
|
||||
func applyRemoteImageHeaders(req *http.Request, host string) {
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0 Safari/537.36")
|
||||
req.Header.Set("Accept", "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8")
|
||||
req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
|
||||
req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,ja;q=0.8,en;q=0.7")
|
||||
req.Header.Set("Cache-Control", "no-cache")
|
||||
req.Header.Set("Pragma", "no-cache")
|
||||
if referer := remoteImageReferer(host); referer != "" {
|
||||
req.Header.Set("Referer", referer)
|
||||
}
|
||||
}
|
||||
|
||||
func remoteImageReferer(host string) string {
|
||||
h := strings.ToLower(strings.TrimSpace(host))
|
||||
switch {
|
||||
case strings.Contains(host, "doubanio.com"):
|
||||
req.Header.Set("Referer", "https://movie.douban.com/")
|
||||
case strings.Contains(host, "bgm.tv"):
|
||||
req.Header.Set("Referer", "https://bgm.tv/")
|
||||
case strings.Contains(h, "doubanio.com"):
|
||||
return "https://movie.douban.com/"
|
||||
case strings.Contains(h, "bgm.tv"):
|
||||
return "https://bgm.tv/"
|
||||
case strings.Contains(h, "javbus") || strings.Contains(h, "busjav") || strings.Contains(h, "dmmbus") || strings.Contains(h, "javsee"):
|
||||
return "https://www.javbus.com/"
|
||||
case strings.Contains(h, "javdb") || strings.Contains(h, "jdbstatic"):
|
||||
return "https://javdb.com/"
|
||||
case strings.Contains(h, "dmm.co.jp") || strings.Contains(h, "dmm.com"):
|
||||
return "https://www.dmm.co.jp/"
|
||||
case strings.Contains(h, "mgstage.com"):
|
||||
return "https://www.mgstage.com/"
|
||||
case strings.Contains(h, "faleno.jp"):
|
||||
return "https://faleno.jp/"
|
||||
case strings.Contains(h, "fc2.com"):
|
||||
return "https://adult.contents.fc2.com/"
|
||||
case h != "":
|
||||
return "https://" + h + "/"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,8 +143,8 @@ func fetchRemoteImageWithCurl(ctx context.Context, raw, host string) ([]byte, st
|
||||
"--header", "Cache-Control: no-cache",
|
||||
"--header", "Pragma: no-cache",
|
||||
}
|
||||
if isDoubanImageHost(host) {
|
||||
args = append(args, "--referer", "https://movie.douban.com/")
|
||||
if referer := remoteImageReferer(host); referer != "" {
|
||||
args = append(args, "--referer", referer)
|
||||
}
|
||||
args = append(args, "--", raw)
|
||||
|
||||
|
||||
@@ -299,3 +299,26 @@ func TestImageProxyDoesNotCacheMislabeledRemoteResponse(t *testing.T) {
|
||||
t.Fatalf("upstream calls = %d, want 1", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteImageRefererForAdultHosts(t *testing.T) {
|
||||
tests := []struct {
|
||||
host string
|
||||
want string
|
||||
}{
|
||||
{"www.javbus.com", "https://www.javbus.com/"},
|
||||
{"pics.dmm.co.jp", "https://www.dmm.co.jp/"},
|
||||
{"javdb.com", "https://javdb.com/"},
|
||||
{"image.mgstage.com", "https://www.mgstage.com/"},
|
||||
{"img.faleno.jp", "https://faleno.jp/"},
|
||||
{"adult.contents.fc2.com", "https://adult.contents.fc2.com/"},
|
||||
{"img1.doubanio.com", "https://movie.douban.com/"},
|
||||
{"lain.bgm.tv", "https://bgm.tv/"},
|
||||
{"example.com", "https://example.com/"},
|
||||
{"", ""},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := remoteImageReferer(tt.host); got != tt.want {
|
||||
t.Errorf("remoteImageReferer(%q) = %q, want %q", tt.host, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user