From 3db517715bef6a53225c5c3c06e8fc5fd0bf71e3 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sun, 24 Apr 2022 00:46:49 -0700 Subject: basic pass over view posts, post, catalog and manage page connections --- db/actor.go | 16 +++++++++++++++ db/database.go | 7 +++++-- db/redis.go | 64 ++++++++++++++++++++++++++++++++++++++++++---------------- 3 files changed, 68 insertions(+), 19 deletions(-) (limited to 'db') diff --git a/db/actor.go b/db/actor.go index 51c8f41..7e36090 100644 --- a/db/actor.go +++ b/db/actor.go @@ -1,11 +1,13 @@ package db import ( + "encoding/json" "fmt" "regexp" "strings" "github.com/FChannel0/FChannel-Server/activitypub" + "github.com/gofiber/fiber/v2" ) func GetActorFromPath(location string, prefix string) (activitypub.Actor, error) { @@ -49,3 +51,17 @@ func GetActorByName(name string) activitypub.Actor { return actor } + +func GetActorInfo(ctx *fiber.Ctx, id string) error { + actor, err := GetActorFromDB(id) + if err != nil { + return err + } + + enc, _ := json.MarshalIndent(actor, "", "\t") + ctx.Response().Header.Set("Content-Type", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"") + + _, err = ctx.Write(enc) + + return err +} diff --git a/db/database.go b/db/database.go index 0b44404..db7e715 100644 --- a/db/database.go +++ b/db/database.go @@ -858,6 +858,7 @@ func GetObjectFromDBCatalog(id string) (activitypub.Collection, error) { query := `select x.id, x.name, x.content, x.type, x.published, x.updated, x.attributedto, x.attachment, x.preview, x.actor, x.tripcode, x.sensitive from (select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode, sensitive from activitystream where actor=$1 and id in (select id from replies where inreplyto='') and type='Note' union select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode, sensitive from activitystream where actor in (select following from following where id=$1) and id in (select id from replies where inreplyto='') and type='Note' union select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode, sensitive from cacheactivitystream where actor in (select following from following where id=$1) and id in (select id from replies where inreplyto='') and type='Note') as x order by x.updated desc limit 165` rows, err := db.Query(query, id) + if err != nil { return nColl, err } @@ -880,6 +881,7 @@ func GetObjectFromDBCatalog(id string) (activitypub.Collection, error) { post.Replies = &replies post.Replies.TotalItems, post.Replies.TotalImgs, err = GetObjectRepliesCount(post) + if err != nil { return nColl, err } @@ -1229,8 +1231,9 @@ func GetObjectRepliesCount(parent activitypub.ObjectBase) (int, int, error) { defer rows.Close() - rows.Next() - err = rows.Scan(&countId, &countImg) + for rows.Next() { + err = rows.Scan(&countId, &countImg) + } return countId, countImg, err } diff --git a/db/redis.go b/db/redis.go index 873ca27..1650b4f 100644 --- a/db/redis.go +++ b/db/redis.go @@ -3,10 +3,11 @@ package db import ( "bufio" "fmt" - "net/http" "os" + "strings" "github.com/FChannel0/FChannel-Server/config" + "github.com/gofiber/fiber/v2" "github.com/gomodule/redigo/redis" ) @@ -22,6 +23,50 @@ func CloseCache() error { return Cache.Close() } +func GetClientKey() (string, error) { + file, err := os.Open("clientkey") + if err != nil { + return "", err + } + defer file.Close() + + scanner := bufio.NewScanner(file) + var line string + for scanner.Scan() { + line = fmt.Sprintf("%s", scanner.Text()) + } + + return line, nil +} + +func GetPasswordFromSession(c *fiber.Ctx) (string, string) { + + cookie := c.Cookies("session_token") + + if cookie == "" { + return "", "" + } + + sessionToken := cookie + + response, err := Cache.Do("GET", sessionToken) + + if err != nil { + return "", "" + } + + token := fmt.Sprintf("%s", response) + + parts := strings.Split(token, "|") + + if len(parts) > 1 { + return parts[0], parts[1] + } + + return "", "" +} + +/* TODO: Convert to fiber ctx func CheckSession(w http.ResponseWriter, r *http.Request) (interface{}, error) { c, err := r.Cookie("session_token") @@ -49,20 +94,5 @@ func CheckSession(w http.ResponseWriter, r *http.Request) (interface{}, error) { } return response, nil -} - -func GetClientKey() (string, error) { - file, err := os.Open("clientkey") - if err != nil { - return "", err - } - defer file.Close() - - scanner := bufio.NewScanner(file) - var line string - for scanner.Scan() { - line = fmt.Sprintf("%s", scanner.Text()) } - - return line, nil -} +*/ -- cgit v1.2.3