mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-09-04 10:06:24 -07:00
Fix manage postinfo action
This commit is contained in:
parent
36fbf6d45d
commit
d5c9d4e657
3 changed files with 73 additions and 29 deletions
|
@ -105,22 +105,48 @@ func GetReplyFileCount(postID int) (int, error) {
|
|||
return count, err
|
||||
}
|
||||
|
||||
func GetPostsFromIP(ip string, limit int, onlyNotDeleted bool) ([]Post, error) {
|
||||
sql := `SELECT
|
||||
DBPREFIXposts.id,
|
||||
thread_id AS threadid,
|
||||
(SELECT id FROM DBPREFIXposts WHERE is_top_post = TRUE AND thread_id = threadid LIMIT 1),
|
||||
(SELECT board_id FROM DBPREFIXthreads WHERE id = DBPREFIXposts.thread_id) as board_id,
|
||||
created_on,name,tripcode,email,subject,message,message_raw,password,
|
||||
const selectPostsQuery = `SELECT
|
||||
DBPREFIXposts.id,
|
||||
thread_id AS threadid,
|
||||
(SELECT id FROM DBPREFIXposts WHERE is_top_post = TRUE AND thread_id = threadid LIMIT 1),
|
||||
(SELECT board_id FROM DBPREFIXthreads WHERE id = DBPREFIXposts.thread_id) as board_id,
|
||||
ip,created_on,name,tripcode,email,subject,message,message_raw,password,
|
||||
|
||||
COALESCE(files.filename,''),
|
||||
COALESCE(files.original_filename,''),
|
||||
COALESCE(files.thumbnail_width, 0),
|
||||
COALESCE(files.thumbnail_height, 0),
|
||||
COALESCE(files.width, 0),
|
||||
COALESCE(files.height, 0)
|
||||
FROM DBPREFIXposts LEFT OUTER JOIN DBPREFIXfiles AS files ON files.post_id = DBPREFIXposts.id
|
||||
WHERE ip = ?`
|
||||
COALESCE(files.filename,''),
|
||||
COALESCE(files.original_filename,''),
|
||||
COALESCE(files.file_size, 0),
|
||||
COALESCE(files.checksum, ''),
|
||||
COALESCE(files.thumbnail_width, 0),
|
||||
COALESCE(files.thumbnail_height, 0),
|
||||
COALESCE(files.width, 0),
|
||||
COALESCE(files.height, 0)
|
||||
FROM DBPREFIXposts LEFT OUTER JOIN DBPREFIXfiles AS files ON files.post_id = DBPREFIXposts.id`
|
||||
|
||||
// GetPostFromID gets the post from the database with a matching ID,
|
||||
// optionally requiring it to not be deleted
|
||||
func GetPostFromID(id int, onlyNotDeleted bool) (*Post, error) {
|
||||
sql := selectPostsQuery + ` WHERE DBPREFIXposts.id = ?`
|
||||
if onlyNotDeleted {
|
||||
sql += " AND is_deleted = 0"
|
||||
}
|
||||
var drop int
|
||||
post := new(Post)
|
||||
err := QueryRowSQL(sql, []interface{}{id}, []interface{}{
|
||||
&post.ID, &drop, &post.ParentID,
|
||||
&post.BoardID,
|
||||
&post.IP, &post.Timestamp, &post.Name, &post.Tripcode, &post.Email, &post.Subject, &post.MessageHTML, &post.MessageText, &post.Password,
|
||||
&post.Filename, &post.FilenameOriginal, &post.Filesize, &post.FileChecksum, &post.ThumbW, &post.ThumbH, &post.ImageW, &post.ImageH,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return post, err
|
||||
}
|
||||
|
||||
// GetPostsFromIP gets the posts from the database with a matching IP address, specifying
|
||||
// optionally requiring them to not be deleted
|
||||
func GetPostsFromIP(ip string, limit int, onlyNotDeleted bool) ([]Post, error) {
|
||||
sql := selectPostsQuery + ` WHERE DBPREFIXposts.ip = ?`
|
||||
if onlyNotDeleted {
|
||||
sql += " AND is_deleted = 0"
|
||||
}
|
||||
|
@ -133,13 +159,12 @@ func GetPostsFromIP(ip string, limit int, onlyNotDeleted bool) ([]Post, error) {
|
|||
var posts []Post
|
||||
for rows.Next() {
|
||||
var post Post
|
||||
post.IP = ip
|
||||
var drop int
|
||||
if err = rows.Scan(
|
||||
&post.ID, &drop, &post.ParentID,
|
||||
&post.BoardID,
|
||||
&post.Timestamp, &post.Name, &post.Tripcode, &post.Email, &post.Subject, &post.MessageHTML, &post.MessageText, &post.Password,
|
||||
&post.Filename, &post.FilenameOriginal, &post.ThumbW, &post.ThumbH, &post.ImageW, &post.ImageH,
|
||||
&post.IP, &post.Timestamp, &post.Name, &post.Tripcode, &post.Email, &post.Subject, &post.MessageHTML, &post.MessageText, &post.Password,
|
||||
&post.Filename, &post.FilenameOriginal, &post.Filesize, &post.FileChecksum, &post.ThumbW, &post.ThumbH, &post.ImageW, &post.ImageH,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -7,15 +7,12 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
var abstractSelectPosts = `
|
||||
/*
|
||||
Left join singlefiles on recentposts where recentposts.selfid = singlefiles.post_id
|
||||
Coalesce filenames to "" (if filename = null -> "" else filename)
|
||||
|
||||
|
||||
*/
|
||||
|
||||
Select
|
||||
var abstractSelectPosts = `
|
||||
SELECT
|
||||
recentposts.selfid AS id,
|
||||
recentposts.toppostid AS parentid,
|
||||
recentposts.boardid,
|
||||
|
@ -171,8 +168,8 @@ func GetSpecificTopPost(ID int) (Post, error) {
|
|||
// GetSpecificPostByString gets a specific post for a given string id.
|
||||
// Deprecated: This method was created to support old functionality during the database refactor of april 2020
|
||||
// The code should be changed to reflect the new database design
|
||||
func GetSpecificPostByString(ID string) (Post, error) {
|
||||
return getSpecificPostStringDecorated(ID, false)
|
||||
func GetSpecificPostByString(ID string, onlyNotDeleted bool) (Post, error) {
|
||||
return getSpecificPostStringDecorated(ID, onlyNotDeleted)
|
||||
}
|
||||
|
||||
// GetSpecificPost gets a specific post for a given id.
|
||||
|
@ -184,7 +181,7 @@ func GetSpecificPost(ID int, onlyNotDeleted bool) (Post, error) {
|
|||
}
|
||||
|
||||
var specificPostSQL = abstractSelectPosts + "\nWHERE recentposts.selfid = ?"
|
||||
var specificPostSQLNotDeleted = specificPostSQL + "\nWHERE recentposts.is_deleted = FALSE"
|
||||
var specificPostSQLNotDeleted = specificPostSQL + "\nAND recentposts.is_deleted = FALSE"
|
||||
|
||||
func getSpecificPostStringDecorated(ID string, onlyNotDeleted bool) (Post, error) {
|
||||
var sql string
|
||||
|
|
|
@ -252,7 +252,7 @@ var actions = []Action{
|
|||
|
||||
if request.FormValue("postid") != "" {
|
||||
var err error
|
||||
post, err = gcsql.GetSpecificPostByString(request.FormValue("postid"))
|
||||
post, err = gcsql.GetSpecificPostByString(request.FormValue("postid"), true)
|
||||
if err != nil {
|
||||
err = errors.New("Error getting post: " + err.Error())
|
||||
return "", err
|
||||
|
@ -850,8 +850,30 @@ var actions = []Action{
|
|||
Permissions: ModPerms,
|
||||
JSONoutput: AlwaysJSON,
|
||||
Callback: func(writer http.ResponseWriter, request *http.Request, wantsJSON bool) (output interface{}, err error) {
|
||||
post, err := gcsql.GetSpecificPost(gcutil.HackyStringToInt(request.FormValue("postid")), false)
|
||||
return post, err
|
||||
postIDstr := request.FormValue("postid")
|
||||
if postIDstr == "" {
|
||||
return "", errors.New("invalid request (missing postid)")
|
||||
}
|
||||
var postID int
|
||||
if postID, err = strconv.Atoi(postIDstr); err != nil {
|
||||
return "", err
|
||||
}
|
||||
post, err := gcsql.GetPostFromID(postID, true)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
postInfo := map[string]interface{}{
|
||||
"post": post,
|
||||
"ip": post.IP,
|
||||
}
|
||||
names, err := net.LookupAddr(post.IP)
|
||||
if err == nil {
|
||||
postInfo["ipFQDN"] = names
|
||||
} else {
|
||||
postInfo["ipFQDN"] = []string{err.Error()}
|
||||
}
|
||||
return postInfo, nil
|
||||
}},
|
||||
// {
|
||||
// may end up deleting this
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue