MM-14686 Send all image proxy requests through /api/v4/image (#10775)
* MM-14686 Implement /api/v4/image when proxy is disabled * MM-14686 Send all image proxy requests through /api/v4/image * Update unit tests
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
4552c20d5b
Коммит
dce6cb601f
@@ -10,7 +10,6 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
@@ -105,33 +104,3 @@ func (backend *LocalBackend) GetImageDirect(imageURL string) (io.ReadCloser, str
|
||||
|
||||
return ioutil.NopCloser(recorder.Body), recorder.Header().Get("Content-Type"), nil
|
||||
}
|
||||
|
||||
func (backend *LocalBackend) GetProxiedImageURL(imageURL string) string {
|
||||
siteURL := *backend.proxy.ConfigService.Config().ServiceSettings.SiteURL
|
||||
|
||||
if imageURL == "" || imageURL[0] == '/' || strings.HasPrefix(imageURL, siteURL) {
|
||||
return imageURL
|
||||
}
|
||||
|
||||
return siteURL + "/api/v4/image?url=" + url.QueryEscape(imageURL)
|
||||
}
|
||||
|
||||
func (backend *LocalBackend) GetUnproxiedImageURL(proxiedURL string) string {
|
||||
siteURL := *backend.proxy.ConfigService.Config().ServiceSettings.SiteURL
|
||||
|
||||
if !strings.HasPrefix(proxiedURL, siteURL+"/api/v4/image?url=") {
|
||||
return proxiedURL
|
||||
}
|
||||
|
||||
parsed, err := url.Parse(proxiedURL)
|
||||
if err != nil {
|
||||
return proxiedURL
|
||||
}
|
||||
|
||||
u := parsed.Query()["url"]
|
||||
if len(u) == 0 {
|
||||
return proxiedURL
|
||||
}
|
||||
|
||||
return u[0]
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user