mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-14 06:57:35 +08:00
show error when request file name extension is invalid when using map image proxy
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user