mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-03 19:56:22 -07:00
Add config defaults
This commit is contained in:
parent
77380750ae
commit
50c58a91ec
3 changed files with 106 additions and 24 deletions
|
@ -18,9 +18,51 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cfg *GochanConfig
|
cfg *GochanConfig
|
||||||
cfgPath string
|
cfgPath string
|
||||||
cfgDefaults = map[string]interface{}{}
|
cfgDefaults = map[string]interface{}{
|
||||||
|
"WebRoot": "/",
|
||||||
|
// SiteConfig
|
||||||
|
"FirstPage": []string{"index.html", "firstrun.html", "1.html"},
|
||||||
|
"CookieMaxAge": "1y",
|
||||||
|
"LockdownMessage": "This imageboard has temporarily disabled posting. We apologize for the inconvenience",
|
||||||
|
"SiteName": "Gochan",
|
||||||
|
"MinifyHTML": true,
|
||||||
|
"MinifyJS": true,
|
||||||
|
"MaxRecentPosts": 3,
|
||||||
|
"EnableAppeals": true,
|
||||||
|
"MaxLogDays": 14,
|
||||||
|
|
||||||
|
// BoardConfig
|
||||||
|
"DateTimeFormat": "Mon, January 02, 2006 15:04 PM",
|
||||||
|
"CaptchaWidth": 240,
|
||||||
|
"CaptchaHeight": 80,
|
||||||
|
"CaptchaMinutesTimeout": 15,
|
||||||
|
|
||||||
|
// PostConfig
|
||||||
|
"NewThreadDelay": 30,
|
||||||
|
"ReplyDelay": 7,
|
||||||
|
"MaxLineLength": 150,
|
||||||
|
"ThreadsPerPage": 15,
|
||||||
|
"PostsPerThreadPage": 50,
|
||||||
|
"RepliesOnBoardPage": 3,
|
||||||
|
"StickyRepliesOnBoardPage": 1,
|
||||||
|
"BanMsg": "USER WAS BANNED FOR THIS POST",
|
||||||
|
"EmbedWidth": 200,
|
||||||
|
"EmbedHeight": 164,
|
||||||
|
"ExpandButton": true,
|
||||||
|
"ImagesOpenNewTab": true,
|
||||||
|
"NewTabOnOutlinks": true,
|
||||||
|
|
||||||
|
// UploadConfig
|
||||||
|
"ThumbWidth": 200,
|
||||||
|
"ThumbHeight": 200,
|
||||||
|
"ThumbWidthReply": 125,
|
||||||
|
"ThumbHeightReply": 125,
|
||||||
|
"ThumbWidthCatalog": 50,
|
||||||
|
"ThumbHeightCatalog": 50,
|
||||||
|
}
|
||||||
|
|
||||||
boardConfigs = map[string]BoardConfig{}
|
boardConfigs = map[string]BoardConfig{}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -54,18 +96,30 @@ func (gcfg *GochanConfig) ValidateValues() error {
|
||||||
return &ErrInvalidValue{Field: "ListenIP", Value: gcfg.ListenIP}
|
return &ErrInvalidValue{Field: "ListenIP", Value: gcfg.ListenIP}
|
||||||
}
|
}
|
||||||
changed := false
|
changed := false
|
||||||
|
|
||||||
|
if gcfg.WebRoot == "" {
|
||||||
|
gcfg.WebRoot = "/"
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
if len(gcfg.FirstPage) == 0 {
|
if len(gcfg.FirstPage) == 0 {
|
||||||
gcfg.FirstPage = cfgDefaults["FirstPage"].([]string)
|
gcfg.FirstPage = cfgDefaults["FirstPage"].([]string)
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
|
if gcfg.CookieMaxAge == "" {
|
||||||
|
gcfg.CookieMaxAge = cfgDefaults["CookieMaxAge"].(string)
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
_, err := gcutil.ParseDurationString(gcfg.CookieMaxAge)
|
_, err := gcutil.ParseDurationString(gcfg.CookieMaxAge)
|
||||||
if err == gcutil.ErrInvalidDurationString {
|
if err == gcutil.ErrInvalidDurationString {
|
||||||
return &ErrInvalidValue{Field: "CookieMaxAge", Value: gcfg.CookieMaxAge, Details: err.Error() + cookieMaxAgeEx}
|
return &ErrInvalidValue{Field: "CookieMaxAge", Value: gcfg.CookieMaxAge, Details: err.Error() + cookieMaxAgeEx}
|
||||||
} else if err == gcutil.ErrEmptyDurationString {
|
|
||||||
return &ErrInvalidValue{Field: "CookieMaxAge", Details: err.Error() + cookieMaxAgeEx}
|
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if gcfg.LockdownMessage == "" {
|
||||||
|
gcfg.LockdownMessage = cfgDefaults["LockdownMessage"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
if gcfg.DBtype != "mysql" && gcfg.DBtype != "postgresql" {
|
if gcfg.DBtype != "mysql" && gcfg.DBtype != "postgresql" {
|
||||||
return &ErrInvalidValue{Field: "DBtype", Value: gcfg.DBtype, Details: "currently supported values: mysql, postgresql"}
|
return &ErrInvalidValue{Field: "DBtype", Value: gcfg.DBtype, Details: "currently supported values: mysql, postgresql"}
|
||||||
}
|
}
|
||||||
|
@ -76,14 +130,11 @@ func (gcfg *GochanConfig) ValidateValues() error {
|
||||||
gcfg.DefaultStyle = gcfg.Styles[0].Filename
|
gcfg.DefaultStyle = gcfg.Styles[0].Filename
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
if gcfg.NewThreadDelay == 0 {
|
|
||||||
gcfg.NewThreadDelay = cfgDefaults["NewThreadDelay"].(int)
|
if gcfg.SiteName == "" {
|
||||||
changed = true
|
gcfg.SiteName = cfgDefaults["SiteName"].(string)
|
||||||
}
|
|
||||||
if gcfg.ReplyDelay == 0 {
|
|
||||||
gcfg.ReplyDelay = cfgDefaults["ReplyDelay"].(int)
|
|
||||||
changed = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if gcfg.MaxLineLength == 0 {
|
if gcfg.MaxLineLength == 0 {
|
||||||
gcfg.MaxLineLength = cfgDefaults["MaxLineLength"].(int)
|
gcfg.MaxLineLength = cfgDefaults["MaxLineLength"].(int)
|
||||||
changed = true
|
changed = true
|
||||||
|
@ -251,13 +302,12 @@ type Style struct {
|
||||||
|
|
||||||
type UploadConfig struct {
|
type UploadConfig struct {
|
||||||
RejectDuplicateImages bool `description:"Enabling this will cause gochan to reject a post if the image has already been uploaded for another post.\nThis may end up being removed or being made board-specific in the future."`
|
RejectDuplicateImages bool `description:"Enabling this will cause gochan to reject a post if the image has already been uploaded for another post.\nThis may end up being removed or being made board-specific in the future."`
|
||||||
AllowVideoUploads bool
|
ThumbWidth int `description:"OP thumbnails use this as their max width.<br />To keep the aspect ratio, the image will be scaled down to the ThumbWidth or ThumbHeight, whichever is larger."`
|
||||||
ThumbWidth int `description:"OP thumbnails use this as their max width.<br />To keep the aspect ratio, the image will be scaled down to the ThumbWidth or ThumbHeight, whichever is larger."`
|
ThumbHeight int `description:"OP thumbnails use this as their max height.<br />To keep the aspect ratio, the image will be scaled down to the ThumbWidth or ThumbHeight, whichever is larger."`
|
||||||
ThumbHeight int `description:"OP thumbnails use this as their max height.<br />To keep the aspect ratio, the image will be scaled down to the ThumbWidth or ThumbHeight, whichever is larger."`
|
ThumbWidthReply int `description:"Same as ThumbWidth and ThumbHeight but for reply images."`
|
||||||
ThumbWidthReply int `description:"Same as ThumbWidth and ThumbHeight but for reply images."`
|
ThumbHeightReply int `description:"Same as ThumbWidth and ThumbHeight but for reply images."`
|
||||||
ThumbHeightReply int `description:"Same as ThumbWidth and ThumbHeight but for reply images."`
|
ThumbWidthCatalog int `description:"Same as ThumbWidth and ThumbHeight but for catalog images."`
|
||||||
ThumbWidthCatalog int `description:"Same as ThumbWidth and ThumbHeight but for catalog images."`
|
ThumbHeightCatalog int `description:"Same as ThumbWidth and ThumbHeight but for catalog images."`
|
||||||
ThumbHeightCatalog int `description:"Same as ThumbWidth and ThumbHeight but for catalog images."`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type PostConfig struct {
|
type PostConfig struct {
|
||||||
|
|
|
@ -35,6 +35,39 @@ func (iv *ErrInvalidValue) Error() string {
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDefaultBool(key string) bool {
|
||||||
|
boolInterface := cfgDefaults[key]
|
||||||
|
if boolInterface == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
b, ok := boolInterface.(bool)
|
||||||
|
return b && ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDefaultInt(key string) int {
|
||||||
|
intInterface := cfgDefaults[key]
|
||||||
|
if intInterface == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
i, ok := intInterface.(int)
|
||||||
|
if !ok {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDefaultString(key string) string {
|
||||||
|
i := cfgDefaults[key]
|
||||||
|
if i == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
str, ok := i.(string)
|
||||||
|
if !ok {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
// ParseJSON loads and parses JSON data, returning a GochanConfig pointer, any critical missing
|
// ParseJSON loads and parses JSON data, returning a GochanConfig pointer, any critical missing
|
||||||
// fields that don't have defaults, and any error from parsing the file. This doesn't mean that the
|
// fields that don't have defaults, and any error from parsing the file. This doesn't mean that the
|
||||||
// values are valid, just that they exist
|
// values are valid, just that they exist
|
||||||
|
|
|
@ -55,10 +55,10 @@
|
||||||
|
|
||||||
"ThumbWidth": 200,
|
"ThumbWidth": 200,
|
||||||
"ThumbHeight": 200,
|
"ThumbHeight": 200,
|
||||||
"ThumbWidth_reply": 125,
|
"ThumbWidthReply": 125,
|
||||||
"ThumbHeight_reply": 125,
|
"ThumbHeightReply": 125,
|
||||||
"ThumbWidth_catalog": 50,
|
"ThumbWidthCatalog": 50,
|
||||||
"ThumbHeight_catalog": 50,
|
"ThumbHeightCatalog": 50,
|
||||||
|
|
||||||
"ThreadsPerPage": 15,
|
"ThreadsPerPage": 15,
|
||||||
"PostsPerThreadPage": 50,
|
"PostsPerThreadPage": 50,
|
||||||
|
@ -73,7 +73,6 @@
|
||||||
"EmbedHeight": 164,
|
"EmbedHeight": 164,
|
||||||
"ExpandButton": true,
|
"ExpandButton": true,
|
||||||
"ImagesOpenNewTab": true,
|
"ImagesOpenNewTab": true,
|
||||||
"MakeURLsHyperlinked": true,
|
|
||||||
"NewTabOnOutlinks": true,
|
"NewTabOnOutlinks": true,
|
||||||
|
|
||||||
"MinifyHTML": true,
|
"MinifyHTML": true,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue