feat: Remove geometry and properties from GET /datasets/{id} endpoint, new endpoint for download cog file
This commit is contained in:
@@ -2,6 +2,7 @@ package http
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@@ -37,6 +38,7 @@ func (h *DatasetHandler) Register(r chi.Router) {
|
||||
r.Post("/", h.upload)
|
||||
r.Get("/{id}", h.get)
|
||||
r.Get("/{id}.geojson", h.geojson)
|
||||
r.Get("/{id}.cog", h.cog)
|
||||
r.Get("/{id}/status", h.status)
|
||||
r.Get("/{id}/download", h.download)
|
||||
r.Post("/{id}/mapping", h.mapping)
|
||||
@@ -324,6 +326,44 @@ func (h *DatasetHandler) geojson(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = w.Write(fc)
|
||||
}
|
||||
|
||||
// cog streams the raster dataset's Cloud-Optimized GeoTIFF. It responds 422 for
|
||||
// a non-raster dataset and 409 when the raster's COG has not been produced yet.
|
||||
func (h *DatasetHandler) cog(w http.ResponseWriter, r *http.Request) {
|
||||
id, ok := parseUUIDParam(w, r, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
dataset, obj, err := h.svc.COG(r.Context(), id)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, service.ErrNotRaster):
|
||||
httputil.WriteError(w, http.StatusUnprocessableEntity, "dataset is not a raster")
|
||||
case errors.Is(err, service.ErrCOGNotReady):
|
||||
httputil.WriteError(w, http.StatusConflict, "cog is not ready")
|
||||
default:
|
||||
respondDomainError(w, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
defer obj.Close()
|
||||
|
||||
w.Header().Set("Content-Type", "image/tiff")
|
||||
w.Header().Set("Content-Disposition", `inline; filename="`+cogFilename(dataset.Filename)+`"`)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
if _, err := io.Copy(w, obj); err != nil {
|
||||
// Headers are already sent; nothing useful to return to the client.
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// cogFilename derives a .cog.tif download name from the source filename.
|
||||
func cogFilename(filename string) string {
|
||||
if i := strings.LastIndex(filename, "."); i > 0 {
|
||||
filename = filename[:i]
|
||||
}
|
||||
return filename + ".cog.tif"
|
||||
}
|
||||
|
||||
func (h *DatasetHandler) download(w http.ResponseWriter, r *http.Request) {
|
||||
id, ok := parseUUIDParam(w, r, "id")
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user