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

38 lines
870 B
Go
Raw Normal View History

2020-10-07 22:21:45 -07:00
// Copyright 2020 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package proxy // import "miniflux.app/proxy"
import (
"encoding/base64"
2022-08-29 21:33:47 -06:00
"net/url"
"path"
2020-10-07 22:21:45 -07:00
"miniflux.app/http/route"
"github.com/gorilla/mux"
2022-08-29 21:33:47 -06:00
"miniflux.app/config"
2020-10-07 22:21:45 -07:00
)
// ProxifyURL generates an URL for a proxified resource.
func ProxifyURL(router *mux.Router, link string) string {
2022-07-05 21:13:40 -07:00
if link != "" {
2022-08-29 21:33:47 -06:00
proxyImageUrl := config.Opts.ProxyImageUrl()
if proxyImageUrl == "" {
return route.Path(router, "proxy", "encodedURL", base64.URLEncoding.EncodeToString([]byte(link)))
}
proxyUrl, err := url.Parse(proxyImageUrl)
if err != nil {
return ""
}
proxyUrl.Path = path.Join(proxyUrl.Path, base64.URLEncoding.EncodeToString([]byte(link)))
return proxyUrl.String()
2022-07-05 21:13:40 -07:00
}
return ""
2020-10-07 22:21:45 -07:00
}