@@ -126,6 +126,26 @@ type response struct {
126126 Message string `json:"message,omitempty"`
127127}
128128
129+ // postTilepack starts or polls tilepack generation for one STAC item.
130+ //
131+ // Endpoint:
132+ //
133+ // POST /tilepacks/{id}?format=pmtiles|mbtiles[&min_zoom=N&max_zoom=N]
134+ //
135+ // The same endpoint is used for trigger + polling. Clients should re-POST
136+ // the same URL until status becomes "ready".
137+ //
138+ // Zoom modes:
139+ // - Canonical request: min_zoom and max_zoom omitted.
140+ // Worker derives zooms from source GSD; resulting artifact is the
141+ // canonical item+format variant and is represented in STAC assets.
142+ // - Non-canonical request: min_zoom and max_zoom both provided.
143+ // Worker generates exactly that range; artifact is served from S3 via
144+ // response URL and is intentionally not written to STAC.
145+ //
146+ // Typical statuses:
147+ // - 202 {"status":"started"} or {"status":"in_progress"}
148+ // - 200 {"status":"ready","url":"https://..."}
129149func (h * Handler ) postTilepack (w http.ResponseWriter , r * http.Request ) {
130150 started := time .Now ()
131151 id := r .PathValue ("id" )
@@ -164,6 +184,13 @@ func (h *Handler) postTilepack(w http.ResponseWriter, r *http.Request) {
164184 respond (http .StatusBadRequest , response {Status : "error" , Message : err .Error ()}, "invalid_input" )
165185 return
166186 }
187+ // "canonical" means the default tilepack variant for an item+format:
188+ // the caller did not set min/max zoom, so the worker derives zooms
189+ // from source GSD and this artifact is represented in STAC.
190+ //
191+ // Non-canonical means a caller explicitly requested min/max zoom.
192+ // Those are generated and served from S3, but intentionally not
193+ // written to STAC so one request cannot overwrite catalogue metadata.
167194 canonical := minZoom == 0 && maxZoom == 0
168195
169196 // Per-IP rate limit happens before any expensive work so abusive
@@ -252,8 +279,13 @@ func (h *Handler) postTilepack(w http.ResponseWriter, r *http.Request) {
252279 // If STAC says asset exists but S3 object is missing, fall through
253280 // and regenerate so both systems converge.
254281 } else if s3Exists {
255- // Non-canonical requests are represented by the concrete S3 object,
256- // not by a STAC asset entry.
282+ // Non-canonical (custom zoom) requests are not represented in
283+ // STAC. The caller gets a direct S3-backed public URL instead.
284+ //
285+ // Why: STAC should describe the single canonical archive for an
286+ // item+format. If we patched STAC for custom zoom requests, one
287+ // caller could make STAC metadata (href/minzoom/maxzoom) flip to
288+ // an ad-hoc variant that other users did not ask for.
257289 log .Printf ("ready: stac_id=%s format=%s mode=non_canonical state=s3" , id , format )
258290 respond (http .StatusOK , response {Status : "ready" , URL : h .s3 .PublicURL (outputKey )}, "ready" )
259291 return
0 commit comments