mirror of
https://github.com/writefreely/writefreely
synced 2024-11-28 11:30:18 +00:00
Add MaxBlogs config value
Plus update copy / options / templates in the config process.
This commit is contained in:
parent
342542444d
commit
8ab29d89da
3 changed files with 96 additions and 42 deletions
|
@ -35,6 +35,7 @@ type (
|
|||
SingleUser bool `ini:"single_user"`
|
||||
OpenRegistration bool `ini:"open_registration"`
|
||||
MinUsernameLen int `ini:"min_username_len"`
|
||||
MaxBlogs int `ini:"max_blogs"`
|
||||
|
||||
// Federation
|
||||
Federation bool `ini:"federation"`
|
||||
|
@ -65,6 +66,7 @@ func New() *Config {
|
|||
WebFonts: true,
|
||||
SingleUser: true,
|
||||
MinUsernameLen: 3,
|
||||
MaxBlogs: 1,
|
||||
Federation: true,
|
||||
PublicStats: true,
|
||||
},
|
||||
|
|
17
config/funcs.go
Normal file
17
config/funcs.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// FriendlyHost returns the app's Host sans any schema
|
||||
func (ac AppCfg) FriendlyHost() string {
|
||||
return ac.Host[strings.Index(ac.Host, "://")+len("://"):]
|
||||
}
|
||||
|
||||
func (ac AppCfg) CanCreateBlogs(currentlyUsed uint64) bool {
|
||||
if ac.MaxBlogs <= 0 {
|
||||
return true
|
||||
}
|
||||
return int(currentlyUsed) < ac.MaxBlogs
|
||||
}
|
|
@ -28,7 +28,15 @@ func Configure() error {
|
|||
title(" Server setup ")
|
||||
fmt.Println()
|
||||
|
||||
tmpls := &promptui.PromptTemplates{
|
||||
Success: "{{ . | bold | faint }}: ",
|
||||
}
|
||||
selTmpls := &promptui.SelectTemplates{
|
||||
Selected: fmt.Sprintf(`{{.Label}} {{ . | faint }}`, promptui.IconGood),
|
||||
}
|
||||
|
||||
prompt := promptui.Prompt{
|
||||
Templates: tmpls,
|
||||
Label: "Local port",
|
||||
Validate: validatePort,
|
||||
Default: fmt.Sprintf("%d", c.Server.Port),
|
||||
|
@ -39,21 +47,12 @@ func Configure() error {
|
|||
}
|
||||
c.Server.Port, _ = strconv.Atoi(port) // Ignore error, as we've already validated number
|
||||
|
||||
prompt = promptui.Prompt{
|
||||
Label: "Public-facing host",
|
||||
Validate: validateDomain,
|
||||
Default: c.App.Host,
|
||||
}
|
||||
c.App.Host, err = prompt.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
title(" Database setup ")
|
||||
fmt.Println()
|
||||
|
||||
prompt = promptui.Prompt{
|
||||
Templates: tmpls,
|
||||
Label: "Username",
|
||||
Validate: validateNonEmpty,
|
||||
Default: c.Database.User,
|
||||
|
@ -64,6 +63,7 @@ func Configure() error {
|
|||
}
|
||||
|
||||
prompt = promptui.Prompt{
|
||||
Templates: tmpls,
|
||||
Label: "Password",
|
||||
Validate: validateNonEmpty,
|
||||
Default: c.Database.Password,
|
||||
|
@ -75,6 +75,7 @@ func Configure() error {
|
|||
}
|
||||
|
||||
prompt = promptui.Prompt{
|
||||
Templates: tmpls,
|
||||
Label: "Database name",
|
||||
Validate: validateNonEmpty,
|
||||
Default: c.Database.Database,
|
||||
|
@ -85,6 +86,7 @@ func Configure() error {
|
|||
}
|
||||
|
||||
prompt = promptui.Prompt{
|
||||
Templates: tmpls,
|
||||
Label: "Host",
|
||||
Validate: validateNonEmpty,
|
||||
Default: c.Database.Host,
|
||||
|
@ -95,6 +97,7 @@ func Configure() error {
|
|||
}
|
||||
|
||||
prompt = promptui.Prompt{
|
||||
Templates: tmpls,
|
||||
Label: "Port",
|
||||
Validate: validatePort,
|
||||
Default: fmt.Sprintf("%d", c.Database.Port),
|
||||
|
@ -110,20 +113,26 @@ func Configure() error {
|
|||
fmt.Println()
|
||||
|
||||
selPrompt := promptui.Select{
|
||||
Templates: selTmpls,
|
||||
Label: "Site type",
|
||||
Items: []string{"Single user", "Multiple users"},
|
||||
Items: []string{"Single user blog", "Multi-user instance"},
|
||||
}
|
||||
_, usersType, err := selPrompt.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.App.SingleUser = usersType == "Single user"
|
||||
// TODO: if c.App.SingleUser {
|
||||
// prompt for username
|
||||
// prompt for password
|
||||
// create blog
|
||||
|
||||
siteNameLabel := "Instance name"
|
||||
if c.App.SingleUser {
|
||||
siteNameLabel = "Blog name"
|
||||
}
|
||||
prompt = promptui.Prompt{
|
||||
Templates: tmpls,
|
||||
Label: siteNameLabel,
|
||||
Validate: validateNonEmpty,
|
||||
Default: c.App.SiteName,
|
||||
|
@ -133,8 +142,20 @@ func Configure() error {
|
|||
return err
|
||||
}
|
||||
|
||||
prompt = promptui.Prompt{
|
||||
Templates: tmpls,
|
||||
Label: "Public URL",
|
||||
Validate: validateDomain,
|
||||
Default: c.App.Host,
|
||||
}
|
||||
c.App.Host, err = prompt.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !c.App.SingleUser {
|
||||
selPrompt = promptui.Select{
|
||||
Templates: selTmpls,
|
||||
Label: "Registration",
|
||||
Items: []string{"Open", "Closed"},
|
||||
}
|
||||
|
@ -143,9 +164,21 @@ func Configure() error {
|
|||
return err
|
||||
}
|
||||
c.App.OpenRegistration = regType == "Open"
|
||||
|
||||
prompt = promptui.Prompt{
|
||||
Templates: tmpls,
|
||||
Label: "Max blogs per user",
|
||||
Default: fmt.Sprintf("%d", c.App.MaxBlogs),
|
||||
}
|
||||
maxBlogs, err := prompt.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.App.MaxBlogs, _ = strconv.Atoi(maxBlogs) // Ignore error, as we've already validated number
|
||||
}
|
||||
|
||||
selPrompt = promptui.Select{
|
||||
Templates: selTmpls,
|
||||
Label: "Federation",
|
||||
Items: []string{"Enabled", "Disabled"},
|
||||
}
|
||||
|
@ -157,6 +190,7 @@ func Configure() error {
|
|||
|
||||
if c.App.Federation {
|
||||
selPrompt = promptui.Select{
|
||||
Templates: selTmpls,
|
||||
Label: "Federation usage stats",
|
||||
Items: []string{"Public", "Private"},
|
||||
}
|
||||
|
@ -167,6 +201,7 @@ func Configure() error {
|
|||
c.App.PublicStats = fedStatsType == "Public"
|
||||
|
||||
selPrompt = promptui.Select{
|
||||
Templates: selTmpls,
|
||||
Label: "Instance metadata privacy",
|
||||
Items: []string{"Public", "Private"},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue