From 9d937e6f895ca7213ae759efca9b292a1d014ab3 Mon Sep 17 00:00:00 2001
From: FChannel <>
Date: Thu, 3 Jun 2021 01:19:37 -0700
Subject: cleaning up removing posts
---
Database.go | 112 +++++++++++++++++++++++++++++++++++++++++++++++++--
main.go | 77 ++++++++++++++---------------------
static/js/posts.js | 15 ++++---
static/ncatalog.html | 11 +++--
static/posts.html | 2 +-
5 files changed, 155 insertions(+), 62 deletions(-)
diff --git a/Database.go b/Database.go
index 3e890dd..9f8516d 100644
--- a/Database.go
+++ b/Database.go
@@ -818,7 +818,7 @@ func GetObjectAttachment(db *sql.DB, id string) []ObjectBase {
var attachments []ObjectBase
- query := `select x.id, x.type, x.name, x.href, x.mediatype, x.size, x.published from (select id, type, name, href, mediatype, size, published from activitystream where id=$1 union select id, type, name, href, mediatype, size, published from cacheactivitystream where id=$1) as x`
+ query := `select x.id, x.type, x.name, x.href, x.mediatype, x.size, x.published from (select id, type, name, href, mediatype, size, published from activitystream where id=$1 union select id, type, name, href, mediatype, size, published from cacheactivitystream where id=$1) as x where type='Attachment'`
rows, err := db.Query(query, id)
@@ -844,7 +844,7 @@ func GetObjectPreview(db *sql.DB, id string) *NestedObjectBase {
var preview NestedObjectBase
- query := `select x.id, x.type, x.name, x.href, x.mediatype, x.size, x.published from (select id, type, name, href, mediatype, size, published from activitystream where id=$1 union select id, type, name, href, mediatype, size, published from cacheactivitystream where id=$1) as x`
+ query := `select x.id, x.type, x.name, x.href, x.mediatype, x.size, x.published from (select id, type, name, href, mediatype, size, published from activitystream where id=$1 union select id, type, name, href, mediatype, size, published from cacheactivitystream where id=$1) as x where type='Preview'`
rows, err := db.Query(query, id)
@@ -1044,8 +1044,114 @@ func DeleteObjectRepliesFromDB(db *sql.DB, id string) {
}
-func DeleteObject(db *sql.DB, id string) {
+func SetAttachmentFromDB(db *sql.DB, id string, _type string) {
+ datetime := time.Now().Format(time.RFC3339)
+
+ var query = `update activitystream set type=$1, deleted=$2 where id in (select attachment from activitystream where id=$3)`
+
+ _, err := db.Exec(query, _type, datetime, id)
+
+ CheckError(err, "error with set attachment")
+
+ query = `update cacheactivitystream set type=$1, deleted=$2 where id in (select attachment from cacheactivitystream where id=$3)`
+
+ _, err = db.Exec(query, _type, datetime, id)
+
+ CheckError(err, "error with set cache attachment")
+}
+
+func SetAttachmentRepliesFromDB(db *sql.DB, id string, _type string) {
+ datetime := time.Now().Format(time.RFC3339)
+
+ var query = `update activitystream set type=$1, deleted=$2 where id in (select attachment from activitystream where id in (select id from replies where inreplyto=$3))`
+
+ _, err := db.Exec(query, _type, datetime, id)
+
+ CheckError(err, "error with set attachment")
+
+ query = `update cacheactivitystream set type=$1, deleted=$2 where id in (select attachment from cacheactivitystream where id in (select id from replies where inreplyto=$3))`
+
+ _, err = db.Exec(query, _type, datetime, id)
+
+ CheckError(err, "error with set cache attachment")
+}
+
+func SetPreviewFromDB(db *sql.DB, id string, _type string) {
+ datetime := time.Now().Format(time.RFC3339)
+
+ var query = `update activitystream set type=$1, deleted=$2 where id in (select preview from activitystream where id=$3)`
+
+ _, err := db.Exec(query, _type, datetime, id)
+
+ CheckError(err, "error with set preview")
+
+ query = `update cacheactivitystream set type=$1, deleted=$2 where id in (select preview from cacheactivitystream where id=$3)`
+
+ _, err = db.Exec(query, _type, datetime, id)
+
+ CheckError(err, "error with set cache preview")
+}
+
+func SetPreviewRepliesFromDB(db *sql.DB, id string, _type string) {
+ datetime := time.Now().Format(time.RFC3339)
+
+ var query = `update activitystream set type=$1, deleted=$2 where id in (select preview from activitystream where id in (select id from replies where inreplyto=$3))`
+
+ _, err := db.Exec(query, _type, datetime, id)
+
+ CheckError(err, "error with set preview")
+
+ query = `update cacheactivitystream set type=$1, deleted=$2 where id in (select preview from cacheactivitystream where id in (select id from replies where inreplyto=$3))`
+
+ _, err = db.Exec(query, _type, datetime, id)
+
+ CheckError(err, "error with set cache preview")
+}
+
+func SetObjectFromDB(db *sql.DB, id string, _type string) {
+ datetime := time.Now().Format(time.RFC3339)
+ var query = `update activitystream set type=$1, deleted=$2 where id=$3`
+
+ _, err := db.Exec(query, _type, datetime, id)
+
+ CheckError(err, "error with set object")
+
+ query = `update cacheactivitystream set type=$1, deleted=$2 where id=$3`
+
+ _, err = db.Exec(query, _type, datetime, id)
+
+ CheckError(err, "error with set cache object")
+}
+
+func SetObjectRepliesFromDB(db *sql.DB, id string, _type string) {
+ datetime := time.Now().Format(time.RFC3339)
+
+ var query = `update activitystream set type=$1, deleted=$2 where id in (select id from replies where inreplyto=$3)`
+ _, err := db.Exec(query, _type, datetime, id)
+ CheckError(err, "error with set object replies")
+
+ query = `update cacheactivitystream set type=$1, deleted=$2 where id in (select id from replies where inreplyto=$3)`
+ _, err = db.Exec(query, _type, datetime, id)
+ CheckError(err, "error with set cache object replies")
+}
+
+func SetObject(db *sql.DB, id string, _type string) {
+ SetAttachmentFromDB(db, id, _type);
+ SetPreviewFromDB(db, id, _type);
+ SetObjectFromDB(db, id, _type);
+}
+
+func SetObjectAndReplies(db *sql.DB, id string, _type string) {
+ SetAttachmentFromDB(db, id, _type);
+ SetPreviewFromDB(db, id, _type);
+ SetObjectRepliesFromDB(db, id, _type);
+ SetAttachmentRepliesFromDB(db, id, _type);
+ SetPreviewRepliesFromDB(db, id, _type);
+ SetObjectFromDB(db, id, _type);
+}
+
+func DeleteObject(db *sql.DB, id string) {
if(!IsIDLocal(db, id)) {
return
}
diff --git a/main.go b/main.go
index 1be79e1..5e4c69e 100644
--- a/main.go
+++ b/main.go
@@ -739,40 +739,29 @@ func main() {
OP = col.OrderedItems[0].InReplyTo[0].Id
}
- if !IsIDLocal(db, id) {
- CloseLocalReportDB(db, id, board)
- CreateLocalDeleteDB(db, id, "post")
- if(manage == "t") {
- http.Redirect(w, r, "/" + *Key + "/" + board, http.StatusSeeOther)
- } else if(OP != ""){
- http.Redirect(w, r, "/" + board + "/" + remoteShort(OP), http.StatusSeeOther)
- } else {
- http.Redirect(w, r, "/" + board, http.StatusSeeOther)
- }
-
- return
+ if !isOP {
+ SetObject(db, id, "Removed")
+ } else {
+ SetObjectAndReplies(db, id, "Removed")
}
- if !isOP {
- DeleteReportActivity(db, id)
- DeleteObjectRequest(db, id)
- DeleteObject(db, obj.Id)
- if(manage == "t"){
- http.Redirect(w, r, "/" + *Key + "/" + board , http.StatusSeeOther)
- }else{
+ if IsIDLocal(db, id){
+ DeleteObjectRequest(db, id)
+ }
+
+ if(manage == "t"){
+ http.Redirect(w, r, "/" + *Key + "/" + board , http.StatusSeeOther)
+ return
+ } else if !isOP {
+ if (!IsIDLocal(db, id)){
+ http.Redirect(w, r, "/" + board + "/" + remoteShort(OP), http.StatusSeeOther)
+ return
+ } else {
http.Redirect(w, r, OP, http.StatusSeeOther)
+ return
}
- return
-
} else {
- DeleteReportActivity(db, id)
- DeleteObjectAndRepliesRequest(db, id)
- DeleteObjectAndReplies(db, obj.Id)
- if(manage == "t"){
- http.Redirect(w, r, "/" + *Key + "/" + board , http.StatusSeeOther)
- }else{
- http.Redirect(w, r, "/" + board, http.StatusSeeOther)
- }
+ http.Redirect(w, r, "/" + board, http.StatusSeeOther)
return
}
@@ -809,26 +798,22 @@ func main() {
return
}
-
-
- if !IsIDLocal(db, id) {
- CreateLocalDeleteDB(db, id, "attachment")
- if(manage == "t") {
- http.Redirect(w, r, "/" + *Key + "/" + board, http.StatusSeeOther)
- } else {
- http.Redirect(w, r, "/" + board + "/" + remoteShort(OP), http.StatusSeeOther)
- }
- return
- }
-
- DeleteAttachmentFromFile(db, id)
- DeletePreviewFromFile(db, id)
-
- if(manage == "t") {
+ SetAttachmentFromDB(db, id, "Removed")
+ SetPreviewFromDB(db, id, "Removed")
+
+ if (manage == "t") {
http.Redirect(w, r, "/" + *Key + "/" + board, http.StatusSeeOther)
- } else {
+ return
+ } else if !IsIDLocal(db, OP) {
+ http.Redirect(w, r, "/" + board + "/" + remoteShort(OP), http.StatusSeeOther)
+ return
+ } else {
http.Redirect(w, r, OP, http.StatusSeeOther)
+ return
}
+
+ w.WriteHeader(http.StatusBadRequest)
+ w.Write([]byte(""))
})
http.HandleFunc("/report", func(w http.ResponseWriter, r *http.Request){
diff --git a/static/js/posts.js b/static/js/posts.js
index b2bfd7a..077b654 100644
--- a/static/js/posts.js
+++ b/static/js/posts.js
@@ -26,6 +26,8 @@ function shortURL(actorName, url)
{
re = /.+\//g;
temp = re.exec(url)
+
+ var output
if(stripTransferProtocol(temp[0]) == stripTransferProtocol(actorName) + "/")
{
@@ -39,11 +41,8 @@ function shortURL(actorName, url)
re = /\w+$/g;
- u = re.exec(short);
-
- return u;
+ output = re.exec(short);
}else{
-
var short = url.replace("https://", "");
short = short.replace("http://", "");
short = short.replace("www.", "");
@@ -64,10 +63,10 @@ function shortURL(actorName, url)
v = re.exec(str)
- v = "f" + v[0] + "-" + u
-
- return v;
+ output = "f" + v[0] + "-" + u
}
+
+ return output
}
function shortImg(url)
@@ -113,7 +112,7 @@ function getBoardId(url)
function convertContent(actorName, content, opid)
{
- var re = /(>>)(https:\/\/|http:\/\/)?(www\.)?.+\/\w+/gm;
+ var re = /(>>)(https?:\/\/)?(www\.)?.+\/\w+/gm;
var match = content.match(re);
var newContent = content;
if(match)
diff --git a/static/ncatalog.html b/static/ncatalog.html
index 81d31f3..a399d13 100644
--- a/static/ncatalog.html
+++ b/static/ncatalog.html
@@ -24,6 +24,7 @@
{{ end }}
+
{{ end }}
+