show error when request file name extension is invalid when using map image proxy

This commit is contained in:
MaysWind
2023-10-29 14:54:58 +08:00
parent d18e8211ca
commit 777e14b6d4
2 changed files with 12 additions and 6 deletions
+10 -5
View File
@@ -36,6 +36,16 @@ func (p *MapImageProxy) MapTileImageProxyHandler(c *core.Context) (*httputil.Rev
return nil, errs.ErrMapProviderNotCurrent
}
zoomLevel := c.Param("zoomLevel")
coordinateX := c.Param("coordinateX")
fileName := c.Param("fileName")
fileNameParts := strings.Split(fileName, ".")
coordinateY := fileNameParts[0]
if len(fileNameParts) != 2 || fileNameParts[len(fileNameParts)-1] != "png" {
return nil, errs.ErrImageExtensionNotSupported
}
if mapProvider == settings.OpenStreetMapProvider {
targetUrl = openStreetMapTileImageUrlFormat
} else if mapProvider == settings.OpenStreetMapHumanitarianStyleProvider {
@@ -60,11 +70,6 @@ func (p *MapImageProxy) MapTileImageProxyHandler(c *core.Context) (*httputil.Rev
}
director := func(req *http.Request) {
zoomLevel := c.Param("zoomLevel")
coordinateX := c.Param("coordinateX")
fileName := c.Param("fileName")
coordinateY := strings.Split(fileName, ".")[0]
imageRawUrl := targetUrl
imageRawUrl = strings.Replace(imageRawUrl, "{z}", zoomLevel, -1)
imageRawUrl = strings.Replace(imageRawUrl, "{x}", coordinateX, -1)
+2 -1
View File
@@ -4,5 +4,6 @@ import "net/http"
// Error codes related to map image proxy
var (
ErrMapProviderNotCurrent = NewNormalError(NormalSubcategoryMapProxy, 0, http.StatusBadRequest, "specified map provider is not set")
ErrMapProviderNotCurrent = NewNormalError(NormalSubcategoryMapProxy, 0, http.StatusBadRequest, "specified map provider is not set")
ErrImageExtensionNotSupported = NewNormalError(NormalSubcategoryMapProxy, 0, http.StatusNotFound, "specified image extension is not supported")
)