mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-09-11 22:45:34 +00:00
fix: make hex query params case-insensitive
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"encoding/hex"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/MeshCore-Beacon/beacon-server/internal/api"
|
||||
@@ -63,7 +64,7 @@ func listChannels(reader api.Reader) http.HandlerFunc {
|
||||
cursor = c
|
||||
}
|
||||
var hashHex []byte
|
||||
if hash := r.URL.Query().Get("hash"); hash != "" {
|
||||
if hash := strings.ToLower(r.URL.Query().Get("hash")); hash != "" {
|
||||
h, decodeErr := hex.DecodeString(hash)
|
||||
if decodeErr != nil {
|
||||
respondError(w, http.StatusBadRequest, "invalid channel hash")
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"encoding/hex"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/MeshCore-Beacon/beacon-server/internal/api"
|
||||
@@ -44,7 +45,7 @@ func MessagesRouter(reader api.Reader) http.Handler {
|
||||
func listMessages(reader api.Reader) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
channelIDParam := r.URL.Query().Get("channelID")
|
||||
channelHashParam := r.URL.Query().Get("channelHash")
|
||||
channelHashParam := strings.ToLower(r.URL.Query().Get("channelHash"))
|
||||
if channelIDParam != "" && channelHashParam != "" {
|
||||
respondError(w, http.StatusBadRequest, "filter by either channelId or channelHash, not both")
|
||||
return
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"encoding/hex"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/MeshCore-Beacon/beacon-server/internal/api"
|
||||
"github.com/go-chi/chi/v5"
|
||||
@@ -83,7 +84,7 @@ func listNodes(reader api.Reader) http.HandlerFunc {
|
||||
cursor = c
|
||||
}
|
||||
var pubkey []byte
|
||||
if pubkeyParam := r.URL.Query().Get("pubkey"); pubkeyParam != "" {
|
||||
if pubkeyParam := strings.ToLower(r.URL.Query().Get("pubkey")); pubkeyParam != "" {
|
||||
b, err := hex.DecodeString(pubkeyParam)
|
||||
if err != nil {
|
||||
respondError(w, http.StatusBadRequest, "pubkey must be a valid hex string")
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"encoding/hex"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/MeshCore-Beacon/beacon-server/internal/api"
|
||||
@@ -212,7 +213,7 @@ func listPacketsBackfill(reader api.Reader) http.HandlerFunc {
|
||||
// @Router /packets/{packetHash} [get]
|
||||
func getPacket(reader api.Reader) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
hashHex := chi.URLParam(r, "packetHash")
|
||||
hashHex := strings.ToLower(chi.URLParam(r, "packetHash"))
|
||||
hash, err := hex.DecodeString(hashHex)
|
||||
if err != nil {
|
||||
respondError(w, http.StatusBadRequest, "invalid packet hash")
|
||||
|
||||
@@ -6,6 +6,7 @@ package handlers
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/MeshCore-Beacon/beacon-server/internal/api"
|
||||
@@ -80,9 +81,9 @@ func listKnownRoutes(reader api.Reader) http.HandlerFunc {
|
||||
// @Router /routes/search [get]
|
||||
func searchKnownRoutes(reader api.Reader) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
iata := r.URL.Query().Get("iata")
|
||||
from := r.URL.Query().Get("from")
|
||||
to := r.URL.Query().Get("to")
|
||||
iata := strings.ToUpper(r.URL.Query().Get("iata"))
|
||||
from := strings.ToLower(r.URL.Query().Get("from"))
|
||||
to := strings.ToLower(r.URL.Query().Get("to"))
|
||||
if iata == "" || from == "" || to == "" {
|
||||
respondError(w, http.StatusBadRequest, "iata, from and to are required")
|
||||
return
|
||||
@@ -111,10 +112,10 @@ func searchKnownRoutes(reader api.Reader) http.HandlerFunc {
|
||||
// @Router /routes/cross [get]
|
||||
func searchCrossIATARoutes(reader api.Reader) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
fromHash := r.URL.Query().Get("fromHash")
|
||||
fromIATA := r.URL.Query().Get("fromIata")
|
||||
toHash := r.URL.Query().Get("toHash")
|
||||
toIATA := r.URL.Query().Get("toIata")
|
||||
fromHash := strings.ToLower(r.URL.Query().Get("fromHash"))
|
||||
fromIATA := strings.ToUpper(r.URL.Query().Get("fromIata"))
|
||||
toHash := strings.ToLower(r.URL.Query().Get("toHash"))
|
||||
toIATA := strings.ToUpper(r.URL.Query().Get("toIata"))
|
||||
if fromHash == "" || fromIATA == "" || toHash == "" || toIATA == "" {
|
||||
respondError(w, http.StatusBadRequest, "fromHash, fromIata, toHash and toIata are required")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user