From 895d90f8dd038540e65cf291f003195a0f6bd024 Mon Sep 17 00:00:00 2001 From: FChannel <=> Date: Sun, 24 Jan 2021 10:59:49 -0800 Subject: domain routing bug --- Database.go | 22 ++++++++++++++++++++++ Follow.go | 1 - OutboxPost.go | 1 + client.go | 7 +++++++ clientkey | 2 +- main.go | 15 +++++++++++---- session.go | 6 +++++- 7 files changed, 47 insertions(+), 7 deletions(-) diff --git a/Database.go b/Database.go index 275bfcd..ea1b031 100644 --- a/Database.go +++ b/Database.go @@ -30,6 +30,28 @@ func GetActorFromDB(db *sql.DB, id string) Actor { 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` + + rows, err := db.Query(query, name) + + if CheckError(err, "could not get actor from db query") != nil { + return nActor + } + + 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) + CheckError(err, "error with actor from db scan ") + } + + nActor.AtContext.Context = "https://www.w3.org/ns/activitystreams" + + return nActor +} + func CreateNewBoardDB(db *sql.DB, actor Actor) Actor{ query := `insert into actor (type, id, name, preferedusername, inbox, outbox, following, followers, summary) values ($1, $2, $3, $4, $5, $6, $7, $8, $9)` diff --git a/Follow.go b/Follow.go index 94469c2..8659604 100644 --- a/Follow.go +++ b/Follow.go @@ -190,7 +190,6 @@ func SetActorFollowingDB(db *sql.DB, activity Activity) Activity { alreadyFollow := false following := GetActorFollowingDB(db, activity.Object.Actor.Id) - for _, e := range following { if e.Id == activity.Actor.Id { alreadyFollow = true diff --git a/OutboxPost.go b/OutboxPost.go index f66c234..dbb49d2 100644 --- a/OutboxPost.go +++ b/OutboxPost.go @@ -110,6 +110,7 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { SetActorFollowingDB(db, rActivity) MakeActivityRequest(activity) } + w.Write([]byte("")) case "Delete": fmt.Println("This is a delete") diff --git a/client.go b/client.go index e0c5975..b197168 100644 --- a/client.go +++ b/client.go @@ -389,6 +389,13 @@ func WantToServe(db *sql.DB, actorName string) (Collection, bool) { var collection Collection serve := false + + boardActor := GetActorByNameFromDB(db, actorName) + + if boardActor.Id != "" { + collection = GetActorCollectionDB(db, boardActor) + return collection, true + } for _, e := range *Boards { boardActor := GetActorFromDB(db, e.Id) diff --git a/clientkey b/clientkey index 98282ee..37b5687 100644 --- a/clientkey +++ b/clientkey @@ -1 +1 @@ -fcc28cdb95d2983a10efdc8f3b8a9503 \ No newline at end of file +515ff978b24a657d3d1076da3cfe5102 \ No newline at end of file diff --git a/main.go b/main.go index e4d1190..e9cdb2f 100644 --- a/main.go +++ b/main.go @@ -100,9 +100,9 @@ func main() { var method = r.Method - var actor = GetActorFromPath(db, path, "/") + var actor = GetActorFromPath(db, path, "/") - if actor.Name == "" { + if actor.Name == "main" { mainActor = (path == "/") mainInbox = (path == "/inbox") mainOutbox = (path == "/outbox") @@ -429,7 +429,10 @@ func main() { CheckError(err, "error with add board follow resp") + + following := GetActorFollowingDB(db, Domain) + Boards = &following http.Redirect(w, r, r.Header.Get("Referer"), http.StatusSeeOther) @@ -916,8 +919,12 @@ func GetActorFromPath(db *sql.DB, location string, prefix string) Actor { } var nActor Actor - - nActor = GetActorByName(db, actor) + + nActor = GetActorByNameFromDB(db, actor) + + if nActor.Id == "" { + nActor = GetActorByName(db, actor) + } return nActor } diff --git a/session.go b/session.go index 3478802..0867b16 100644 --- a/session.go +++ b/session.go @@ -86,5 +86,9 @@ func GetPasswordFromSession(r *http.Request) (string, string) { parts := strings.Split(token, "|") - return parts[0], parts[1] + if len(parts) > 1 { + return parts[0], parts[1] + } + + return "", "" } -- cgit v1.2.3