mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-01-06 07:32:08 +08:00
238 lines
6.4 KiB
Go
238 lines
6.4 KiB
Go
package js
|
|
|
|
import (
|
|
"bytes"
|
|
"compress/gzip"
|
|
"encoding/base64"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"os"
|
|
"path"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
type _escLocalFS struct{}
|
|
|
|
var _escLocal _escLocalFS
|
|
|
|
type _escStaticFS struct{}
|
|
|
|
var _escStatic _escStaticFS
|
|
|
|
type _escDirectory struct {
|
|
fs http.FileSystem
|
|
name string
|
|
}
|
|
|
|
type _escFile struct {
|
|
compressed string
|
|
size int64
|
|
modtime int64
|
|
local string
|
|
isDir bool
|
|
|
|
once sync.Once
|
|
data []byte
|
|
name string
|
|
}
|
|
|
|
func (_escLocalFS) Open(name string) (http.File, error) {
|
|
f, present := _escData[path.Clean(name)]
|
|
if !present {
|
|
return nil, os.ErrNotExist
|
|
}
|
|
return os.Open(f.local)
|
|
}
|
|
|
|
func (_escStaticFS) prepare(name string) (*_escFile, error) {
|
|
f, present := _escData[path.Clean(name)]
|
|
if !present {
|
|
return nil, os.ErrNotExist
|
|
}
|
|
var err error
|
|
f.once.Do(func() {
|
|
f.name = path.Base(name)
|
|
if f.size == 0 {
|
|
return
|
|
}
|
|
var gr *gzip.Reader
|
|
b64 := base64.NewDecoder(base64.StdEncoding, bytes.NewBufferString(f.compressed))
|
|
gr, err = gzip.NewReader(b64)
|
|
if err != nil {
|
|
return
|
|
}
|
|
f.data, err = ioutil.ReadAll(gr)
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return f, nil
|
|
}
|
|
|
|
func (fs _escStaticFS) Open(name string) (http.File, error) {
|
|
f, err := fs.prepare(name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return f.File()
|
|
}
|
|
|
|
func (dir _escDirectory) Open(name string) (http.File, error) {
|
|
return dir.fs.Open(dir.name + name)
|
|
}
|
|
|
|
func (f *_escFile) File() (http.File, error) {
|
|
type httpFile struct {
|
|
*bytes.Reader
|
|
*_escFile
|
|
}
|
|
return &httpFile{
|
|
Reader: bytes.NewReader(f.data),
|
|
_escFile: f,
|
|
}, nil
|
|
}
|
|
|
|
func (f *_escFile) Close() error {
|
|
return nil
|
|
}
|
|
|
|
func (f *_escFile) Readdir(count int) ([]os.FileInfo, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (f *_escFile) Stat() (os.FileInfo, error) {
|
|
return f, nil
|
|
}
|
|
|
|
func (f *_escFile) Name() string {
|
|
return f.name
|
|
}
|
|
|
|
func (f *_escFile) Size() int64 {
|
|
return f.size
|
|
}
|
|
|
|
func (f *_escFile) Mode() os.FileMode {
|
|
return 0
|
|
}
|
|
|
|
func (f *_escFile) ModTime() time.Time {
|
|
return time.Unix(f.modtime, 0)
|
|
}
|
|
|
|
func (f *_escFile) IsDir() bool {
|
|
return f.isDir
|
|
}
|
|
|
|
func (f *_escFile) Sys() interface{} {
|
|
return f
|
|
}
|
|
|
|
// FS returns a http.Filesystem for the embedded assets. If useLocal is true,
|
|
// the filesystem's contents are instead used.
|
|
func FS(useLocal bool) http.FileSystem {
|
|
if useLocal {
|
|
return _escLocal
|
|
}
|
|
return _escStatic
|
|
}
|
|
|
|
// Dir returns a http.Filesystem for the embedded assets on a given prefix dir.
|
|
// If useLocal is true, the filesystem's contents are instead used.
|
|
func Dir(useLocal bool, name string) http.FileSystem {
|
|
if useLocal {
|
|
return _escDirectory{fs: _escLocal, name: name}
|
|
}
|
|
return _escDirectory{fs: _escStatic, name: name}
|
|
}
|
|
|
|
// FSByte returns the named file from the embedded assets. If useLocal is
|
|
// true, the filesystem's contents are instead used.
|
|
func FSByte(useLocal bool, name string) ([]byte, error) {
|
|
if useLocal {
|
|
f, err := _escLocal.Open(name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
b, err := ioutil.ReadAll(f)
|
|
f.Close()
|
|
return b, err
|
|
}
|
|
f, err := _escStatic.prepare(name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return f.data, nil
|
|
}
|
|
|
|
// FSMustByte is the same as FSByte, but panics if name is not present.
|
|
func FSMustByte(useLocal bool, name string) []byte {
|
|
b, err := FSByte(useLocal, name)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return b
|
|
}
|
|
|
|
// FSString is the string version of FSByte.
|
|
func FSString(useLocal bool, name string) (string, error) {
|
|
b, err := FSByte(useLocal, name)
|
|
return string(b), err
|
|
}
|
|
|
|
// FSMustString is the string version of FSMustByte.
|
|
func FSMustString(useLocal bool, name string) string {
|
|
return string(FSMustByte(useLocal, name))
|
|
}
|
|
|
|
var _escData = map[string]*_escFile{
|
|
|
|
"/helpers.js": {
|
|
local: "js/helpers.js",
|
|
size: 6729,
|
|
modtime: 0,
|
|
compressed: `
|
|
H4sIAAAJbogA/7RZfW/bvBH/35/iJmC1tKhykrbZINfDvCftg2K1WyTuFsAwDEaibbZ6A0k7zQLnsw9H
|
|
UhIl2U8SYO0faUTey+9eeDxenK2gICRnkXSGvd6OcIjybAUjeOgBAHC6ZkJywkUI84Wv1uJMLAXlOxbR
|
|
ZcHzHYtpYztPCcvUQm9vZMZ0RbaJvBSFgBHMF8Neb7XNIsnyDFjGJCMJ+y91Pa20geAYimcgaaPB7/1Q
|
|
g+wA2luQpvTuqlTpZiSlvrwvqJ9SSTwDi63AxUWvgolfMBqBMxlPv40/O1rRXv1EH3C6RqNQXAhKqGIJ
|
|
1U8fUHiofhqI6IWgtjwotmLjcrr2hiYycsszJagD/vL6q1tr0LIt4OAq6PlKbcBoNIJ+fvudRrLvwatX
|
|
4PZZsYzybEe5YHkm+sAyLcOzgoILQZMQRrDKeUrkUkr3wL7Xckksipe75GDQtXdiUTzlnYzeXaqU0A6q
|
|
/OtVCa8YG5gqorD+1aB72ON2lPNYhPOFjxbpBCwzbDb7HMKpryQhakzQ+WLfBFXwPKJCXBK+Fm7qm6S1
|
|
nT0YoGeBkm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