referer_override.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package rewrite // import "miniflux.app/v2/internal/reader/rewrite"
  4. import (
  5. "net/url"
  6. "strings"
  7. )
  8. // GetRefererForURL returns the referer for the given URL if it exists, otherwise an empty string.
  9. func GetRefererForURL(u string) string {
  10. parsedUrl, err := url.Parse(u)
  11. if err != nil {
  12. return ""
  13. }
  14. switch parsedUrl.Hostname() {
  15. case "appinn.com":
  16. return "https://appinn.com"
  17. case "bjp.org.cn":
  18. return "https://bjp.org.cn"
  19. case "cdnfile.sspai.com":
  20. return "https://sspai.com"
  21. case "f.video.weibocdn.com":
  22. return "https://weibo.com"
  23. case "i.pximg.net":
  24. return "https://www.pixiv.net"
  25. case "img.hellogithub.com":
  26. return "https://hellogithub.com"
  27. case "moyu.im":
  28. return "https://i.jandan.net"
  29. case "www.parkablogs.com":
  30. return "https://www.parkablogs.com"
  31. }
  32. switch {
  33. case strings.HasSuffix(parsedUrl.Hostname(), ".cdninstagram.com"):
  34. return "https://www.instagram.com"
  35. case strings.HasSuffix(parsedUrl.Hostname(), ".moyu.im"):
  36. return "https://i.jandan.net"
  37. case strings.HasSuffix(parsedUrl.Hostname(), ".sinaimg.cn"):
  38. return "https://weibo.com"
  39. }
  40. return ""
  41. }