1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

feat: brotli precompressed assets (resolve #284)

This commit is contained in:
Ferdinand Mütsch
2021-12-20 14:51:05 +01:00
parent aebfdc535d
commit 374e578a7c
11 changed files with 72 additions and 308 deletions

45
utils/fs/exists.go Normal file
View File

@@ -0,0 +1,45 @@
package fs
import (
"io/fs"
"net/http"
"strings"
)
type ExistsFS struct {
Fs fs.FS
}
func (efs ExistsFS) Exists(name string) bool {
_, err := fs.Stat(efs.Fs, name)
return err == nil
}
func (efs ExistsFS) Open(name string) (fs.File, error) {
return efs.Fs.Open(name)
}
// ---
type ExistsHttpFS struct {
Fs ExistsFS
httpFs http.FileSystem
}
func NewExistsHttpFs(fs ExistsFS) ExistsHttpFS {
return ExistsHttpFS{
Fs: fs,
httpFs: http.FS(fs),
}
}
func (ehfs ExistsHttpFS) Exists(name string) bool {
if strings.HasPrefix(name, "/") {
name = name[1:]
}
return ehfs.Fs.Exists(name)
}
func (ehfs ExistsHttpFS) Open(name string) (http.File, error) {
return ehfs.httpFs.Open(name)
}

View File

@@ -1,17 +1,17 @@
package utils
package fs
import (
"net/http"
"io/fs"
"path/filepath"
)
// https://www.alexedwards.net/blog/disable-http-fileserver-directory-listings
type NeuteredFileSystem struct {
Fs http.FileSystem
Fs fs.FS
}
func (nfs NeuteredFileSystem) Open(path string) (http.File, error) {
func (nfs NeuteredFileSystem) Open(path string) (fs.File, error) {
f, err := nfs.Fs.Open(path)
if err != nil {
return nil, err