...

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  	Template string // Custom template directory.
    47  
    48  	Identifiers bool // Whether staff may browse posts by IP hashes and boards may display identifier hashes.
    49  
    50  	Uploads []string // Supported upload file types.
    51  
    52  	Import ImportConfig // Board import configuration.
    53  
    54  	// Calculated fields.
    55  	cachedUploads  []*UploadType
    56  	ImportMode     bool
    57  	ImportComplete bool
    58  	StartTime      time.Time
    59  }
    60  
    61  func (c *Config) UploadTypes() []*UploadType {
    62  	if c.cachedUploads != nil {
    63  		return c.cachedUploads
    64  	}
    65  	uploads := []*UploadType{}
    66  	for _, upload := range c.Uploads {
    67  		fields := strings.Fields(upload)
    68  		if len(fields) < 2 {
    69  			continue
    70  		}
    71  		u := &UploadType{
    72  			Ext:  strings.ToLower(fields[0]),
    73  			MIME: strings.ToLower(fields[1]),
    74  		}
    75  		if len(fields) > 2 {
    76  			u.Thumb = fields[2]
    77  		}
    78  		uploads = append(uploads, u)
    79  	}
    80  	c.cachedUploads = uploads
    81  	return uploads
    82  }
    83  

View as plain text