cleaned up old config properties and added an external resource directory and a user agreement resource name
This commit is contained in:
+10
-12
@@ -59,16 +59,13 @@ func (*AmCLI) Version() string {
|
|||||||
// AmConfig holds the configuration of the application as read from YAML.
|
// AmConfig holds the configuration of the application as read from YAML.
|
||||||
type AmConfig struct {
|
type AmConfig struct {
|
||||||
Site struct {
|
Site struct {
|
||||||
BaseURL string `yaml:"baseURL"`
|
BaseURL string `yaml:"baseURL"`
|
||||||
Title string `yaml:"title"`
|
Title string `yaml:"title"`
|
||||||
TopRefresh int `yaml:"topRefresh"`
|
TopRefresh int `yaml:"topRefresh"`
|
||||||
LoginCookieName string `yaml:"loginCookieName"`
|
LoginCookieName string `yaml:"loginCookieName"`
|
||||||
LoginCookieAge int `yaml:"loginCookieAge"`
|
LoginCookieAge int `yaml:"loginCookieAge"`
|
||||||
SessionExpire string `yaml:"sessionExpire"`
|
SessionExpire string `yaml:"sessionExpire"`
|
||||||
UserAgreement struct {
|
UserAgreementResource string `yaml:"userAgreementResource"`
|
||||||
Title string `yaml:"title"`
|
|
||||||
Text string `yaml:"text"`
|
|
||||||
} `yaml:"userAgreement"`
|
|
||||||
} `yaml:"site"`
|
} `yaml:"site"`
|
||||||
Database struct {
|
Database struct {
|
||||||
Driver string `yaml:"driver"`
|
Driver string `yaml:"driver"`
|
||||||
@@ -98,8 +95,9 @@ type AmConfig struct {
|
|||||||
VeniceCompatibleImageURLs bool `yaml:"veniceCompatibleImageURLs"`
|
VeniceCompatibleImageURLs bool `yaml:"veniceCompatibleImageURLs"`
|
||||||
} `yaml:"rendering"`
|
} `yaml:"rendering"`
|
||||||
Resources struct {
|
Resources struct {
|
||||||
ViewTemplateDir string `yaml:"viewTemplateDir"`
|
ViewTemplateDir string `yaml:"viewTemplateDir"`
|
||||||
ExternalContentPath string `yaml:"externalContentPath"`
|
ExternalContentPath string `yaml:"externalContentPath"`
|
||||||
|
ExternalResourcePath string `yaml:"externalResourcePath"`
|
||||||
} `yaml:"resources"`
|
} `yaml:"resources"`
|
||||||
Posting struct {
|
Posting struct {
|
||||||
ExternalDictionary string `yaml:"externalDictionary"`
|
ExternalDictionary string `yaml:"externalDictionary"`
|
||||||
|
|||||||
+2
-4
@@ -13,10 +13,7 @@ site:
|
|||||||
loginCookieName: AmsterdamAuth
|
loginCookieName: AmsterdamAuth
|
||||||
loginCookieAge: 365
|
loginCookieAge: 365
|
||||||
sessionExpire: "3h"
|
sessionExpire: "3h"
|
||||||
userAgreement:
|
userAgreementResource: "useragreement.html"
|
||||||
title: "Amsterdam User Agreement"
|
|
||||||
text: >
|
|
||||||
Text of this agreement is TBD.
|
|
||||||
database:
|
database:
|
||||||
driver: "mysql"
|
driver: "mysql"
|
||||||
dsn: "amsdb:x00yes2k@tcp(localhost)/amsterdam?parseTime=true&loc=UTC"
|
dsn: "amsdb:x00yes2k@tcp(localhost)/amsterdam?parseTime=true&loc=UTC"
|
||||||
@@ -46,6 +43,7 @@ rendering:
|
|||||||
resources:
|
resources:
|
||||||
viewTemplateDir: ""
|
viewTemplateDir: ""
|
||||||
externalContentPath: ""
|
externalContentPath: ""
|
||||||
|
externalResourcePath: ""
|
||||||
posting:
|
posting:
|
||||||
externalDictionary: ""
|
externalDictionary: ""
|
||||||
uploads:
|
uploads:
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.erbosoft.com/amy/amsterdam/config"
|
||||||
"git.erbosoft.com/amy/amsterdam/database"
|
"git.erbosoft.com/amy/amsterdam/database"
|
||||||
"git.erbosoft.com/amy/amsterdam/email"
|
"git.erbosoft.com/amy/amsterdam/email"
|
||||||
"git.erbosoft.com/amy/amsterdam/ui"
|
"git.erbosoft.com/amy/amsterdam/ui"
|
||||||
@@ -316,7 +317,7 @@ func NewAccountUserAgreement(ctxt ui.AmContext) (string, any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load the user agreement from the resources.
|
// Load the user agreement from the resources.
|
||||||
agreementTitle, agreementBody, err := ui.AmLoadHTMLResource("useragreement.html")
|
agreementTitle, agreementBody, err := ui.AmLoadHTMLResource(config.GlobalConfig.Site.UserAgreementResource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "error", err
|
return "error", err
|
||||||
}
|
}
|
||||||
|
|||||||
+43
-4
@@ -16,10 +16,13 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.erbosoft.com/amy/amsterdam/config"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"golang.org/x/net/html"
|
"golang.org/x/net/html"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,8 +32,27 @@ var static_data embed.FS
|
|||||||
//go:embed resources/*
|
//go:embed resources/*
|
||||||
var static_resources embed.FS
|
var static_resources embed.FS
|
||||||
|
|
||||||
|
// external_resources is the link to the external resource path.
|
||||||
|
var external_resources fs.FS = nil
|
||||||
|
|
||||||
func setupResources() {
|
func setupResources() {
|
||||||
// do nothing yet
|
// Open the external resource path.
|
||||||
|
if config.GlobalConfig.Resources.ExternalResourcePath != "" {
|
||||||
|
finfo, err := os.Stat(config.GlobalConfig.Resources.ExternalResourcePath)
|
||||||
|
if err == nil {
|
||||||
|
if finfo.IsDir() {
|
||||||
|
root, err := os.OpenRoot(config.GlobalConfig.Resources.ExternalResourcePath)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
external_resources = root.FS()
|
||||||
|
} else {
|
||||||
|
log.Errorf("external resource path \"%s\" is not a directory, ignored", config.GlobalConfig.Resources.ExternalResourcePath)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Errorf("external resource path \"%s\" is not valid, ignored (%v)", config.GlobalConfig.Resources.ExternalResourcePath, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AmStaticFileHandler returns a handler for the files in the static embedded filesystem.
|
// AmStaticFileHandler returns a handler for the files in the static embedded filesystem.
|
||||||
@@ -95,9 +117,26 @@ func breakUpHTML(r io.Reader) (string, string, error) {
|
|||||||
|
|
||||||
// AmLoadHTMLResource loads an HTML resource and splits it into title and body.
|
// AmLoadHTMLResource loads an HTML resource and splits it into title and body.
|
||||||
func AmLoadHTMLResource(resourceName string) (string, string, error) {
|
func AmLoadHTMLResource(resourceName string) (string, string, error) {
|
||||||
f, err := static_resources.Open(filepath.Join("resources", resourceName))
|
var f fs.File = nil
|
||||||
if err != nil {
|
var err error
|
||||||
return "", "", err
|
if external_resources != nil {
|
||||||
|
f, err = external_resources.Open(resourceName)
|
||||||
|
if err != nil {
|
||||||
|
f = nil
|
||||||
|
pe := err.(*fs.PathError)
|
||||||
|
if pe.Err == os.ErrInvalid || pe.Err == os.ErrNotExist {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if f == nil {
|
||||||
|
f, err = static_resources.Open(filepath.Join("resources", resourceName))
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
title, body, err := breakUpHTML(f)
|
title, body, err := breakUpHTML(f)
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|||||||
Reference in New Issue
Block a user