97 lines
2.0 KiB
Go
Executable File
97 lines
2.0 KiB
Go
Executable File
package config
|
|
|
|
import (
|
|
"bytes"
|
|
_ "embed"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"time"
|
|
|
|
"gitea.inhome.blapointe.com/local/args"
|
|
)
|
|
|
|
var (
|
|
Root string
|
|
Port string
|
|
Head string
|
|
Foot string
|
|
OAuthServer string
|
|
VersionInterval time.Duration
|
|
ReadOnly bool
|
|
MaxSizeMB int
|
|
)
|
|
|
|
func init() {
|
|
Refresh()
|
|
}
|
|
|
|
func Refresh() {
|
|
if strings.Contains(fmt.Sprint(os.Args), " -test") {
|
|
return
|
|
}
|
|
|
|
as := args.NewArgSet()
|
|
as.Append(args.STRING, "root", "root dir path", "./public")
|
|
as.Append(args.STRING, "port", "port to listen on", "49909")
|
|
as.Append(args.STRING, "wrap", "file with http header/footer", "")
|
|
as.Append(args.STRING, "oauth", "oauth URL", "")
|
|
as.Append(args.DURATION, "version", "duration to mark versions", "0s")
|
|
as.Append(args.BOOL, "ro", "read-only mode", false)
|
|
as.Append(args.INT, "max-v-size", "max size in mb for versioning", 2)
|
|
if err := as.Parse(); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
wrap := as.GetString("wrap")
|
|
var b []byte
|
|
if len(wrap) > 0 {
|
|
log.Printf("reading %v (%T)", wrap, wrap)
|
|
var err error
|
|
b, err = ioutil.ReadFile(wrap)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
} else {
|
|
b = []byte(defaultWrapper)
|
|
}
|
|
bs := bytes.Split(b, []byte("{{{}}}"))
|
|
if len(bs) != 2 {
|
|
panic(len(bs))
|
|
}
|
|
|
|
Root = strings.TrimSuffix(as.GetString("root"), "/")
|
|
Root, _ = filepath.Abs(Root)
|
|
Port = ":" + strings.TrimPrefix(as.GetString("port"), ":")
|
|
Head = string(bs[0])
|
|
Foot = string(bs[1])
|
|
OAuthServer = as.GetString("oauth")
|
|
VersionInterval = as.GetDuration("version")
|
|
ReadOnly = as.GetBool("ro")
|
|
MaxSizeMB = as.GetInt("max-v-size")
|
|
}
|
|
|
|
//go:embed water.css.txt
|
|
var waterCSS string
|
|
|
|
var defaultWrapper = `
|
|
<html>
|
|
<header>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<!-- https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/dark.min.css -->
|
|
<style>
|
|
` + waterCSS + `
|
|
/*# sourceMappingURL=dark-legacy.standalone.min.css.map */
|
|
</style>
|
|
</header>
|
|
<body>
|
|
{{{}}}
|
|
</body>
|
|
<footer>
|
|
</footer>
|
|
</html>
|
|
`
|