aboutsummaryrefslogtreecommitdiff
path: root/outboxPost.go
diff options
context:
space:
mode:
authorFChannel <>2021-07-28 15:31:37 -0700
committerFChannel <>2021-07-28 15:31:37 -0700
commit98d72c9b94b5dda9a987dfe41552f00512d43574 (patch)
treeef75468766c6c5e2d4392cfc567eb29cb90d0c9d /outboxPost.go
parentea12d0f741455c542accf24a003a62ab85bfbfa3 (diff)
parent87fc54c9d41bdbe7eaa8769386776a3723580b34 (diff)
v0.0.13-release
Diffstat (limited to 'outboxPost.go')
-rw-r--r--outboxPost.go65
1 files changed, 58 insertions, 7 deletions
diff --git a/outboxPost.go b/outboxPost.go
index 356647e..6d23e23 100644
--- a/outboxPost.go
+++ b/outboxPost.go
@@ -7,6 +7,7 @@ import _ "github.com/lib/pq"
import "encoding/json"
import "reflect"
import "io/ioutil"
+import "mime/multipart"
import "os"
import "regexp"
import "strings"
@@ -24,13 +25,21 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) {
r.ParseMultipartForm(5 << 20)
if(BoardHasAuthType(db, actor.Name, "captcha") && CheckCaptcha(db, r.FormValue("captcha"))) {
f, header, _ := r.FormFile("file")
+
if(header != nil) {
+ defer f.Close()
if(header.Size > (7 << 20)){
w.WriteHeader(http.StatusRequestEntityTooLarge)
w.Write([]byte("7MB max file size"))
return
}
+ if(IsMediaBanned(db, f)) {
+ fmt.Println("media banned")
+ http.Redirect(w, r, Domain, http.StatusSeeOther)
+ return
+ }
+
contentType, _ := GetFileContentType(f)
if(!SupportedMIMEType(contentType)) {
@@ -39,7 +48,7 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) {
return
}
}
-
+
var nObj = CreateObject("Note")
nObj = ObjectFromForm(r, db, nObj)
@@ -92,7 +101,7 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) {
var rActivity Activity
if validActor && validLocalActor {
rActivity = AcceptFollow(activity)
- SetActorFollowingDB(db, rActivity)
+ rActivity = SetActorFollowingDB(db, rActivity)
MakeActivityRequest(db, activity)
}
@@ -339,7 +348,6 @@ func ObjectFromForm(r *http.Request, db *sql.DB, obj ObjectBase) ObjectBase {
err := cmd.Run()
CheckError(err, "error with removing exif data from image")
-
}
obj.Preview = CreatePreviewObject(obj.Attachment[0])
@@ -373,7 +381,7 @@ func ObjectFromForm(r *http.Request, db *sql.DB, obj ObjectBase) ObjectBase {
}
}
- replyingTo := ParseCommentForReplies(r.FormValue("comment"))
+ replyingTo := ParseCommentForReplies(db, r.FormValue("comment"), originalPost.Id)
for _, e := range replyingTo {
@@ -557,16 +565,26 @@ func ParseInboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) {
MakeActivityRequest(db, response)
alreadyFollow := false
+ alreadyFollowing := false
autoSub := GetActorAutoSubscribeDB(db, response.Actor.Id)
following := GetActorFollowingDB(db, response.Actor.Id)
for _, e := range following {
- if e.Id == activity.Actor.Id {
+ if e.Id == response.Object.Id {
alreadyFollow = true
}
}
- if autoSub && !alreadyFollow {
+ actor := FingerActor(response.Object.Actor)
+ remoteActorFollowingCol := GetCollectionFromReq(actor.Following)
+
+ for _, e := range remoteActorFollowingCol.Items {
+ if e.Id == response.Actor.Id {
+ alreadyFollowing = true
+ }
+ }
+
+ if autoSub && !alreadyFollow && alreadyFollowing {
followActivity := MakeFollowActivity(db, response.Actor.Id, response.Object.Actor)
if FingerActor(response.Object.Actor).Id != "" {
@@ -589,7 +607,6 @@ func ParseInboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) {
}
break
}
-
}
func MakeActivityFollowingReq(w http.ResponseWriter, r *http.Request, activity Activity) bool {
@@ -617,3 +634,37 @@ func MakeActivityFollowingReq(w http.ResponseWriter, r *http.Request, activity A
return false
}
+
+func IsMediaBanned(db *sql.DB, f multipart.File) bool {
+ f.Seek(0, 0)
+
+ fileBytes := make([]byte, 2048)
+
+ _, err := f.Read(fileBytes)
+ if err != nil {
+ fmt.Println("error readin bytes for media ban")
+ }
+
+ hash := HashBytes(fileBytes)
+
+ f.Seek(0, 0)
+
+ query := `select hash from bannedmedia where hash=$1`
+
+ rows, err := db.Query(query, hash)
+
+ CheckError(err, "could not get hash from banned media in db")
+
+ var h string
+
+ defer rows.Close()
+
+ rows.Next()
+ rows.Scan(&h)
+
+ if h == hash {
+ return true
+ }
+
+ return false
+}