add user-agent configuration option

This commit is contained in:
Nils
2026-06-08 18:57:51 +02:00
parent 28425a2e3a
commit 309f892d42
2 changed files with 16 additions and 1 deletions
+13
View File
@@ -105,6 +105,18 @@ If you're a developer or want to modify the code, you can build the application
4. **Open your web browser** and go to `http://localhost:8080`.
## Responsible Usage
**Please use this tool responsibly!** When downloading map tiles:
* **Respect tile server limits:** Use reasonable rate limits to avoid overloading map tile servers. The default rate limit is 50 tiles per second, which is conservative for most servers.
* **Avoid excessive downloads:** Only download the areas and zoom levels you actually need. Downloading entire continents at high zoom levels can generate millions of tiles.
* **Check terms of service:** Review the terms of service of the map tile provider you're using. Some providers have specific restrictions on bulk downloading.
* **Risk of being banned:** Aggressive downloading patterns can result in your IP address being temporarily or permanently banned from tile servers.
* **Consider self-hosting:** For large-scale or repeated downloads, consider setting up your own tile server.
The default settings are designed to be respectful of tile servers, but you can adjust them based on your specific needs and the tile provider's policies.
## File Storage
The downloaded map tiles are stored in the local filesystem. The default directory is `maps`, but you can change this using the `-maps-directory` command-line option. The tiles are organized by map style, zoom level, and tile coordinates.
@@ -118,6 +130,7 @@ You can also use command-line options to configure the application:
* `-max-workers`: The number of concurrent download workers (default: `10`).
* `-rate-limit`: The maximum number of tiles to download per second (default: `50`).
* `-max-retries`: The maximum number of retries for downloading a tile (default: `3`).
* `-user-agent`: User-Agent header for HTTP requests (default: `MapTileDownloader/1.0 (Go)`).
* `-help`: Show the help message.
Example:
+3 -1
View File
@@ -54,6 +54,7 @@ var (
maxWorkers *int
rateLimit *int
maxRetries *int
userAgent *string
)
// Tile represents a single map tile with X, Y coordinates and zoom level Z.
@@ -101,6 +102,7 @@ func main() {
maxWorkers = flag.Int("max-workers", 10, "Number of concurrent download workers")
rateLimit = flag.Int("rate-limit", 50, "Maximum number of tiles to download per second")
maxRetries = flag.Int("max-retries", 3, "Maximum number of retries for downloading a tile")
userAgent = flag.String("user-agent", "MapTileDownloader/1.0 (Go)", "User-Agent header for HTTP requests")
help := flag.Bool("help", false, "Show help message")
flag.Parse()
@@ -426,7 +428,7 @@ func downloadTile(ctx context.Context, msgChan chan<- WSMessage, tile Tile, mapS
time.Sleep(time.Second * time.Duration(math.Pow(2, float64(attempt))))
continue
}
req.Header.Set("User-Agent", "MapTileDownloader/1.0 (Go)")
req.Header.Set("User-Agent", *userAgent)
resp, err := http.DefaultClient.Do(req)
if err != nil {