From ad683a1b343d7aba3f5d7a6ed92be183b7eb8e6a Mon Sep 17 00:00:00 2001 From: Joshua Merrell Date: Sat, 3 Feb 2018 10:21:45 -0800 Subject: [PATCH] Hide gochan's root directory if someone tries to make a board when the directory already exists, don't throw an error if a board SQL column doesn't have a default (they all should now, this is for old installations) --- gochan.example.json | 1 + initialsetupdb.sql | 5 ++--- src/manage.go | 26 ++++++++++++-------------- src/posting.go | 1 + src/types.go | 7 +++++-- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/gochan.example.json b/gochan.example.json index 87a9ac87..44aeed55 100644 --- a/gochan.example.json +++ b/gochan.example.json @@ -40,6 +40,7 @@ "DefaultStyle_txt": "pipes", "AllowDuplicateImages": true, + "AllowVideoUploads": true, "NewThreadDelay": 30, "ReplyDelay": 7, "MaxLineLength": 150, diff --git a/initialsetupdb.sql b/initialsetupdb.sql index 00256dfc..f595e04f 100644 --- a/initialsetupdb.sql +++ b/initialsetupdb.sql @@ -61,10 +61,9 @@ CREATE TABLE IF NOT EXISTS `DBPREFIXboards` ( `autosage_after` INT(5) UNSIGNED NOT NULL DEFAULT 200, `no_images_after` INT(5) UNSIGNED NOT NULL DEFAULT 0, `max_message_length` INT(10) UNSIGNED NOT NULL DEFAULT 8192, - `embeds_allowed` TINYINT(1) NOT NULL, + `embeds_allowed` TINYINT(1) NOT NULL DEFAULT 1, `redirect_to_thread` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, - `require_file` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, - + `require_file` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, `enable_catalog` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=0; diff --git a/src/manage.go b/src/manage.go index 461e5086..50010378 100644 --- a/src/manage.go +++ b/src/manage.go @@ -221,7 +221,7 @@ var manage_functions = map[string]ManageFunction{ Permissions: 3, Callback: func() (html string) { html = "" - rows, err := db.Query("SELECT `dir` FROM `" + config.DBprefix + "boards`;") + rows, err := db.Query("SELECT `dir` FROM `" + config.DBprefix + "boards`") if err != nil { html += err.Error() return @@ -602,28 +602,28 @@ var manage_functions = map[string]ManageFunction{ err = os.Mkdir(path.Join(config.DocumentRoot, board.Dir), 0777) if err != nil { do = "" - board_creation_status = err.Error() + board_creation_status = "ERROR: directory /" + config.DocumentRoot + "/" + board.Dir + "/ already exists!" break } err = os.Mkdir(path.Join(config.DocumentRoot, board.Dir, "res"), 0777) if err != nil { do = "" - board_creation_status = err.Error() + board_creation_status = "ERROR: directory /" + config.DocumentRoot + "/" + board.Dir + "/res/ already exists!" break } err = os.Mkdir(path.Join(config.DocumentRoot, board.Dir, "thumb"), 0777) if err != nil { do = "" - board_creation_status = err.Error() + board_creation_status = "ERROR: directory /" + config.DocumentRoot + "/" + board.Dir + "/thumb/ already exists!" break } err = os.Mkdir(path.Join(config.DocumentRoot, board.Dir, "src"), 0777) if err != nil { do = "" - board_creation_status = err.Error() + board_creation_status = "ERROR: directory /" + config.DocumentRoot + "/" + board.Dir + "/src/ already exists!" break } stmt, err := db.Prepare( @@ -677,24 +677,23 @@ var manage_functions = map[string]ManageFunction{ default: // put the default column values in the text boxes rows, err = db.Query("SELECT `column_name`,`column_default` FROM `information_schema`.`columns` WHERE `table_name` = '" + config.DBprefix + "boards'") + defer func() { + if rows != nil { + rows.Close() + } + }() if err != nil { html += err.Error() - println(1, err.Error()) + println(1, "Error getting column names from boards table:"+err.Error()) return } for rows.Next() { var column_name string var column_default string - err = rows.Scan(&column_name, &column_default) - if err != nil { - html += err.Error() - println(1, err.Error()) - return - } + rows.Scan(&column_name, &column_default) column_default_int, _ := strconv.Atoi(column_default) column_default_bool := (column_default_int == 1) - println(1, "Got this far...") switch column_name { case "id": board.ID = column_default_int @@ -745,7 +744,6 @@ var manage_functions = map[string]ManageFunction{ case "enable_catalog": board.EnableCatalog = column_default_bool } - println(1, "Done with the switch") } } diff --git a/src/posting.go b/src/posting.go index a4d59140..8ee92c8b 100755 --- a/src/posting.go +++ b/src/posting.go @@ -822,6 +822,7 @@ func createImageThumbnail(image_obj image.Image, size string) image.Image { func createVideoThumbnail(video, thumb string, size int) error { sizeStr := strconv.Itoa(size) outputBytes, err := exec.Command("ffmpeg", "-y", "-itsoffset", "-1", "-i", video, "-vframes", "1", "-filter:v", "scale='min("+sizeStr+"\\, "+sizeStr+"):-1'", thumb).CombinedOutput() + println(2, "ffmpeg output: \n"+string(outputBytes)) if err != nil { outputStringArr := strings.Split(string(outputBytes), "\n") if len(outputStringArr) > 1 { diff --git a/src/types.go b/src/types.go index f1329b79..56d532f1 100644 --- a/src/types.go +++ b/src/types.go @@ -497,7 +497,7 @@ func initConfig() { } if config.DBtype == "" { - println(0, "DBtype not set in gochan.json, halting.") + println(0, "DBtype not set in gochan.json, halting (currently supported values: mysql).") os.Exit(2) } @@ -548,7 +548,10 @@ func initConfig() { } if config.DomainRegex == "" { - config.DomainRegex = "(https|http):\\/\\/(" + config.SiteDomain + ")\\/(.*)" + println(0, "DomainRegex not set in gochan.json, consider using (https|http):\\/\\/("+config.SiteDomain+")\\/(.*)") + println(0, "This should work in most cases. Halting") + os.Exit(2) + //config.DomainRegex = "(https|http):\\/\\/(" + config.SiteDomain + ")\\/(.*)" } if config.Styles_img == nil {