Add debug endpoint for looking at tiles via GPS coord

This commit is contained in:
Eli Ribble 2026-03-01 21:14:48 +00:00
parent 89eda187be
commit 8bfad892bc
No known key found for this signature in database
3 changed files with 66 additions and 8 deletions

View file

@ -46,7 +46,7 @@ func getComplianceRequestImagePool(w http.ResponseWriter, r *http.Request) {
}
ring := (*envelope)[0]
p := ring[0]
err = writeImage(ctx, w, org, 22, p[1], p[0])
err = writeImage(ctx, w, org, 19, p[1], p[0])
if err != nil {
log.Error().Err(err).Msg("write image")
http.Error(w, "failed to write image", http.StatusInternalServerError)

View file

@ -48,15 +48,23 @@ func Router() chi.Router {
// Authenticated endpoints
r.Route("/api", api.AddRoutes)
r.Method("GET", "/admin", authenticatedHandler(getAdminDash))
r.Method("GET", "/cell/{cell}", authenticatedHandler(getCellDetails))
r.Method("GET", "/communication", authenticatedHandler(getCommunicationRoot))
r.Method("GET", "/configuration", authenticatedHandler(getConfigurationRoot))
r.Method("GET", "/configuration/integration", authenticatedHandler(getConfigurationIntegration))
r.Method("GET", "/configuration/integration/arcgis", authenticatedHandler(getConfigurationIntegrationArcgis))
r.Method("GET", "/configuration/organization", authenticatedHandler(getConfigurationOrganization))
r.Method("GET", "/configuration/pesticide", authenticatedHandler(getConfigurationPesticide))
r.Method("GET", "/configuration/pesticide/add", authenticatedHandler(getConfigurationPesticideAdd))
r.Method("GET", "/configuration/upload", authenticatedHandler(getUploadList))
r.Method("GET", "/configuration/upload/pool", authenticatedHandler(getUploadPoolCreate))
r.Method("POST", "/configuration/upload/pool", authenticatedHandlerPostMultipart(postUploadPoolCreate))
r.Method("GET", "/configuration/upload/{id}", authenticatedHandler(getUploadByID))
r.Method("POST", "/configuration/upload/{id}/discard", authenticatedHandlerPost(postUploadDiscard))
r.Method("GET", "/configuration/user", authenticatedHandler(getConfigurationUserList))
r.Method("GET", "/configuration/user/add", authenticatedHandler(getConfigurationUserAdd))
r.Method("GET", "/download", authenticatedHandler(getDownloadList))
r.Method("GET", "/intelligence", authenticatedHandler(getIntelligenceRoot))
r.Method("GET", "/layout-test", authenticatedHandler(getLayoutTest))
@ -73,13 +81,6 @@ func Router() chi.Router {
r.Method("GET", "/review", authenticatedHandler(getReviewRoot))
r.Method("GET", "/service-request", authenticatedHandler(getServiceRequestList))
r.Method("GET", "/service-request/{id}", authenticatedHandler(getServiceRequestDetail))
r.Method("GET", "/configuration/integration", authenticatedHandler(getConfigurationIntegration))
r.Method("GET", "/configuration/integration/arcgis", authenticatedHandler(getConfigurationIntegrationArcgis))
r.Method("GET", "/configuration/organization", authenticatedHandler(getConfigurationOrganization))
r.Method("GET", "/configuration/pesticide", authenticatedHandler(getConfigurationPesticide))
r.Method("GET", "/configuration/pesticide/add", authenticatedHandler(getConfigurationPesticideAdd))
r.Method("GET", "/configuration/user", authenticatedHandler(getConfigurationUserList))
r.Method("GET", "/configuration/user/add", authenticatedHandler(getConfigurationUserAdd))
r.Method("GET", "/signout", auth.NewEnsureAuth(getSignout))
r.Method("GET", "/source/{globalid}", authenticatedHandler(getSource))
r.Method("GET", "/stadia", authenticatedHandler(getStadia))
@ -88,6 +89,7 @@ func Router() chi.Router {
r.Method("POST", "/sudo/sms", authenticatedHandlerPost(postSudoSMS))
r.Method("GET", "/trap/{globalid}", authenticatedHandler(getTrap))
r.Method("GET", "/text/{destination}", authenticatedHandler(getTextMessages))
r.Method("GET", "/tile/gps", auth.NewEnsureAuth(getTileGPS))
html.AddStaticRoute(r, "/static")
return r

56
sync/tile.go Normal file
View file

@ -0,0 +1,56 @@
package sync
import (
"bytes"
"fmt"
"io"
"net/http"
"strconv"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/Gleipnir-Technology/nidus-sync/platform/imagetile"
)
func getTileGPS(w http.ResponseWriter, r *http.Request, u *models.User) {
ctx := r.Context()
if err := r.ParseForm(); err != nil {
respondError(w, "Could not parse form", err, http.StatusBadRequest)
return
}
lat_s := r.FormValue("lat")
lng_s := r.FormValue("lng")
level_s := r.FormValue("level")
if lat_s == "" || lng_s == "" || level_s == "" {
respondError(w, "you must specify lat, lng, and level", nil, http.StatusBadRequest)
return
}
level, err := strconv.Atoi(level_s)
if err != nil {
respondError(w, "couldn't parse level", err, http.StatusBadRequest)
return
}
lat, err := strconv.ParseFloat(lat_s, 10)
if err != nil {
respondError(w, "couldn't parse lat", err, http.StatusBadRequest)
return
}
lng, err := strconv.ParseFloat(lng_s, 10)
if err != nil {
respondError(w, "couldn't parse lng", err, http.StatusBadRequest)
return
}
org := u.R.Organization
img, err := imagetile.ImageAtPoint(ctx, org, uint(level), lat, lng)
if err != nil {
respondError(w, "image at point", err, http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "image/png")
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(img)))
_, err = io.Copy(w, bytes.NewBuffer(img))
if err != nil {
respondError(w, "copy bytes", err, http.StatusInternalServerError)
return
}
}