Compare commits
No commits in common. "b4e554866ee22e025933c6cdae3cad46ebce25be" and "072e87c05fa99235d6df104d378bd9dbd1054646" have entirely different histories.
b4e554866e
...
072e87c05f
|
@ -59,7 +59,7 @@
|
||||||
Value: Array.isArray(change[3]) ? btoa(String.fromCharCode.apply(null, change[3])) : btoa(change[3]),
|
Value: Array.isArray(change[3]) ? btoa(String.fromCharCode.apply(null, change[3])) : btoa(change[3]),
|
||||||
ColVersion: Number(change[4]),
|
ColVersion: Number(change[4]),
|
||||||
DBVersion: Number(change[5]),
|
DBVersion: Number(change[5]),
|
||||||
SiteID: Array.isArray(change[6]) ? btoa(new TextDecoder('utf8').decode(change[6])) : btoa(change[6]),
|
SiteID: Array.isArray(change[6]) ? arrayBufferToBase64(Uint8Array.from(change[6]).buffer) : btoa(change[6]),
|
||||||
CL: Number(change[7]),
|
CL: Number(change[7]),
|
||||||
Seq: Number(change[8])
|
Seq: Number(change[8])
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -2,16 +2,15 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/base64"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"encoding/base64"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"mast/db"
|
"mast/db"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
sqlite3 "github.com/mattn/go-sqlite3"
|
sqlite3 "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
@ -98,19 +97,19 @@ func mapToCRSQLChange(m map[string]interface{}) (CRSQLChange, error) {
|
||||||
change.Seq = int64(m["Seq"].(float64))
|
change.Seq = int64(m["Seq"].(float64))
|
||||||
|
|
||||||
// Handle []byte fields
|
// Handle []byte fields
|
||||||
change.PK, err = decodeBase64ToByteArray(m["PK"].(string))
|
change.PK, err = base64.URLEncoding.DecodeString(m["PK"].(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return change, err
|
return change, err
|
||||||
}
|
}
|
||||||
//fmt.Println(m["PK"])
|
//fmt.Println(m["PK"])
|
||||||
//fmt.Println(m["PK"].(string))
|
//fmt.Println(m["PK"].(string))
|
||||||
//fmt.Println(base64.URLEncoding.DecodeString(m["PK"].(string)))
|
//fmt.Println(base64.URLEncoding.DecodeString(m["PK"].(string)))
|
||||||
change.Value, err = decodeBase64ToByteArray(m["Value"].(string))
|
change.Value, err = base64.URLEncoding.DecodeString(m["Value"].(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return change, err
|
return change, err
|
||||||
}
|
}
|
||||||
change.SiteID, err = decodeBase64ToByteArray(m["SiteID"].(string))
|
//change.SiteID, err = decodeBase64ToIntArray(m["SiteID"].(string))
|
||||||
fmt.Println(change.SiteID)
|
change.SiteID, err = base64.URLEncoding.DecodeString(m["SiteID"].(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return change, err
|
return change, err
|
||||||
}
|
}
|
||||||
|
@ -119,7 +118,7 @@ func mapToCRSQLChange(m map[string]interface{}) (CRSQLChange, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func decodeBase64ToByteArray(encodedString string) ([]uint8, error) {
|
func decodeBase64ToIntArray(encodedString string) ([]int, error) {
|
||||||
// Decode the base64 string
|
// Decode the base64 string
|
||||||
decodedBytes, err := base64.StdEncoding.DecodeString(encodedString)
|
decodedBytes, err := base64.StdEncoding.DecodeString(encodedString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -133,13 +132,13 @@ func decodeBase64ToByteArray(encodedString string) ([]uint8, error) {
|
||||||
stringSlice := strings.Split(decodedString, ",")
|
stringSlice := strings.Split(decodedString, ",")
|
||||||
|
|
||||||
// Convert each string to an integer
|
// Convert each string to an integer
|
||||||
intSlice := make([]uint8, len(stringSlice))
|
intSlice := make([]int, len(stringSlice))
|
||||||
for i, s := range stringSlice {
|
for i, s := range stringSlice {
|
||||||
num, err := strconv.Atoi(s)
|
num, err := strconv.Atoi(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error converting string to int: %w", err)
|
return nil, fmt.Errorf("error converting string to int: %w", err)
|
||||||
}
|
}
|
||||||
intSlice[i] = byte(num)
|
intSlice[i] = num
|
||||||
}
|
}
|
||||||
|
|
||||||
return intSlice, nil
|
return intSlice, nil
|
||||||
|
@ -163,7 +162,7 @@ func applyChanges(changes []interface{}) {
|
||||||
log.Println("Error inserting change:", err)
|
log.Println("Error inserting change:", err)
|
||||||
}
|
}
|
||||||
log.Println("We inserted data successfully??")
|
log.Println("We inserted data successfully??")
|
||||||
fmt.Println(c)
|
printChange(change)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Not OK to convert change")
|
fmt.Println("Not OK to convert change")
|
||||||
fmt.Println("Change look like:")
|
fmt.Println("Change look like:")
|
||||||
|
|
Loading…
Reference in a new issue