diff options
author | FChannel <> | 2021-06-03 02:00:15 -0700 |
---|---|---|
committer | FChannel <> | 2021-06-03 02:00:15 -0700 |
commit | ca748944398e0ebbc0f27446d5e41bd5e4aa3852 (patch) | |
tree | e590ab2f9c53846f1aa02638c4da6ed9b0cd28f2 | |
parent | 9d937e6f895ca7213ae759efca9b292a1d014ab3 (diff) |
deleteing objects and cache objects put into single db commands
-rw-r--r-- | Database.go | 78 | ||||
-rw-r--r-- | main.go | 112 | ||||
l--------- | static/.#ncatalog.html | 1 | ||||
-rw-r--r-- | static/ncatalog.html | 4 |
4 files changed, 158 insertions, 37 deletions
diff --git a/Database.go b/Database.go index 9f8516d..fb12597 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 where type='Attachment'` + 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` 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 where type='Preview'` + 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` rows, err := db.Query(query, id) @@ -897,7 +897,7 @@ func GetObjectImgsTotalDB(db *sql.DB, actor Actor) int{ func DeletePreviewFromFile(db *sql.DB, id string) { - var query = `select href, type from activitystream where id in (select preview from activitystream where id=$1)` + var query = `select href from activitystream where id in (select preview from activitystream where id=$1)` rows, err := db.Query(query, id) @@ -906,18 +906,17 @@ func DeletePreviewFromFile(db *sql.DB, id string) { defer rows.Close() for rows.Next() { var href string - var _type string - err := rows.Scan(&href, &_type) + + err := rows.Scan(&href) href = strings.Replace(href, Domain + "/", "", 1) CheckError(err, "error scanning delete attachment") - - if _type != "Tombstone" { + + if(href != "/static/notfound.png") { _, err = os.Stat(href) if err == nil { os.Remove(href) - } + } } - } DeletePreviewFromDB(db, id) @@ -925,7 +924,7 @@ func DeletePreviewFromFile(db *sql.DB, id string) { func DeleteAttachmentFromFile(db *sql.DB, id string) { - var query = `select href, type from activitystream where id in (select attachment from activitystream where id=$1)` + var query = `select href from activitystream where id in (select attachment from activitystream where id=$1)` rows, err := db.Query(query, id) @@ -934,18 +933,17 @@ func DeleteAttachmentFromFile(db *sql.DB, id string) { defer rows.Close() for rows.Next() { var href string - var _type string - err := rows.Scan(&href, &_type) + err := rows.Scan(&href) href = strings.Replace(href, Domain + "/", "", 1) CheckError(err, "error scanning delete preview") - if _type != "Tombstone" { + if(href != "/static/notfound.png") { _, err = os.Stat(href) if err == nil { os.Remove(href) - } + } } } @@ -993,21 +991,33 @@ func DeleteAttachmentRepliesFromDB(db *sql.DB, id string) { func DeleteAttachmentFromDB(db *sql.DB, id string) { datetime := time.Now().Format(time.RFC3339) - var query = `update activitystream set type='Tombstone', mediatype='image/png', href=$1, name='', content='', attributedto='deleted', updated=$2, deleted=$3 where id in (select attachment from activitystream where id=$4)` + var query = `update activitystream set type='Tombstone', mediatype='image/png', href=$1, name='', content='', attributedto='deleted', deleted=$2 where id in (select attachment from activitystream where id=$3)` - _, err := db.Exec(query, Domain + "/public/removed.png", datetime, datetime, id) + _, err := db.Exec(query, Domain + "/static/notfound.png", datetime, id) - CheckError(err, "error with delete attachment") + CheckError(err, "error with delete attachment") + + query = `update cacheactivitystream set type='Tombstone', mediatype='image/png', href=$1, name='', content='', attributedto='deleted', deleted=$2 where id in (select attachment from cacheactivitystream where id=$3)` + + _, err = db.Exec(query, Domain + "/static/notfound.png", datetime, id) + + CheckError(err, "error with delete cache attachment") } func DeletePreviewFromDB(db *sql.DB, id string) { datetime := time.Now().Format(time.RFC3339) - var query = `update activitystream set type='Tombstone', mediatype='image/png', href=$1, name='', content='', attributedto='deleted', updated=$2, deleted=$3 where id in (select preview from activitystream where id=$4)` + var query = `update activitystream set type='Tombstone', mediatype='image/png', href=$1, name='', content='', attributedto='deleted', deleted=$2 where id in (select preview from activitystream where id=$3)` + + _, err := db.Exec(query, Domain + "/static/notfound.png", datetime, id) + + CheckError(err, "error with delete preview") - _, err := db.Exec(query, Domain + "/public/removed.png", datetime, datetime, id) + query = `update cacheactivitystream set type='Tombstone', mediatype='image/png', href=$1, name='', content='', attributedto='deleted', deleted=$2 where id in (select preview from cacheactivitystream where id=$3)` - CheckError(err, "error with delete preview") + _, err = db.Exec(query, Domain + "/static/notfound.png", datetime, id) + + CheckError(err, "error with delete cache preview") } func DeleteObjectRepliedTo(db *sql.DB, id string){ @@ -1019,11 +1029,17 @@ func DeleteObjectRepliedTo(db *sql.DB, id string){ func DeleteObjectFromDB(db *sql.DB, id string) { datetime := time.Now().Format(time.RFC3339) - var query = `update activitystream set type='Tombstone', name='', content='', attributedto='deleted', tripcode='', updated=$1, deleted=$2 where id=$3` + var query = `update activitystream set type='Tombstone', name='', content='', attributedto='deleted', tripcode='', deleted=$1 where id=$2` - _, err := db.Exec(query, datetime, datetime, id) + _, err := db.Exec(query, datetime, id) CheckError(err, "error with delete object") + + query = `update cacheactivitystream set type='Tombstone', name='', content='', attributedto='deleted', tripcode='', deleted=$1 where id=$2` + + _, err = db.Exec(query, datetime, id) + + CheckError(err, "error with delete cache object") } func DeleteObjectsInReplyTo(db *sql.DB, id string) { @@ -1037,11 +1053,16 @@ func DeleteObjectsInReplyTo(db *sql.DB, id string) { func DeleteObjectRepliesFromDB(db *sql.DB, id string) { datetime := time.Now().Format(time.RFC3339) - var query = `update activitystream set type='Tombstone', name='', content='', attributedto='deleted', tripcode='', updated=$1, deleted=$2 where id in (select id from replies where inreplyto=$3)` + var query = `update activitystream set type='Tombstone', name='', content='', attributedto='deleted', tripcode='', deleted=$1 where id in (select id from replies where inreplyto=$2)` - _, err := db.Exec(query, datetime, datetime, id) + _, err := db.Exec(query, datetime, id) CheckError(err, "error with delete object replies") + query = `update cacheactivitystream set type='Tombstone', name='', content='', attributedto='deleted', tripcode='', deleted=$1 where id in (select id from replies where inreplyto=$2)` + + _, err = db.Exec(query, datetime, id) + CheckError(err, "error with delete object cache replies") + } func SetAttachmentFromDB(db *sql.DB, id string, _type string) { @@ -1152,10 +1173,6 @@ func SetObjectAndReplies(db *sql.DB, id string, _type string) { } func DeleteObject(db *sql.DB, id string) { - if(!IsIDLocal(db, id)) { - return - } - DeleteReportActivity(db, id) DeleteAttachmentFromFile(db, id) DeletePreviewFromFile(db, id) @@ -1164,11 +1181,6 @@ func DeleteObject(db *sql.DB, id string) { } func DeleteObjectAndReplies(db *sql.DB, id string) { - - if(!IsIDLocal(db, id)) { - return - } - DeleteReportActivity(db, id) DeleteAttachmentFromFile(db, id) DeletePreviewFromFile(db, id) @@ -740,6 +740,114 @@ func main() { } if !isOP { + DeleteObject(db, id) + } else { + DeleteObjectAndReplies(db, id) + } + + 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 + } + } else { + http.Redirect(w, r, "/" + board, http.StatusSeeOther) + return + } + + w.WriteHeader(http.StatusBadRequest) + w.Write([]byte("")) + }) + + http.HandleFunc("/deleteattach", func(w http.ResponseWriter, r *http.Request){ + + id := r.URL.Query().Get("id") + manage := r.URL.Query().Get("manage") + board := r.URL.Query().Get("board") + col := GetCollectionFromID(id) + actor := col.OrderedItems[0].Actor + + var OP string + if (len(col.OrderedItems[0].InReplyTo) > 0 && col.OrderedItems[0].InReplyTo[0].Id != "") { + OP = col.OrderedItems[0].InReplyTo[0].Id + } else { + OP = id + } + + _, auth := GetPasswordFromSession(r) + + if id == "" || auth == "" { + w.WriteHeader(http.StatusBadRequest) + w.Write([]byte("")) + return + } + + if !HasAuth(db, auth, actor.Id) { + w.WriteHeader(http.StatusBadRequest) + w.Write([]byte("")) + return + } + + DeleteAttachmentFromFile(db, id) + DeletePreviewFromFile(db, id) + + if (manage == "t") { + http.Redirect(w, r, "/" + *Key + "/" + board, http.StatusSeeOther) + 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("/remove", func(w http.ResponseWriter, r *http.Request){ + id := r.URL.Query().Get("id") + manage := r.URL.Query().Get("manage") + board := r.URL.Query().Get("board") + col := GetCollectionFromID(id) + actor := col.OrderedItems[0].Actor + _, auth := GetPasswordFromSession(r) + + if id == "" || auth == "" { + w.WriteHeader(http.StatusBadRequest) + w.Write([]byte("")) + return + } + + if !HasAuth(db, auth, actor.Id) { + w.WriteHeader(http.StatusBadRequest) + w.Write([]byte("")) + return + } + + var obj ObjectBase + obj.Id = id + obj.Actor = actor + + isOP := CheckIfObjectOP(db, obj.Id) + + var OP string + if len(col.OrderedItems[0].InReplyTo) > 0 { + OP = col.OrderedItems[0].InReplyTo[0].Id + } + + if !isOP { SetObject(db, id, "Removed") } else { SetObjectAndReplies(db, id, "Removed") @@ -769,7 +877,7 @@ func main() { w.Write([]byte("")) }) - http.HandleFunc("/deleteattach", func(w http.ResponseWriter, r *http.Request){ + http.HandleFunc("/removeattach", func(w http.ResponseWriter, r *http.Request){ id := r.URL.Query().Get("id") manage := r.URL.Query().Get("manage") @@ -814,7 +922,7 @@ func main() { w.WriteHeader(http.StatusBadRequest) w.Write([]byte("")) - }) + }) http.HandleFunc("/report", func(w http.ResponseWriter, r *http.Request){ diff --git a/static/.#ncatalog.html b/static/.#ncatalog.html new file mode 120000 index 0000000..7e43052 --- /dev/null +++ b/static/.#ncatalog.html @@ -0,0 +1 @@ +namll@parabola.3055
\ No newline at end of file diff --git a/static/ncatalog.html b/static/ncatalog.html index a399d13..43fd6fd 100644 --- a/static/ncatalog.html +++ b/static/ncatalog.html @@ -16,11 +16,11 @@ {{ range .Posts }} <div style="overflow: hidden; vertical-align: top; padding-right: 24px; padding-bottom: 24px; display: inline-block; width: 180px; max-height: 320px; margin-bottom: 10px;"> {{ if eq $board.ModCred $board.Domain $board.Actor.Id }} - <a href="/delete?id={{ .Id }}">[Delete Post]</a> + <a href="/delete?id={{ .Id }}&board={{ $board.Actor.Name }}">[Delete Post]</a> {{ end }} {{ if .Attachment }} {{ if eq $board.ModCred $board.Domain $board.Actor.Id }} - <a href="/deleteattach?id={{ .Id }}">[Delete Attachment]</a> + <a href="/deleteattach?id={{ .Id }}&board={{ $board.Actor.Name }}">[Delete Attachment]</a> {{ end }} <a id="{{ .Id }}-anchor" href="/{{ $board.Name }}/"> <div id="media-{{ .Id }}" style="width:180px;"></div> |