aboutsummaryrefslogtreecommitdiff
path: root/Database.go
diff options
context:
space:
mode:
authorFChannel <>2021-05-30 17:41:12 -0700
committerFChannel <>2021-05-30 17:41:12 -0700
commit869b0262ac1c69fe41cc8d6bc59bd47f6e48f685 (patch)
treef52177ef0b042759626c091cf1a3a88a1fff84a7 /Database.go
parentb4e551b3db5a5fc69befeffb7fba17b50dc2e258 (diff)
added publickeypem to actor activity requests
Diffstat (limited to 'Database.go')
-rw-r--r--Database.go34
1 files changed, 29 insertions, 5 deletions
diff --git a/Database.go b/Database.go
index f10ae12..3e890dd 100644
--- a/Database.go
+++ b/Database.go
@@ -12,7 +12,7 @@ import "sort"
func GetActorFromDB(db *sql.DB, id string) Actor {
var nActor Actor
- query :=`select type, id, name, preferedusername, inbox, outbox, following, followers, restricted, summary from actor where id=$1`
+ query :=`select type, id, name, preferedusername, inbox, outbox, following, followers, restricted, summary, publickeypem from actor where id=$1`
rows, err := db.Query(query, id)
@@ -20,19 +20,22 @@ func GetActorFromDB(db *sql.DB, id string) Actor {
return nActor
}
- defer rows.Close()
+ var publicKeyPem string
+ defer rows.Close()
for rows.Next() {
- err = rows.Scan(&nActor.Type, &nActor.Id, &nActor.Name, &nActor.PreferredUsername, &nActor.Inbox, &nActor.Outbox, &nActor.Following, &nActor.Followers, &nActor.Restricted, &nActor.Summary)
+ err = rows.Scan(&nActor.Type, &nActor.Id, &nActor.Name, &nActor.PreferredUsername, &nActor.Inbox, &nActor.Outbox, &nActor.Following, &nActor.Followers, &nActor.Restricted, &nActor.Summary, &publicKeyPem)
CheckError(err, "error with actor from db scan ")
}
+ nActor.PublicKey = GetActorPemFromDB(db, publicKeyPem)
+
return nActor
}
func GetActorByNameFromDB(db *sql.DB, name string) Actor {
var nActor Actor
- query :=`select type, id, name, preferedusername, inbox, outbox, following, followers, restricted, summary from actor where name=$1`
+ query :=`select type, id, name, preferedusername, inbox, outbox, following, followers, restricted, summary, publickeypem from actor where name=$1`
rows, err := db.Query(query, name)
@@ -40,12 +43,15 @@ func GetActorByNameFromDB(db *sql.DB, name string) Actor {
return nActor
}
+ var publicKeyPem string
defer rows.Close()
for rows.Next() {
- err = rows.Scan(&nActor.Type, &nActor.Id, &nActor.Name, &nActor.PreferredUsername, &nActor.Inbox, &nActor.Outbox, &nActor.Following, &nActor.Followers, &nActor.Restricted, &nActor.Summary)
+ err = rows.Scan(&nActor.Type, &nActor.Id, &nActor.Name, &nActor.PreferredUsername, &nActor.Inbox, &nActor.Outbox, &nActor.Following, &nActor.Followers, &nActor.Restricted, &nActor.Summary, &publicKeyPem)
CheckError(err, "error with actor from db scan ")
}
+ nActor.PublicKey = GetActorPemFromDB(db, publicKeyPem)
+
return nActor
}
@@ -1208,3 +1214,21 @@ func GetActorReportedDB(db *sql.DB, id string) []ObjectBase {
return nObj
}
+
+func GetActorPemFromDB(db *sql.DB, pemID string) PublicKeyPem {
+ query := `select id, owner, file from publickeypem where id=$1`
+ rows, err := db.Query(query, pemID)
+
+ CheckError(err, "could not get public key pem from database")
+
+ var pem PublicKeyPem
+
+ defer rows.Close()
+ rows.Next()
+ rows.Scan(&pem.Id, &pem.Owner, &pem.PublicKeyPem)
+ f, _ := os.ReadFile(pem.PublicKeyPem)
+
+ pem.PublicKeyPem = strings.ReplaceAll(string(f), "\r\n", `\n`)
+
+ return pem
+}