mirror of
https://github.com/sosedoff/pgweb.git
synced 2024-12-14 19:21:46 +03:00
Encode sql query to base64 for CSV export, GH-95
This commit is contained in:
parent
2a4edaf08f
commit
c02d15ec34
@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
@ -174,8 +175,12 @@ func GetTableIndexes(c *gin.Context) {
|
||||
}
|
||||
|
||||
func HandleQuery(query string, c *gin.Context) {
|
||||
result, err := DbClient.Query(query)
|
||||
rawQuery, err := base64.StdEncoding.DecodeString(query)
|
||||
if err == nil {
|
||||
query = string(rawQuery)
|
||||
}
|
||||
|
||||
result, err := DbClient.Query(query)
|
||||
if err != nil {
|
||||
c.JSON(400, NewError(err))
|
||||
return
|
||||
|
File diff suppressed because one or more lines are too long
@ -24,6 +24,10 @@ function getTableIndexes(table, cb) { apiCall("get", "/tables/" + table + "/i
|
||||
function getHistory(cb) { apiCall("get", "/history", {}, cb); }
|
||||
function getBookmarks(cb) { apiCall("get", "/bookmarks", {}, cb); }
|
||||
|
||||
function encodeQuery(query) {
|
||||
return window.btoa(query);
|
||||
}
|
||||
|
||||
function executeQuery(query, cb) {
|
||||
apiCall("post", "/query", { query: query }, cb);
|
||||
}
|
||||
@ -344,10 +348,7 @@ function exportToCSV() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace line breaks with spaces and properly encode query
|
||||
query = window.encodeURI(query.replace(/\n/g, " "));
|
||||
|
||||
var url = "http://" + window.location.host + "/api/query?format=csv&query=" + query;
|
||||
var url = "http://" + window.location.host + "/api/query?format=csv&query=" + encodeQuery(query);
|
||||
var win = window.open(url, '_blank');
|
||||
|
||||
setCurrentTab("table_query");
|
||||
|
Loading…
Reference in New Issue
Block a user