mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-05 08:46: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.")
|
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 {
|
if err != nil {
|
||||||
html += err.Error() + "<br />"
|
html += err.Error() + "<br />"
|
||||||
op_posts = make([]interface{}, 0)
|
op_posts = make([]interface{}, 0)
|
||||||
|
@ -111,7 +111,7 @@ func buildBoardPages(board *BoardsTable) (html string) {
|
||||||
op_post := op_post_i.(PostTable)
|
op_post := op_post_i.(PostTable)
|
||||||
|
|
||||||
if op_post.Stickied {
|
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 {
|
if err != nil {
|
||||||
html += err.Error() + "<br />"
|
html += err.Error() + "<br />"
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ func buildBoardPages(board *BoardsTable) (html string) {
|
||||||
}
|
}
|
||||||
stickied_threads = append(stickied_threads, thread)
|
stickied_threads = append(stickied_threads, thread)
|
||||||
} else {
|
} 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 {
|
if err != nil {
|
||||||
html += err.Error() + "<br />"
|
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
|
// 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 is set to true, ignore which, otherwise, which = build only specified boardid
|
||||||
if !all {
|
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 := _thread[0]
|
||||||
thread_struct := thread.(PostTable)
|
thread_struct := thread.(PostTable)
|
||||||
html += buildThreadPages(&thread_struct) + "<br />\n"
|
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 {
|
if len(threads) == 0 {
|
||||||
return html + "No threads to build.<br />\n"
|
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) {
|
func buildThreadPages(op *PostTable) (html string) {
|
||||||
|
fmt.Printf("OP: %d\n", op.ID)
|
||||||
var board_dir string
|
var board_dir string
|
||||||
var replies []interface{}
|
var replies []interface{}
|
||||||
var current_page_file *os.File
|
var current_page_file *os.File
|
||||||
|
@ -212,7 +214,7 @@ func buildThreadPages(op *PostTable) (html string) {
|
||||||
return err.Error()
|
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 {
|
if err != nil {
|
||||||
return "Error building thread " + strconv.Itoa(op.ID) + ":" + err.Error()
|
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 {
|
for i, _ := range thread_pages {
|
||||||
thread_pages[i] = append([]interface{}{op}, thread_pages[i]...)
|
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
|
op.NumPages = len(thread_pages) - 1
|
||||||
for page_num, page_posts := range thread_pages {
|
for page_num, page_posts := range thread_pages {
|
||||||
fmt.Printf("len(page_posts): %d\n", len(page_posts))
|
fmt.Printf("len(page_posts): %d\n", len(page_posts))
|
||||||
|
|
|
@ -139,11 +139,8 @@ func getBoardArr(where string) (boards []BoardsTable, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPostArr(where string) (posts []interface{}, err error) {
|
func getPostArr(sql string) (posts []interface{}, err error) {
|
||||||
if where == "" {
|
rows, err := db.Query(sql)
|
||||||
where = "1"
|
|
||||||
}
|
|
||||||
rows, err := db.Query("SELECT * FROM `" + config.DBprefix + "posts` WHERE " + where)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
error_log.Print(err.Error())
|
error_log.Print(err.Error())
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue