mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-03 07:36:23 -07:00
fix thread pages getting deleted
This commit is contained in:
parent
8fe37b6568
commit
81cf1494d3
2 changed files with 11 additions and 12 deletions
|
@ -95,7 +95,7 @@ func buildBoardPages(board *BoardsTable) (html string) {
|
|||
error_log.Println("Error: /" + board.Dir + "/ exists, but is not a folder.")
|
||||
}
|
||||
|
||||
op_posts, err := getPostArr("`boardid` = " + strconv.Itoa(board.ID) + " AND `parentid` = 0 AND `deleted_timestamp` = '" + nil_timestamp + "' ORDER BY `bumped` DESC")
|
||||
op_posts, err := getPostArr("SELECT * FROM " + config.DBprefix + "posts WHERE `boardid` = " + strconv.Itoa(board.ID) + " AND `parentid` = 0 AND `deleted_timestamp` = '" + nil_timestamp + "' ORDER BY `bumped` DESC")
|
||||
if err != nil {
|
||||
html += err.Error() + "<br />"
|
||||
op_posts = make([]interface{}, 0)
|
||||
|
@ -111,7 +111,7 @@ func buildBoardPages(board *BoardsTable) (html string) {
|
|||
op_post := op_post_i.(PostTable)
|
||||
|
||||
if op_post.Stickied {
|
||||
posts_in_thread, err = getPostArr("`boardid` = " + strconv.Itoa(board.ID) + " AND `parentid` = " + strconv.Itoa(op_post.ID) + " AND `deleted_timestamp` = '" + nil_timestamp + "' ORDER BY `id` DESC LIMIT " + strconv.Itoa(config.StickyRepliesOnBoardPage))
|
||||
posts_in_thread, err = getPostArr("(SELECT * FROM " + config.DBprefix + "posts WHERE `boardid` = " + strconv.Itoa(board.ID) + " AND `parentid` = " + strconv.Itoa(op_post.ID) + " AND `deleted_timestamp` = '" + nil_timestamp + "' ORDER BY `id` DESC LIMIT " + strconv.Itoa(config.StickyRepliesOnBoardPage) + ") ORDER BY ID ASC")
|
||||
if err != nil {
|
||||
html += err.Error() + "<br />"
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ func buildBoardPages(board *BoardsTable) (html string) {
|
|||
}
|
||||
stickied_threads = append(stickied_threads, thread)
|
||||
} else {
|
||||
posts_in_thread, err = getPostArr("`boardid` = " + strconv.Itoa(board.ID) + " AND `parentid` = " + strconv.Itoa(op_post.ID) + " AND `deleted_timestamp` = '" + nil_timestamp + "' ORDER BY `id` DESC LIMIT " + strconv.Itoa(config.RepliesOnBoardpage))
|
||||
posts_in_thread, err = getPostArr("(SELECT * FROM " + config.DBprefix + "posts WHERE `boardid` = " + strconv.Itoa(board.ID) + " AND `parentid` = " + strconv.Itoa(op_post.ID) + " AND `deleted_timestamp` = '" + nil_timestamp + "' ORDER BY `id` DESC LIMIT " + strconv.Itoa(config.RepliesOnBoardpage) + ") ORDER BY ID ASC")
|
||||
if err != nil {
|
||||
html += err.Error() + "<br />"
|
||||
}
|
||||
|
@ -184,12 +184,13 @@ func buildThreads(all bool, boardid, threadid int) (html string) {
|
|||
// TODO: detect which page will be built and only build that one and the board page
|
||||
// if all is set to true, ignore which, otherwise, which = build only specified boardid
|
||||
if !all {
|
||||
_thread, _ := getPostArr("`boardid` = " + strconv.Itoa(boardid) + " AND `id` = " + strconv.Itoa(threadid) + " AND `parentid` = 0 AND `deleted_timestamp` = '" + nil_timestamp + "'")
|
||||
_thread, _ := getPostArr("SELECT * FROM " + config.DBprefix + "posts WHERE `boardid` = " + strconv.Itoa(boardid) + " AND `id` = " + strconv.Itoa(threadid) + " AND `parentid` = 0 AND `deleted_timestamp` = '" + nil_timestamp + "'")
|
||||
thread := _thread[0]
|
||||
thread_struct := thread.(PostTable)
|
||||
html += buildThreadPages(&thread_struct) + "<br />\n"
|
||||
return
|
||||
}
|
||||
threads, _ := getPostArr("`boardid` = " + strconv.Itoa(boardid) + " AND `parentid` = 0 AND `deleted_timestamp` = '" + nil_timestamp + "'")
|
||||
threads, _ := getPostArr("SELECT * FROM " + config.DBprefix + "posts WHERE `boardid` = " + strconv.Itoa(boardid) + " AND `parentid` = 0 AND `deleted_timestamp` = '" + nil_timestamp + "'")
|
||||
if len(threads) == 0 {
|
||||
return html + "No threads to build.<br />\n"
|
||||
}
|
||||
|
@ -201,6 +202,7 @@ func buildThreads(all bool, boardid, threadid int) (html string) {
|
|||
}
|
||||
|
||||
func buildThreadPages(op *PostTable) (html string) {
|
||||
fmt.Printf("OP: %d\n", op.ID)
|
||||
var board_dir string
|
||||
var replies []interface{}
|
||||
var current_page_file *os.File
|
||||
|
@ -212,7 +214,7 @@ func buildThreadPages(op *PostTable) (html string) {
|
|||
return err.Error()
|
||||
}
|
||||
|
||||
replies, err = getPostArr("`boardid` = " + strconv.Itoa(op.BoardID) + " AND `parentid` = " + strconv.Itoa(op.ID) + " AND `deleted_timestamp` = '" + nil_timestamp + "'")
|
||||
replies, err = getPostArr("SELECT * FROM " + config.DBprefix + "posts WHERE `boardid` = " + strconv.Itoa(op.BoardID) + " AND `parentid` = " + strconv.Itoa(op.ID) + " AND `deleted_timestamp` = '" + nil_timestamp + "'")
|
||||
if err != nil {
|
||||
return "Error building thread " + strconv.Itoa(op.ID) + ":" + err.Error()
|
||||
}
|
||||
|
@ -220,7 +222,7 @@ func buildThreadPages(op *PostTable) (html string) {
|
|||
for i, _ := range thread_pages {
|
||||
thread_pages[i] = append([]interface{}{op}, thread_pages[i]...)
|
||||
}
|
||||
deleteMatchingFiles(path.Join(config.DocumentRoot, board_dir, "res"), "\\.html$")
|
||||
deleteMatchingFiles(path.Join(config.DocumentRoot, board_dir, "res"), strconv.Itoa(op.ID)+"p%*\\.html")
|
||||
op.NumPages = len(thread_pages) - 1
|
||||
for page_num, page_posts := range thread_pages {
|
||||
fmt.Printf("len(page_posts): %d\n", len(page_posts))
|
||||
|
|
|
@ -139,11 +139,8 @@ func getBoardArr(where string) (boards []BoardsTable, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func getPostArr(where string) (posts []interface{}, err error) {
|
||||
if where == "" {
|
||||
where = "1"
|
||||
}
|
||||
rows, err := db.Query("SELECT * FROM `" + config.DBprefix + "posts` WHERE " + where)
|
||||
func getPostArr(sql string) (posts []interface{}, err error) {
|
||||
rows, err := db.Query(sql)
|
||||
if err != nil {
|
||||
error_log.Print(err.Error())
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue