diff options
Diffstat (limited to 'db')
-rw-r--r-- | db/actor.go | 16 | ||||
-rw-r--r-- | db/database.go | 7 | ||||
-rw-r--r-- | db/redis.go | 64 |
3 files changed, 68 insertions, 19 deletions
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 -} +*/ |