Skip to content

Commit

Permalink
Images from bytea work
Browse files Browse the repository at this point in the history
  • Loading branch information
gazillion101 committed Sep 30, 2022
1 parent 11a144d commit d9f30e1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 100 deletions.
17 changes: 1 addition & 16 deletions web/go/src/authentication/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"aws"
"crypto/rand"
"math/big"
"encoding/base64"
)


Expand Down Expand Up @@ -444,21 +443,7 @@ func GetSelect(schema string, ds *types.DatascopeTable) (types.SqlTestResult, er
err = json.Unmarshal(data, &out)
if(err != nil) {
log.Printf("Error unmarshaling %s\n", err.Error())
} else {
var records [][]string
for _, slice := range out.Records {
var newrecord []string
for _, record := range slice {
rr := base64.StdEncoding.EncodeToString([]byte(record))
// log.Printf("val: %s, rr: %s\n", record, rr)
newrecord = append(newrecord, rr)
}
records = append(records, newrecord)

}
out.Records = records
}
//log.Printf("%v\n", out)
}
return out, err
}

Expand Down
5 changes: 4 additions & 1 deletion web/go/src/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export FILESYSTEM_ROOT='../../assets/'
export AWS_LAMBDAS='{ "DbAnalyzer": "localhost:9080",
"DbSync": "localhost:9081"
}'

[ -z "$DATABASE_PASSWORD" ] && {
DATABASE_PASSWORD=$( grep "^$DATABASE_HOST:\\($DATABASE_PORT\\|[*]\\):[^:]*:$DATABASE_USER:" $HOME/.pgpass | cut -f 5 -d : )
export DATABASE_PASSWORD="$DATABASE_PASSWORD"
}
go test -v ./...


97 changes: 14 additions & 83 deletions web/js/packages/portal/src/App/TestSQL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let columns: HeaderCell[] = []


function IsImage(text): string {

if (text[0] === 'G' && text[1] === 'I' && text[2] === 'F' && text[3] === '8' &&
text[4] === '9' && text[5] === 'a') {
console.log("GIF")
Expand Down Expand Up @@ -134,98 +134,29 @@ function Test() {
headerStyle: { minWidth: '200px' },
formatter: (cell, row) => {

function checkUTF8(text) {
for (let i = 0; i < text.length;) {
let first = text[i]
if (0 == (first & 0b10000000)) {
i = i + 1
continue //ASCII
}
if ((0b11100000 & first) === 0b11000000) {
// possible two byte
if (i > text.length - 1)
return false
let second = text[i + 1]
if ((0b11000000 & second) === 0xb10000000) {
i = i + 2
continue
}
return false
}
if ((0b11110000 & first) === 0b11100000) {
// possible three bytes
if (i > text.length - 2)
return false
let second = text[i + 1]
if ((0b11000000 & second) !== 0xb10000000) {
return false
}
let third = text[i + 2]
if ((0b11000000 & third) !== 0xb10000000) {
return false
}
i = i + 3
}
if ((0b11111000 & first) === 0b11110000) {
// possible four bytes
if (i > text.length - 3)
return false
let second = text[i + 1]
if ((0b11000000 & second) !== 0xb10000000) {
return false
}
let third = text[i + 2]
if ((0b11000000 & third) !== 0xb10000000) {
return false
}
let fourth = text[i + 3]
if ((0b11000000 & fourth) !== 0xb10000000) {
return false
}
i = i + 4
}
return false
}
return true
}
function IsImage(text): string {

if (text[0] === 'G' && text[1] === 'I' && text[2] === 'F' && text[3] === '8' &&
text[4] === '9' && text[5] === 'a') {
console.log("GIF")
return "gif"
}
if (text[0] === 211 && text[1] === 'P' && text[2] === 'N' && text[3] === 'G') {
console.log("PNG")
return "png"
}
if (text[0] === 0xFF && text[1] === 0xD8) {
console.log("JPEG")
return "jpeg"
}

return ""
}
let bcell = b64.base64DecToArr(cell)
if (!checkUTF8(bcell)) {

let b = cell.substring(1, cell.length)
if (cell[0] === '1') {
let bcell = b64.base64DecToArr(b)
let o
let m = IsImage(bcell)
if (m !== "") {

let src = `data:image/${m};base64,${cell}`
cell = <img src={src} width="150px"></img>
let src = `data:image/${m};base64,${b}`

o = <img src={src} width="250px"></img>
} else
cell = "BINARY"
o = "BINARY"
return <div style={{
overflow: 'scroll', minWidth: '200px',
marginLeft: '3px', marginRight: '3px'
}}>{cell}</div>
}}>{o}</div>
}

return <div style={{
overflow: 'scroll', minWidth: '200px',
marginLeft: '3px', marginRight: '3px'
}}>{atob(cell)}</div>
}}>{ b}</div>
},
headerFormatter: (column, colIndex) => {
return <div style={{
Expand All @@ -242,7 +173,7 @@ function Test() {
for (let i = 0; i < columns.length; i++) {

a[columns[i].dataField] = x[i]

console.log(x[i])
let bcell = b64.base64DecToArr(x[i])
let m = IsImage(bcell)
console.log(m)
Expand Down Expand Up @@ -382,7 +313,7 @@ function Test() {
</Row>
</Form>
{data.length > 0 &&
<div id="testtable">
<div id="testtable" className="mb-5">

<BootstrapTable
condensed
Expand Down

0 comments on commit d9f30e1

Please sign in to comment.