website/pkg/config/variable.go
Noah 400a256ec8 Certification Photo Workflow
* Add "Site Gallery" page showing all public+gallery member photos.
* Add "Certification Required" decorator for gallery and other main pages.
* Add the Certification Photo workflow:
  * Users have a checklist on their dashboard to upload a profile pic
    and post a certification selfie (two requirements)
  * Admins notified by email when a new certification pic comes in.
  * Admin can reject (w/ comment) or approve the pic.
  * Users can re-upload or delete their pic at the cost of losing
    certification status if they make any such changes.
  * Users are emailed when their photo is either approved or rejected.
* User Preferences: can now save the explicit pref to your account.
* Explicit photos on user pages and site gallery are hidden if the
  current user hasn't opted-in (user can always see their own explicit
  photos regardless of the setting)
* If a user is viewing a member gallery and explicit pics are hidden, a
  count of the number of explicit pics is shown to inform the user that
  more DO exist, they just don't see them. The site gallery does not do
  this and simply hides explicit photos.
2022-08-13 15:39:31 -07:00

106 lines
2.4 KiB
Go

package config
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"git.kirsle.net/apps/gosocial/pkg/log"
)
// Current loaded settings.json
var Current = DefaultVariable()
// Variable configuration attributes (loaded from settings.json).
type Variable struct {
BaseURL string
AdminEmail string
Mail Mail
Redis Redis
Database Database
}
// DefaultVariable returns the default settings.json data.
func DefaultVariable() Variable {
return Variable{
BaseURL: "http://localhost:8080",
Mail: Mail{
Enabled: false,
Host: "localhost",
Port: 25,
From: "no-reply@localhost",
},
Redis: Redis{
Host: "localhost",
Port: 6379,
},
Database: Database{
SQLite: "database.sqlite",
Postgres: "host=localhost user=gosocial password=gosocial dbname=gosocial port=5679 sslmode=disable TimeZone=America/Los_Angeles",
},
}
}
// LoadSettings loads the settings.json file or, if not existing, creates it with the default settings.
func LoadSettings() {
if _, err := os.Stat(SettingsPath); !os.IsNotExist(err) {
log.Info("Loading settings from %s", SettingsPath)
content, err := ioutil.ReadFile(SettingsPath)
if err != nil {
panic(fmt.Sprintf("LoadSettings: couldn't read settings.json: %s", err))
}
var v Variable
err = json.Unmarshal(content, &v)
if err != nil {
panic(fmt.Sprintf("LoadSettings: couldn't parse settings.json: %s", err))
}
Current = v
} else {
var buf bytes.Buffer
enc := json.NewEncoder(&buf)
enc.SetIndent("", " ")
err := enc.Encode(DefaultVariable())
if err != nil {
panic(fmt.Sprintf("LoadSettings: couldn't marshal default settings: %s", err))
}
ioutil.WriteFile(SettingsPath, buf.Bytes(), 0600)
log.Warn("NOTICE: Created default settings.json file - review it and configure mail servers and database!")
}
// If there is no DB configured, exit now.
if !Current.Database.IsSQLite && !Current.Database.IsPostgres {
log.Error("No database configured in settings.json. Choose SQLite or Postgres and update the DB connector string!")
os.Exit(1)
}
}
// Mail settings.
type Mail struct {
Enabled bool
Host string // localhost
Port int // 25
From string // noreply@localhost
Username string // SMTP credentials
Password string
}
// Redis settings.
type Redis struct {
Host string
Port int
DB int
}
// Database settings.
type Database struct {
IsSQLite bool
IsPostgres bool
SQLite string
Postgres string
}