Skip to content

Commit c759c9b

Browse files
committed
webui: encode and ship queries as json
1 parent c002c54 commit c759c9b

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

internal/search/api_search.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package search
22

33
import (
4+
"encoding/base64"
45
"encoding/json"
56
"fmt"
6-
"io"
77
"net/http"
88

99
"github.com/moov-io/ach-web-viewer/pkg/filelist"
@@ -70,15 +70,26 @@ func (c *controller) index(w http.ResponseWriter, r *http.Request) {
7070
}
7171
}
7272

73+
type searchRequest struct {
74+
Query string `json:"query"`
75+
}
76+
7377
func (c *controller) search(w http.ResponseWriter, r *http.Request) {
7478
ctx, span := telemetry.StartSpan(r.Context(), "api-search")
7579
defer span.End()
7680

77-
query, err := io.ReadAll(r.Body)
81+
var req searchRequest
82+
err := json.NewDecoder(r.Body).Decode(&req)
83+
if err != nil {
84+
c.errorResponse(w, fmt.Errorf("reading search request: %v", err))
85+
return
86+
}
87+
query, err := base64.StdEncoding.DecodeString(req.Query)
7888
if err != nil {
79-
c.errorResponse(w, fmt.Errorf("problem reading search body: %v", err))
89+
c.errorResponse(w, fmt.Errorf("problem decoding query body: %v", err))
8090
return
8191
}
92+
fmt.Printf("\n\n%s\n", string(query))
8293

8394
options, err := filelist.ReadListOptions(r)
8495
if err != nil {

webui/static/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ window.onload = function () {
291291
});
292292
};
293293

294+
function encodeSQLToBase64(sql) {
295+
return btoa(sql);
296+
}
297+
294298
function performSearch(body) {
295299
const currentParams = new URLSearchParams(window.location.search);
296300
const queryParams = new URLSearchParams();
@@ -314,7 +318,9 @@ function performSearch(body) {
314318
headers: {
315319
"Content-Type": "text/plain",
316320
},
317-
body: body,
321+
body: JSON.stringify({
322+
query: encodeSQLToBase64(body),
323+
}),
318324
})
319325
.then((response) => response.json())
320326
.then((data) => {

0 commit comments

Comments
 (0)