proxy.go 870 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2020 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package proxy // import "miniflux.app/proxy"
  5. import (
  6. "encoding/base64"
  7. "net/url"
  8. "path"
  9. "miniflux.app/http/route"
  10. "github.com/gorilla/mux"
  11. "miniflux.app/config"
  12. )
  13. // ProxifyURL generates an URL for a proxified resource.
  14. func ProxifyURL(router *mux.Router, link string) string {
  15. if link != "" {
  16. proxyImageUrl := config.Opts.ProxyImageUrl()
  17. if proxyImageUrl == "" {
  18. return route.Path(router, "proxy", "encodedURL", base64.URLEncoding.EncodeToString([]byte(link)))
  19. }
  20. proxyUrl, err := url.Parse(proxyImageUrl)
  21. if err != nil {
  22. return ""
  23. }
  24. proxyUrl.Path = path.Join(proxyUrl.Path, base64.URLEncoding.EncodeToString([]byte(link)))
  25. return proxyUrl.String()
  26. }
  27. return ""
  28. }