mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-19 11:36:47 +02:00
building, before doing the refactor to make device ID just another random ID
This commit is contained in:
parent
2a3887b9ed
commit
32e74eb3a1
@ -1,12 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/ddworken/hishtory/shared"
|
"github.com/ddworken/hishtory/shared"
|
||||||
)
|
)
|
||||||
@ -75,12 +75,11 @@ func saveHistoryEntry() {
|
|||||||
// Persist it locally
|
// Persist it locally
|
||||||
db, err := shared.OpenLocalSqliteDb()
|
db, err := shared.OpenLocalSqliteDb()
|
||||||
shared.CheckFatalError(err)
|
shared.CheckFatalError(err)
|
||||||
err = db.Create(entry)
|
result := db.Create(entry)
|
||||||
shared.CheckFatalError(err)
|
shared.CheckFatalError(result.Error)
|
||||||
|
|
||||||
// Persist it remotely
|
// Persist it remotely
|
||||||
// TODO: This is encrypting one to this device, this is wrong. We want to encrypt it to every device except this one.
|
encEntry, err := shared.EncryptHistoryEntry(config.UserSecret, *entry)
|
||||||
encEntry, err := shared.EncryptHistoryEntry(config.UserSecret ,config.DeviceId, *entry)
|
|
||||||
shared.CheckFatalError(err)
|
shared.CheckFatalError(err)
|
||||||
jsonValue, err := json.Marshal(encEntry)
|
jsonValue, err := json.Marshal(encEntry)
|
||||||
shared.CheckFatalError(err)
|
shared.CheckFatalError(err)
|
||||||
|
@ -36,10 +36,10 @@ func apiESubmitHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
GLOBAL_DB.Where("user_id = ?", )
|
GLOBAL_DB.Where("user_id = ?")
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
tx := GLOBAL_DB.Where("user_id = ?", entry.UserId)
|
tx := GLOBAL_DB.Where("user_id = ?", entry.UserId)
|
||||||
var devices []*shared.Device;
|
var devices []*shared.Device
|
||||||
result := tx.Find(&devices)
|
result := tx.Find(&devices)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
panic(fmt.Errorf("DB query error: %v", result.Error))
|
panic(fmt.Errorf("DB query error: %v", result.Error))
|
||||||
@ -48,7 +48,7 @@ func apiESubmitHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
panic(fmt.Errorf("Found no devices associated with user_id=%s, can't save history entry!", entry.UserId))
|
panic(fmt.Errorf("Found no devices associated with user_id=%s, can't save history entry!", entry.UserId))
|
||||||
}
|
}
|
||||||
for _, device := range devices {
|
for _, device := range devices {
|
||||||
entry.DeviceId = device.DeviceId;
|
entry.DeviceId = device.DeviceId
|
||||||
GLOBAL_DB.Create(&entry)
|
GLOBAL_DB.Create(&entry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ func OpenLocalSqliteDb() (*gorm.DB, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create ~/.hishtory dir: %v", err)
|
return nil, fmt.Errorf("failed to create ~/.hishtory dir: %v", err)
|
||||||
}
|
}
|
||||||
db, err := gorm.Open(sqlite.Open(path.Join(homedir, HISHTORY_PATH, DB_PATH)), &gorm.Config{SkipDefaultTransaction: true,})
|
db, err := gorm.Open(sqlite.Open(path.Join(homedir, HISHTORY_PATH, DB_PATH)), &gorm.Config{SkipDefaultTransaction: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to connect to the DB: %v", err)
|
return nil, fmt.Errorf("failed to connect to the DB: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user