From 8bfad892bcd0ab98349ea5986ed06859e671ef61 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Sun, 1 Mar 2026 21:14:48 +0000 Subject: [PATCH] Add debug endpoint for looking at tiles via GPS coord --- api/compliance.go | 2 +- sync/routes.go | 16 ++++++++------ sync/tile.go | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 sync/tile.go diff --git a/api/compliance.go b/api/compliance.go index ec0ae3b5..93f6e2a4 100644 --- a/api/compliance.go +++ b/api/compliance.go @@ -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) diff --git a/sync/routes.go b/sync/routes.go index d48280b1..0c77645c 100644 --- a/sync/routes.go +++ b/sync/routes.go @@ -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 diff --git a/sync/tile.go b/sync/tile.go new file mode 100644 index 00000000..c23374af --- /dev/null +++ b/sync/tile.go @@ -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 + } +}