Jade can work with embed FS, so we do that.
This commit is contained in:
parent
94437e3bab
commit
381a0dcc98
@ -6,11 +6,13 @@ import (
|
|||||||
"dwelling-upload/pkg/logging"
|
"dwelling-upload/pkg/logging"
|
||||||
"dwelling-upload/pkg/server"
|
"dwelling-upload/pkg/server"
|
||||||
"dwelling-upload/pkg/utils"
|
"dwelling-upload/pkg/utils"
|
||||||
|
"embed"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -19,10 +21,14 @@ import (
|
|||||||
"github.com/Joker/jade"
|
"github.com/Joker/jade"
|
||||||
)
|
)
|
||||||
|
|
||||||
//var defaultAmberOptions = amber.Options{PrettyPrint: false, LineNumbers: false}
|
|
||||||
|
|
||||||
var compiledTemplates map[string]*template.Template
|
var compiledTemplates map[string]*template.Template
|
||||||
|
|
||||||
|
//go:embed web/assets
|
||||||
|
var assetsDir embed.FS
|
||||||
|
|
||||||
|
//go:embed web/templates
|
||||||
|
var templatesDir embed.FS
|
||||||
|
|
||||||
type NotFoundData struct {
|
type NotFoundData struct {
|
||||||
MainSite string
|
MainSite string
|
||||||
}
|
}
|
||||||
@ -64,6 +70,11 @@ func NewUploadHandlers(conf *configuration.Configuration, lErr, lUp, lDown *logg
|
|||||||
uploadDirSize: uploadDirSize}
|
uploadDirSize: uploadDirSize}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *UploadHandlers) AssetsFS() http.FileSystem {
|
||||||
|
f, _ := fs.Sub(assetsDir, "web/assets")
|
||||||
|
return http.FS(f)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *UploadHandlers) Index(w http.ResponseWriter, r *http.Request) {
|
func (h *UploadHandlers) Index(w http.ResponseWriter, r *http.Request) {
|
||||||
var storCapacity int64 = h.conf.Uploads.Limits.Storage << 20
|
var storCapacity int64 = h.conf.Uploads.Limits.Storage << 20
|
||||||
var fMaxSize int64 = h.conf.Uploads.Limits.FileSize << 20
|
var fMaxSize int64 = h.conf.Uploads.Limits.FileSize << 20
|
||||||
@ -216,7 +227,10 @@ func (h *UploadHandlers) NotFound(w http.ResponseWriter, r *http.Request) {
|
|||||||
func compileTemplates(dir string, lErr *logging.Logger) {
|
func compileTemplates(dir string, lErr *logging.Logger) {
|
||||||
compiledTemplates = make(map[string]*template.Template)
|
compiledTemplates = make(map[string]*template.Template)
|
||||||
|
|
||||||
indexStr, err := jade.ParseFile(path.Join(dir, "index.jade"))
|
t, _ := fs.Sub(templatesDir, "web/templates")
|
||||||
|
templatesFS := http.FS(t)
|
||||||
|
|
||||||
|
indexStr, err := jade.ParseFileFromFileSystem("index.jade", templatesFS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lErr.Fatalln(err)
|
lErr.Fatalln(err)
|
||||||
}
|
}
|
||||||
@ -228,7 +242,7 @@ func compileTemplates(dir string, lErr *logging.Logger) {
|
|||||||
|
|
||||||
compiledTemplates["index"] = indexTpl
|
compiledTemplates["index"] = indexTpl
|
||||||
|
|
||||||
uploadedStr, err := jade.ParseFile(path.Join(dir, "uploaded.jade"))
|
uploadedStr, err := jade.ParseFileFromFileSystem("uploaded.jade", templatesFS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lErr.Fatalln(err)
|
lErr.Fatalln(err)
|
||||||
}
|
}
|
||||||
@ -240,7 +254,7 @@ func compileTemplates(dir string, lErr *logging.Logger) {
|
|||||||
|
|
||||||
compiledTemplates["uploaded"] = uploadedTpl
|
compiledTemplates["uploaded"] = uploadedTpl
|
||||||
|
|
||||||
notfoundStr, err := jade.ParseFile(path.Join(dir, "404.jade"))
|
notfoundStr, err := jade.ParseFileFromFileSystem("404.jade", templatesFS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lErr.Fatalln(err)
|
lErr.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user