1
0

Amber is replaced with Jade.

This commit is contained in:
Alexander Andreev 2022-02-08 04:23:38 +04:00
parent b2a5e90245
commit e529bfa353
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -16,10 +16,10 @@ import (
"path"
"time"
"github.com/eknkc/amber"
"github.com/Joker/jade"
)
var defaultAmberOptions = amber.Options{PrettyPrint: false, LineNumbers: false}
//var defaultAmberOptions = amber.Options{PrettyPrint: false, LineNumbers: false}
var compiledTemplates map[string]*template.Template
@ -54,8 +54,7 @@ type UploadHandlers struct {
}
func NewUploadHandlers(conf *configuration.Configuration, lErr, lUp, lDown *logging.Logger, uploadDirSize *int64) *UploadHandlers {
compiledTemplates = amber.MustCompileDir(conf.WebDir+"/templates",
amber.DefaultDirOptions, defaultAmberOptions)
compileTemplates(path.Join(conf.WebDir, "templates"), lErr)
return &UploadHandlers{
conf: conf,
@ -160,6 +159,11 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusFound)
}
scheme := r.Header.Get("X-Forwarded-Proto")
if scheme == "" {
scheme = "http"
}
downloadURL := path.Join("/f", fSaltedHash, fHandler.Filename)
if err := compiledTemplates["uploaded"].Execute(w, &UploadedData{
@ -208,3 +212,43 @@ func (h *UploadHandlers) NotFound(w http.ResponseWriter, r *http.Request) {
h.logErr.Fatalln("failed to execute 404 template:", err)
}
}
func compileTemplates(dir string, lErr *logging.Logger) {
compiledTemplates = make(map[string]*template.Template)
indexStr, err := jade.ParseFile(path.Join(dir, "index.jade"))
if err != nil {
lErr.Fatalln(err)
}
indexTpl, err := template.New("index").Parse(indexStr)
if err != nil {
lErr.Fatalln(err)
}
compiledTemplates["index"] = indexTpl
uploadedStr, err := jade.ParseFile(path.Join(dir, "uploaded.jade"))
if err != nil {
lErr.Fatalln(err)
}
uploadedTpl, err := template.New("uploaded").Parse(uploadedStr)
if err != nil {
lErr.Fatalln(err)
}
compiledTemplates["uploaded"] = uploadedTpl
notfoundStr, err := jade.ParseFile(path.Join(dir, "404.jade"))
if err != nil {
lErr.Fatalln(err)
}
notfoundTpl, err := template.New("404").Parse(notfoundStr)
if err != nil {
lErr.Fatalln(err)
}
compiledTemplates["404"] = notfoundTpl
}