mirror of
https://github.com/writefreely/writefreely
synced 2024-11-10 11:24:13 +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
|
||||
}
|
119
config/setup.go
119
config/setup.go
|
@ -28,10 +28,18 @@ 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{
|
||||
Label: "Local port",
|
||||
Validate: validatePort,
|
||||
Default: fmt.Sprintf("%d", c.Server.Port),
|
||||
Templates: tmpls,
|
||||
Label: "Local port",
|
||||
Validate: validatePort,
|
||||
Default: fmt.Sprintf("%d", c.Server.Port),
|
||||
}
|
||||
port, err := prompt.Run()
|
||||
if err != nil {
|
||||
|
@ -39,24 +47,15 @@ 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{
|
||||
Label: "Username",
|
||||
Validate: validateNonEmpty,
|
||||
Default: c.Database.User,
|
||||
Templates: tmpls,
|
||||
Label: "Username",
|
||||
Validate: validateNonEmpty,
|
||||
Default: c.Database.User,
|
||||
}
|
||||
c.Database.User, err = prompt.Run()
|
||||
if err != nil {
|
||||
|
@ -64,10 +63,11 @@ func Configure() error {
|
|||
}
|
||||
|
||||
prompt = promptui.Prompt{
|
||||
Label: "Password",
|
||||
Validate: validateNonEmpty,
|
||||
Default: c.Database.Password,
|
||||
Mask: '*',
|
||||
Templates: tmpls,
|
||||
Label: "Password",
|
||||
Validate: validateNonEmpty,
|
||||
Default: c.Database.Password,
|
||||
Mask: '*',
|
||||
}
|
||||
c.Database.Password, err = prompt.Run()
|
||||
if err != nil {
|
||||
|
@ -75,9 +75,10 @@ func Configure() error {
|
|||
}
|
||||
|
||||
prompt = promptui.Prompt{
|
||||
Label: "Database name",
|
||||
Validate: validateNonEmpty,
|
||||
Default: c.Database.Database,
|
||||
Templates: tmpls,
|
||||
Label: "Database name",
|
||||
Validate: validateNonEmpty,
|
||||
Default: c.Database.Database,
|
||||
}
|
||||
c.Database.Database, err = prompt.Run()
|
||||
if err != nil {
|
||||
|
@ -85,9 +86,10 @@ func Configure() error {
|
|||
}
|
||||
|
||||
prompt = promptui.Prompt{
|
||||
Label: "Host",
|
||||
Validate: validateNonEmpty,
|
||||
Default: c.Database.Host,
|
||||
Templates: tmpls,
|
||||
Label: "Host",
|
||||
Validate: validateNonEmpty,
|
||||
Default: c.Database.Host,
|
||||
}
|
||||
c.Database.Host, err = prompt.Run()
|
||||
if err != nil {
|
||||
|
@ -95,9 +97,10 @@ func Configure() error {
|
|||
}
|
||||
|
||||
prompt = promptui.Prompt{
|
||||
Label: "Port",
|
||||
Validate: validatePort,
|
||||
Default: fmt.Sprintf("%d", c.Database.Port),
|
||||
Templates: tmpls,
|
||||
Label: "Port",
|
||||
Validate: validatePort,
|
||||
Default: fmt.Sprintf("%d", c.Database.Port),
|
||||
}
|
||||
dbPort, err := prompt.Run()
|
||||
if err != nil {
|
||||
|
@ -110,44 +113,74 @@ func Configure() error {
|
|||
fmt.Println()
|
||||
|
||||
selPrompt := promptui.Select{
|
||||
Label: "Site type",
|
||||
Items: []string{"Single user", "Multiple users"},
|
||||
Templates: selTmpls,
|
||||
Label: "Site type",
|
||||
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{
|
||||
Label: siteNameLabel,
|
||||
Validate: validateNonEmpty,
|
||||
Default: c.App.SiteName,
|
||||
Templates: tmpls,
|
||||
Label: siteNameLabel,
|
||||
Validate: validateNonEmpty,
|
||||
Default: c.App.SiteName,
|
||||
}
|
||||
c.App.SiteName, err = prompt.Run()
|
||||
if err != nil {
|
||||
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{
|
||||
Label: "Registration",
|
||||
Items: []string{"Open", "Closed"},
|
||||
Templates: selTmpls,
|
||||
Label: "Registration",
|
||||
Items: []string{"Open", "Closed"},
|
||||
}
|
||||
_, regType, err := selPrompt.Run()
|
||||
if err != nil {
|
||||
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{
|
||||
Label: "Federation",
|
||||
Items: []string{"Enabled", "Disabled"},
|
||||
Templates: selTmpls,
|
||||
Label: "Federation",
|
||||
Items: []string{"Enabled", "Disabled"},
|
||||
}
|
||||
_, fedType, err := selPrompt.Run()
|
||||
if err != nil {
|
||||
|
@ -157,8 +190,9 @@ func Configure() error {
|
|||
|
||||
if c.App.Federation {
|
||||
selPrompt = promptui.Select{
|
||||
Label: "Federation usage stats",
|
||||
Items: []string{"Public", "Private"},
|
||||
Templates: selTmpls,
|
||||
Label: "Federation usage stats",
|
||||
Items: []string{"Public", "Private"},
|
||||
}
|
||||
_, fedStatsType, err := selPrompt.Run()
|
||||
if err != nil {
|
||||
|
@ -167,8 +201,9 @@ func Configure() error {
|
|||
c.App.PublicStats = fedStatsType == "Public"
|
||||
|
||||
selPrompt = promptui.Select{
|
||||
Label: "Instance metadata privacy",
|
||||
Items: []string{"Public", "Private"},
|
||||
Templates: selTmpls,
|
||||
Label: "Instance metadata privacy",
|
||||
Items: []string{"Public", "Private"},
|
||||
}
|
||||
_, fedStatsType, err = selPrompt.Run()
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue