mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-01-06 07:32:08 +08:00
c747498b87
* allowing multiple newBase ips * generate * only bundle helpers * generate change
237 lines
6.4 KiB
Go
237 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: 6644,
|
|
modtime: 0,
|
|
compressed: `
|
|
H4sIAAAJbogA/7RZb2/bvBF/709xE7BaWlQ5SZtskOth3pP2QbHaCRJ3C2AYBmPRNlP9A0k7zQLnsw9H
|
|
UhIl2U8SYM2LNCLvjr/7w7vj1dkICkJytpBOv9PZEg6LLF3CAJ46AACcrpiQnHARwnTmq7UoFXNB+ZYt
|
|
6Dzn2ZZFtLadJYSlaqGzMzIjuiSbWF6IXMAAprN+p7PcpAvJshRYyiQjMfsvdT19aA3BIRSvQNJEg9+7
|
|
vgbZArSzII3pw3VxpJuShPryMad+QiXxDCy2BBcXvRImfsFgAM5oOP4+/Obog3bqN9qA0xUqheJCUEIV
|
|
S6h++4DCQ/XbQEQrBJXmQb4Ra5fTldc3npEbnipBLfAXN1dudYKWbQEHV0HPlmoDBoMBdLO7e7qQXQ/e
|
|
vQO3y/L5Iku3lAuWpaILLNUyPMspuBDUCWEAy4wnRM6ldPfsew2TRCJ/u0n2Ol1bJxL5S9ZJ6cOFCglt
|
|
oNK+XhnwirGGqSQKqz8Nuqcdbi8yHolwOvNRIx2ARYRNJt9COPaVJESNAT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