1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-09-04 10:06:24 -07:00

add some board info functions

This commit is contained in:
Eggbertx 2022-10-31 12:43:39 -07:00
parent ca6f5fc793
commit fb708bb6f3
2 changed files with 55 additions and 12 deletions

View file

@ -24,6 +24,7 @@ func (m *Pre2021Migrator) MigrateBoards() error {
if err != nil {
return err
}
defer rows.Close()
for rows.Next() {
var id int
var dir string
@ -85,18 +86,18 @@ func (m *Pre2021Migrator) MigrateBoards() error {
// create new board using the board data from the old db
// omitting things like ID and creation date since we don't really care
if err = gcsql.CreateBoard(&gcsql.Board{
Dir: dir,
Title: title,
Subtitle: subtitle,
Description: description,
SectionID: section,
MaxFilesize: max_file_size,
MaxPages: max_pages,
DefaultStyle: default_style,
Locked: locked,
AnonymousName: anonymous,
ForceAnonymous: forced_anon,
MaxAge: max_age,
Dir: dir,
Title: title,
Subtitle: subtitle,
Description: description,
SectionID: section,
MaxFilesize: max_file_size,
// MaxPages: max_pages,
DefaultStyle: default_style,
Locked: locked,
AnonymousName: anonymous,
ForceAnonymous: forced_anon,
// MaxAge: max_age,
AutosageAfter: autosage_after,
NoImagesAfter: no_images_after,
MaxMessageLength: max_message_length,

View file

@ -48,6 +48,7 @@ func getAllBoards() ([]Board, error) {
if err != nil {
return nil, err
}
defer rows.Close()
var boards []Board
for rows.Next() {
var board Board
@ -200,6 +201,47 @@ func getBoardIDFromURI(uri string) (int, error) {
return id, err
}
func (board *Board) GetThreads(onlyNotDeleted bool) ([]Thread, error) {
query := selectThreadsBaseSQL + " WHERE id = ?"
if onlyNotDeleted {
query += " AND is_deleted = FALSE"
}
rows, err := QuerySQL(query, board.ID)
if err != nil {
return nil, err
}
defer rows.Close()
var threads []Thread
for rows.Next() {
var thread Thread
err = rows.Scan(
&thread.ID, &thread.BoardID, &thread.Locked, &thread.Stickied, &thread.Anchored,
&thread.Cyclical, &thread.LastBump, &thread.DeletedAt, &thread.IsDeleted,
)
if err != nil {
return threads, err
}
threads = append(threads, thread)
}
return threads, nil
}
// IsHidden returns true if the board is in a section that is hidden, otherwise false. If it is in a section
// that is not in the AllSections array, it returns defValueIfMissingSection
func (board *Board) IsHidden(defValueIfMissingSection bool) bool {
for s := range AllSections {
if AllSections[s].ID == board.SectionID {
return AllSections[s].Hidden
}
}
return defValueIfMissingSection // board is not in a valid section (or AllSections needs to be reset)
}
// AbsolutePath returns the full filepath of the board directory
func (board *Board) AbsolutePath(subpath ...string) string {
return path.Join(config.GetSystemCriticalConfig().DocumentRoot, board.Dir, path.Join(subpath...))
}
// WebPath returns a string that represents the file's path as accessible by a browser
// fileType should be "boardPage", "threadPage", "upload", or "thumb"
func (board *Board) WebPath(fileName, fileType string) string {