Amber is replaced with Jade.
This commit is contained in:
parent
b2a5e90245
commit
e529bfa353
@ -16,10 +16,10 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"time"
|
"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
|
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 {
|
func NewUploadHandlers(conf *configuration.Configuration, lErr, lUp, lDown *logging.Logger, uploadDirSize *int64) *UploadHandlers {
|
||||||
compiledTemplates = amber.MustCompileDir(conf.WebDir+"/templates",
|
compileTemplates(path.Join(conf.WebDir, "templates"), lErr)
|
||||||
amber.DefaultDirOptions, defaultAmberOptions)
|
|
||||||
|
|
||||||
return &UploadHandlers{
|
return &UploadHandlers{
|
||||||
conf: conf,
|
conf: conf,
|
||||||
@ -160,6 +159,11 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.WriteHeader(http.StatusFound)
|
w.WriteHeader(http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scheme := r.Header.Get("X-Forwarded-Proto")
|
||||||
|
if scheme == "" {
|
||||||
|
scheme = "http"
|
||||||
|
}
|
||||||
|
|
||||||
downloadURL := path.Join("/f", fSaltedHash, fHandler.Filename)
|
downloadURL := path.Join("/f", fSaltedHash, fHandler.Filename)
|
||||||
|
|
||||||
if err := compiledTemplates["uploaded"].Execute(w, &UploadedData{
|
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)
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user