aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFChannel <>2021-06-03 01:19:37 -0700
committerFChannel <>2021-06-03 01:19:37 -0700
commit9d937e6f895ca7213ae759efca9b292a1d014ab3 (patch)
treeeecfbe1c593afc5c1c2e4017a109cfb94a51a014
parent60b6bdf1c021fcffff397c7b1439a1407ed90f0a (diff)
cleaning up removing posts
-rw-r--r--Database.go112
-rw-r--r--main.go77
-rw-r--r--static/js/posts.js15
-rw-r--r--static/ncatalog.html11
-rw-r--r--static/posts.html2
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 }}
<a id="{{ .Id }}-anchor" href="/{{ $board.Name }}/">
<div id="media-{{ .Id }}" style="width:180px;"></div>
+ </a>
<script>
media = document.getElementById("media-{{ .Id }}")
if(getMIMEType({{ (index .Attachment 0).MediaType }}) == "image"){
@@ -56,9 +57,12 @@
video.style = "margin-right: 10px; margin-bottom: 10px; max-width: 180px; max-height: 180px;"
video.innerText = 'Video is not supported.'
media.appendChild(video)
- }
+ }
+
+ document.getElementById("{{ .Id }}-anchor").href = "/{{ $board.Name }}/" + shortURL("{{$board.Actor.Id}}", "{{ .Id }}")
</script>
{{ end }}
+ <a id="{{ .Id }}-link" href="/{{ $board.Name }}/">
<div>
{{ $replies := .Replies }}
{{ if $replies }}
@@ -71,12 +75,11 @@
{{ if .Content }}
<span style="display: block">{{.Content}}</span>
{{ end }}
-
</div>
- </a>
+ </a>
</div>
<script>
- document.getElementById("{{ .Id }}-anchor").href = "/{{ $board.Name }}/" + shortURL("{{$board.Actor.Id}}", "{{ .Id }}")
+ document.getElementById("{{ .Id }}-link").href = "/{{ $board.Name }}/" + shortURL("{{$board.Actor.Id}}", "{{ .Id }}")
</script>
{{ end }}
</div>
diff --git a/static/posts.html b/static/posts.html
index aaf10c9..ee71faf 100644
--- a/static/posts.html
+++ b/static/posts.html
@@ -79,7 +79,7 @@
{{ end }}
{{ if .Attachment }}
{{ if eq $board.ModCred $board.Domain $board.Actor.Id }}
- <a href="/deleteattach?id={{ .Id }}&board={{ $board.Actor.Id }}">[Delete Attachment]</a>
+ <a href="/deleteattach?id={{ .Id }}&board={{ $board.Actor.Name }}">[Delete Attachment]</a>
{{ end }}
<span style="display: block;">File <a id="{{ .Id }}-img" href="{{ (index .Attachment 0).Href}}">{{ (index .Attachment 0).Name }}</a> <span id="{{ .Id }}-size">({{ (index .Attachment 0).Size }})</span></span>
<div id="media-{{ .Id }}"></div>