diff options
author | FChannel <> | 2022-04-30 22:17:32 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | 503a6637b8294aeb8e5e5546f8acbd2b3d6c4744 (patch) | |
tree | 56614d955df0d3e7284baa997bbf1a8dcc2e78f5 /activitypub | |
parent | 1892327cee2c3fa1d3bea729bd08eb63c2189a96 (diff) |
first steps in posting connected. can make reply with no quote or quote OP
do not recommend working on this branch for the time being since
things are being moved around a lot
Diffstat (limited to 'activitypub')
-rw-r--r-- | activitypub/actor.go | 34 | ||||
-rw-r--r-- | activitypub/object.go | 31 | ||||
-rw-r--r-- | activitypub/pem.go | 11 |
3 files changed, 31 insertions, 45 deletions
diff --git a/activitypub/actor.go b/activitypub/actor.go index d9399ab..70681d1 100644 --- a/activitypub/actor.go +++ b/activitypub/actor.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/FChannel0/FChannel-Server/config" - "github.com/FChannel0/FChannel-Server/post" "github.com/FChannel0/FChannel-Server/util" "github.com/gofiber/fiber/v2" ) @@ -413,19 +412,12 @@ func GetActorFromDB(id string) (Actor, error) { query := `select type, id, name, preferedusername, inbox, outbox, following, followers, restricted, summary, publickeypem from actor where id=$1` - rows, err := config.DB.Query(query, id) + var publicKeyPem string + err := config.DB.QueryRow(query, id).Scan(&nActor.Type, &nActor.Id, &nActor.Name, &nActor.PreferredUsername, &nActor.Inbox, &nActor.Outbox, &nActor.Following, &nActor.Followers, &nActor.Restricted, &nActor.Summary, &publicKeyPem) if err != nil { return nActor, err } - var publicKeyPem string - defer rows.Close() - for rows.Next() { - if err := rows.Scan(&nActor.Type, &nActor.Id, &nActor.Name, &nActor.PreferredUsername, &nActor.Inbox, &nActor.Outbox, &nActor.Following, &nActor.Followers, &nActor.Restricted, &nActor.Summary, &publicKeyPem); err != nil { - return nActor, err - } - } - nActor.PublicKey, err = GetActorPemFromDB(publicKeyPem) if err != nil { return nActor, err @@ -629,6 +621,26 @@ func GetActorsFollowPostFromId(actors []string, id string) (Collection, error) { return collection, nil } +func GetActorPost(ctx *fiber.Ctx, path string) error { + collection, err := GetCollectionFromPath(config.Domain + "" + path) + if err != nil { + return err + } + + if len(collection.OrderedItems) > 0 { + enc, err := json.MarshalIndent(collection, "", "\t") + if err != nil { + return err + } + + ctx.Response().Header.Set("Content-Type", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"") + _, err = ctx.Write(enc) + return err + } + + return nil +} + func GetAllActorArchiveDB(id string, offset int) (Collection, error) { var nColl Collection var result []ObjectBase @@ -814,7 +826,7 @@ func WriteActorObjectReplyToDB(obj ObjectBase) error { } func WriteActorObjectToCache(obj ObjectBase) (ObjectBase, error) { - if res, err := post.IsPostBlacklist(obj.Content); err == nil && res { + if res, err := util.IsPostBlacklist(obj.Content); err == nil && res { fmt.Println("\n\nBlacklist post blocked\n\n") return obj, nil } else if err != nil { diff --git a/activitypub/object.go b/activitypub/object.go index 692fa5b..1256fac 100644 --- a/activitypub/object.go +++ b/activitypub/object.go @@ -14,7 +14,6 @@ import ( "time" "github.com/FChannel0/FChannel-Server/config" - "github.com/FChannel0/FChannel-Server/post" "github.com/FChannel0/FChannel-Server/util" ) @@ -42,7 +41,7 @@ func CheckIfObjectOP(id string) (bool, error) { } func CreateAttachmentObject(file multipart.File, header *multipart.FileHeader) ([]ObjectBase, *os.File, error) { - contentType, err := post.GetFileContentType(file) + contentType, err := util.GetFileContentType(file) if err != nil { return nil, nil, err } @@ -1563,7 +1562,6 @@ func AddFollower(id string, follower string) error { func WriteObjectReplyToDB(obj ObjectBase) error { for i, e := range obj.InReplyTo { - if res, err := CheckIfObjectOP(obj.Id); err == nil && !res && i == 0 { nType, err := GetObjectTypeDB(e.Id) if err != nil { @@ -1581,19 +1579,8 @@ func WriteObjectReplyToDB(obj ObjectBase) error { query := `select id from replies where id=$1 and inreplyto=$2` - rows, err := config.DB.Query(query, obj.Id, e.Id) - if err != nil { - return err - } - defer rows.Close() - var id string - rows.Next() - if err := rows.Scan(&id); err != nil { - return err - } - - if id == "" { + if err := config.DB.QueryRow(query, obj.Id, e.Id).Scan(&id); err != nil { query := `insert into replies (id, inreplyto) values ($1, $2)` _, err := config.DB.Exec(query, obj.Id, e.Id) @@ -1620,17 +1607,8 @@ func WriteObjectReplyToDB(obj ObjectBase) error { if len(obj.InReplyTo) < 1 { query := `select id from replies where id=$1 and inreplyto=$2` - rows, err := config.DB.Query(query, obj.Id, "") - if err != nil { - return err - } - defer rows.Close() - var id string - rows.Next() - rows.Scan(&id) - - if id == "" { + if err := config.DB.QueryRow(query, obj.Id, "").Scan(&id); err != nil { query := `insert into replies (id, inreplyto) values ($1, $2)` if _, err := config.DB.Exec(query, obj.Id, ""); err != nil { @@ -1688,7 +1666,7 @@ func WriteObjectReplyToLocalDB(id string, replyto string) error { } func WriteObjectToCache(obj ObjectBase) (ObjectBase, error) { - if res, err := post.IsPostBlacklist(obj.Content); err == nil && res { + if res, err := util.IsPostBlacklist(obj.Content); err == nil && res { fmt.Println("\n\nBlacklist post blocked\n\n") return obj, nil } else { @@ -1742,7 +1720,6 @@ func WriteObjectToDB(obj ObjectBase) (ObjectBase, error) { return obj, err } } - for i := range obj.Attachment { id, err := util.CreateUniqueID(obj.Actor) if err != nil { diff --git a/activitypub/pem.go b/activitypub/pem.go index ca6c068..ab225a9 100644 --- a/activitypub/pem.go +++ b/activitypub/pem.go @@ -139,16 +139,13 @@ func GetActorPemFromDB(pemID string) (PublicKeyPem, error) { query := `select id, owner, file from publickeypem where id=$1` - rows, err := config.DB.Query(query, pemID) - if err != nil { + if err := config.DB.QueryRow(query, pemID).Scan(&pem.Id, &pem.Owner, &pem.PublicKeyPem); err != nil { return pem, err } - defer rows.Close() - - rows.Next() - rows.Scan(&pem.Id, &pem.Owner, &pem.PublicKeyPem) - f, err := os.ReadFile(pem.PublicKeyPem) + dir, _ := os.Getwd() + dir = dir + "" + strings.Replace(pem.PublicKeyPem, ".", "", 1) + f, err := os.ReadFile(dir) if err != nil { return pem, err } |