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:
45
utils/fs/exists.go
Normal file
45
utils/fs/exists.go
Normal 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)
|
||||
}
|
@@ -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
|
Reference in New Issue
Block a user