1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

feat(rewrite): add parkablogs.com to the referer override list

This commit is contained in:
Frédéric Guillot 2025-06-16 20:24:10 -07:00
parent 237672a62c
commit da4ab4263c
3 changed files with 52 additions and 42 deletions

View file

@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package rewrite // import "miniflux.app/v2/internal/reader/rewrite"
import (
"net/url"
"strings"
)
// GetRefererForURL returns the referer for the given URL if it exists, otherwise an empty string.
func GetRefererForURL(u string) string {
parsedUrl, err := url.Parse(u)
if err != nil {
return ""
}
switch parsedUrl.Hostname() {
case "appinn.com":
return "https://appinn.com"
case "bjp.org.cn":
return "https://bjp.org.cn"
case "cdnfile.sspai.com":
return "https://sspai.com"
case "f.video.weibocdn.com":
return "https://weibo.com"
case "i.pximg.net":
return "https://www.pixiv.net"
case "img.hellogithub.com":
return "https://hellogithub.com"
case "moyu.im":
return "https://i.jandan.net"
case "www.parkablogs.com":
return "https://www.parkablogs.com"
}
switch {
case strings.HasSuffix(parsedUrl.Hostname(), ".cdninstagram.com"):
return "https://www.instagram.com"
case strings.HasSuffix(parsedUrl.Hostname(), ".moyu.im"):
return "https://i.jandan.net"
case strings.HasSuffix(parsedUrl.Hostname(), ".sinaimg.cn"):
return "https://weibo.com"
}
return ""
}

View file

@ -43,6 +43,11 @@ func TestGetRefererForURL(t *testing.T) {
url: "https://img.hellogithub.com/example.png", url: "https://img.hellogithub.com/example.png",
expected: "https://hellogithub.com", expected: "https://hellogithub.com",
}, },
{
name: "Park Blogs",
url: "https://www.parkablogs.com/sites/default/files/2025/image.jpg",
expected: "https://www.parkablogs.com",
},
{ {
name: "Non-matching URL", name: "Non-matching URL",
url: "https://example.com/image.jpg", url: "https://example.com/image.jpg",

View file

@ -3,13 +3,7 @@
package rewrite // import "miniflux.app/v2/internal/reader/rewrite" package rewrite // import "miniflux.app/v2/internal/reader/rewrite"
import (
"net/url"
"strings"
)
// List of predefined rewrite rules (alphabetically sorted) // List of predefined rewrite rules (alphabetically sorted)
// Available rules: "add_image_title", "add_youtube_video"
// domain => rule name // domain => rule name
var predefinedRules = map[string]string{ var predefinedRules = map[string]string{
"abstrusegoose.com": "add_image_title", "abstrusegoose.com": "add_image_title",
@ -40,39 +34,3 @@ var predefinedRules = map[string]string{
"xkcd.com": "add_image_title", "xkcd.com": "add_image_title",
"youtube.com": "add_youtube_video", "youtube.com": "add_youtube_video",
} }
// GetRefererForURL returns the referer for the given URL if it exists, otherwise an empty string.
func GetRefererForURL(u string) string {
parsedUrl, err := url.Parse(u)
if err != nil {
return ""
}
switch parsedUrl.Hostname() {
case "appinn.com":
return "https://appinn.com"
case "bjp.org.cn":
return "https://bjp.org.cn"
case "cdnfile.sspai.com":
return "https://sspai.com"
case "f.video.weibocdn.com":
return "https://weibo.com"
case "i.pximg.net":
return "https://www.pixiv.net"
case "img.hellogithub.com":
return "https://hellogithub.com"
case "moyu.im":
return "https://i.jandan.net"
}
switch {
case strings.HasSuffix(parsedUrl.Hostname(), ".cdninstagram.com"):
return "https://www.instagram.com"
case strings.HasSuffix(parsedUrl.Hostname(), ".moyu.im"):
return "https://i.jandan.net"
case strings.HasSuffix(parsedUrl.Hostname(), ".sinaimg.cn"):
return "https://weibo.com"
}
return ""
}