mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-24 08:46:24 -07:00
Get the internal thread and treat threadid as op, properly attach upload to post
This commit is contained in:
parent
8bc5e2148b
commit
c943cdef6a
3 changed files with 30 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
package gcsql
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"strconv"
|
||||
)
|
||||
|
@ -47,6 +48,17 @@ func GetThread(threadID int) (*Thread, error) {
|
|||
return thread, err
|
||||
}
|
||||
|
||||
// GetTopPostThreadID gets the thread ID from the database, given the post ID of a top post
|
||||
func GetTopPostThreadID(opID int) (int, error) {
|
||||
const query = `SELECT thread_id FROM DBPREFIXposts WHERE id = ? and is_top_post`
|
||||
var threadID int
|
||||
err := QueryRowSQL(query, interfaceSlice(opID), interfaceSlice(&threadID))
|
||||
if err == sql.ErrNoRows {
|
||||
err = ErrThreadDoesNotExist
|
||||
}
|
||||
return threadID, err
|
||||
}
|
||||
|
||||
// GetThreadsWithBoardID queries the database for the threads with the given board ID from the database.
|
||||
// If onlyNotDeleted is true, it omits deleted threads and threads that were removed because the max
|
||||
// thread limit was reached
|
||||
|
|
|
@ -56,6 +56,7 @@ func (p *Post) AttachFile(upload *Upload) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
upload.PostID = p.ID
|
||||
if _, err = ExecSQL(query,
|
||||
&upload.PostID, &upload.FileOrder, &upload.OriginalFilename, &upload.Filename, &upload.Checksum, &upload.FileSize,
|
||||
&upload.IsSpoilered, &upload.ThumbnailWidth, &upload.ThumbnailHeight, &upload.Width, &upload.Height,
|
||||
|
|
|
@ -63,15 +63,30 @@ func MakePost(writer http.ResponseWriter, request *http.Request) {
|
|||
post.IP = gcutil.GetRealIP(request)
|
||||
var err error
|
||||
threadidStr := request.FormValue("threadid")
|
||||
// to avoid potential hiccups, we'll just treat the "threadid" form field as the OP ID and convert it internally
|
||||
// to the real thread ID
|
||||
var opID int
|
||||
if threadidStr != "" {
|
||||
// post is a reply
|
||||
if post.ThreadID, err = strconv.Atoi(threadidStr); err != nil {
|
||||
errEv.Str("threadid", threadidStr).Caller().Msg("Invalid threadid value")
|
||||
if opID, err = strconv.Atoi(threadidStr); err != nil {
|
||||
errEv.Err(err).
|
||||
Str("opIDstr", threadidStr).
|
||||
Caller().Msg("Invalid threadid value")
|
||||
serverutil.ServeError(writer, "Invalid form data (invalid threadid)", wantsJSON, map[string]interface{}{
|
||||
"threadid": threadidStr,
|
||||
})
|
||||
return
|
||||
}
|
||||
if opID > 0 {
|
||||
if post.ThreadID, err = gcsql.GetTopPostThreadID(opID); err != nil {
|
||||
errEv.Err(err).
|
||||
Int("opID", opID).
|
||||
Caller().Send()
|
||||
serverutil.ServeError(writer, err.Error(), wantsJSON, map[string]interface{}{
|
||||
"opID": opID,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boardidStr := request.FormValue("boardid")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue