loading user agreement from a "resource" now
This commit is contained in:
+26
-2
@@ -15,6 +15,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
@@ -68,7 +69,6 @@ type AmConfig struct {
|
||||
Title string `yaml:"title"`
|
||||
Text string `yaml:"text"`
|
||||
} `yaml:"userAgreement"`
|
||||
ExternalPath string `yaml:"externalPath"`
|
||||
} `yaml:"site"`
|
||||
Database struct {
|
||||
Driver string `yaml:"driver"`
|
||||
@@ -91,13 +91,16 @@ type AmConfig struct {
|
||||
Disclaimer string `yaml:"disclaimer"`
|
||||
} `yaml:"email"`
|
||||
Rendering struct {
|
||||
TemplateDir string `yaml:"templatedir"`
|
||||
CookieKey string `yaml:"cookiekey"`
|
||||
CountryList struct {
|
||||
Prioritize string `yaml:"prioritize"`
|
||||
} `yaml:"countryList"`
|
||||
VeniceCompatibleImageURLs bool `yaml:"veniceCompatibleImageURLs"`
|
||||
} `yaml:"rendering"`
|
||||
Resources struct {
|
||||
ViewTemplateDir string `yaml:"viewTemplateDir"`
|
||||
ExternalContentPath string `yaml:"externalContentPath"`
|
||||
} `yaml:"resources"`
|
||||
Posting struct {
|
||||
ExternalDictionary string `yaml:"externalDictionary"`
|
||||
Uploads struct {
|
||||
@@ -256,6 +259,27 @@ func parseDataSize(s string) (int32, error) {
|
||||
return int32(rc), nil
|
||||
}
|
||||
|
||||
// AmOpenExternalContentPath opens the "external content path" specified in the configuration as a root filesystem.
|
||||
func AmOpenExternalContentPath() (fs.FS, error) {
|
||||
if GlobalConfig.Resources.ExternalContentPath == "" {
|
||||
return nil, nil
|
||||
}
|
||||
finfo, err := os.Stat(GlobalConfig.Resources.ExternalContentPath)
|
||||
if err != nil {
|
||||
log.Errorf("external content path \"%s\" is not valid, ignored (%v)", GlobalConfig.Resources.ExternalContentPath, err)
|
||||
return nil, nil
|
||||
}
|
||||
if !finfo.IsDir() {
|
||||
log.Errorf("external content path \"%s\" is not a directory, ignored", GlobalConfig.Resources.ExternalContentPath)
|
||||
return nil, nil
|
||||
}
|
||||
root, err := os.OpenRoot(GlobalConfig.Resources.ExternalContentPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return root.FS(), nil
|
||||
}
|
||||
|
||||
// SetupConfig loads the command line arguments, loads the config file, and prepares GlobalConfig.
|
||||
func SetupConfig() {
|
||||
argparse.MustParse(&CommandLine)
|
||||
|
||||
+3
-2
@@ -17,7 +17,6 @@ site:
|
||||
title: "Amsterdam User Agreement"
|
||||
text: >
|
||||
Text of this agreement is TBD.
|
||||
externalPath: ""
|
||||
database:
|
||||
driver: "mysql"
|
||||
dsn: "amsdb:x00yes2k@tcp(localhost)/amsterdam?parseTime=true&loc=UTC"
|
||||
@@ -40,11 +39,13 @@ email:
|
||||
The Amsterdam Project is not responsible for the contents of this message
|
||||
Report abuses to: <abuse@example.com>
|
||||
rendering:
|
||||
templatedir: custom_templates
|
||||
cookiekey: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
|
||||
countryList:
|
||||
prioritize: US
|
||||
veniceCompatibleImageURLs: false
|
||||
resources:
|
||||
viewTemplateDir: ""
|
||||
externalContentPath: ""
|
||||
posting:
|
||||
externalDictionary: ""
|
||||
uploads:
|
||||
|
||||
Reference in New Issue
Block a user