...

Source file src/codeberg.org/tslocum/sriracha/util/config.go

Documentation: codeberg.org/tslocum/sriracha/util

     1  package util
     2  
     3  import (
     4  	"strings"
     5  	"time"
     6  )
     7  
     8  type UploadType struct {
     9  	Ext   string
    10  	MIME  string
    11  	Thumb string
    12  }
    13  
    14  // ImportConfig represents a board import configuration.
    15  type ImportConfig struct {
    16  	Address  string // Address:Port to connect to the database.
    17  	Username string // Database username.
    18  	Password string // Database password.
    19  	DBName   string // Database name.
    20  
    21  	Posts    string // Posts table.
    22  	Keywords string // Keywords table.
    23  }
    24  
    25  func (c ImportConfig) Enabled() bool {
    26  	return c != ImportConfig{}
    27  }
    28  
    29  // Config represents the server configuration.
    30  type Config struct {
    31  	Locale string // Default locale. See locale directory for available languages.
    32  	Root   string // Directory where board files are written to.
    33  	Serve  string // Address:Port to listen for HTTP connections on.
    34  	Header string // Client IP address header.
    35  
    36  	SaltData string // Long random string of text used when one-way hashing data. Must not change once set.
    37  	SaltPass string // Long random string of text used when two-way hashing data. Must not change once set.
    38  	SaltTrip string // Long random string of text used when generating secure tripcodes. Must not change once set.
    39  
    40  	Address  string // Address:Port to connect to the database.
    41  	Username string // Database username.
    42  	Password string // Database password.
    43  	DBName   string // Database name.
    44  	DBURL    string // Database connection URL.
    45  
    46  	MailAddress  string // SMTP server Address:Port.
    47  	MailTLS      bool   // Whether TLS is used to connect to the server.
    48  	MailInsecure bool   // Whether TLS certificate verification is skipped.
    49  	MailUsername string // SMTP server username.
    50  	MailPassword string // SMTP server password.
    51  	MailAuth     string // SMTP server authentication mechanism. May be challenge / plain / none.
    52  	MailFrom     string // "From" email address.
    53  	MailReplyTo  string // "Reply-To" email address.
    54  	MailDomains  string // Regular expression specifying allowed email address domains.
    55  
    56  	Mentions      int // Duration (in minutes) mention notifications are batched together.
    57  	Notifications int // Duration (in minutes) non-mention notifications are batched together.
    58  
    59  	Template string // Custom template directory.
    60  
    61  	Identifiers bool // Whether staff may browse posts by IP hashes and boards may display identifier hashes.
    62  
    63  	Uploads []string // Supported upload file types.
    64  
    65  	Access map[string]string // Specifies which roles may perform each management or moderation action.
    66  
    67  	Import ImportConfig // Board import configuration.
    68  
    69  	// Calculated fields.
    70  	cachedUploads  []*UploadType
    71  	ImportMode     bool
    72  	ImportComplete bool
    73  	StartTime      time.Time
    74  }
    75  
    76  func (c *Config) UploadTypes() []*UploadType {
    77  	if c.cachedUploads != nil {
    78  		return c.cachedUploads
    79  	}
    80  	uploads := []*UploadType{}
    81  	for _, upload := range c.Uploads {
    82  		fields := strings.Fields(upload)
    83  		if len(fields) < 2 {
    84  			continue
    85  		}
    86  		u := &UploadType{
    87  			Ext:  strings.ToLower(fields[0]),
    88  			MIME: strings.ToLower(fields[1]),
    89  		}
    90  		if len(fields) > 2 {
    91  			u.Thumb = fields[2]
    92  		}
    93  		uploads = append(uploads, u)
    94  	}
    95  	c.cachedUploads = uploads
    96  	return uploads
    97  }
    98  

View as plain text