Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix build error with bindata tag
  • Loading branch information
lunny committed May 29, 2021
commit c2ff37b19b813d6ecbf788fd2328ed4846751db3
10 changes: 5 additions & 5 deletions modules/public/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
"time"
)

// ServeContent serve http content
func ServeContent(w http.ResponseWriter, req *http.Request, fi os.FileInfo, modtime time.Time, content io.ReadSeeker) {
http.ServeContent(w, req, fi.Name(), modtime, content)
}

func fileSystem(dir string) http.FileSystem {
return http.Dir(dir)
}

// serveContent serve http content
func serveContent(w http.ResponseWriter, req *http.Request, fi os.FileInfo, modtime time.Time, content io.ReadSeeker) {
http.ServeContent(w, req, fi.Name(), modtime, content)
}
13 changes: 5 additions & 8 deletions modules/public/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ import (

// Options represents the available options to configure the handler.
type Options struct {
Directory string
IndexFile string
SkipLogging bool
FileSystem http.FileSystem
Prefix string
Directory string
Prefix string
}

// Assets implements the static handler for serving custom or original assets.
func Assets(opts *Options) func(http.Handler) http.Handler {
// AssetsHandler implements the static handler for serving custom or original assets.
func AssetsHandler(opts *Options) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
var custPath = filepath.Join(setting.CustomPath, "public")
if !filepath.IsAbs(custPath) {
Expand Down Expand Up @@ -109,6 +106,6 @@ func (opts *Options) handle(w http.ResponseWriter, req *http.Request, fs http.Fi
return true
}

ServeContent(w, req, fi, fi.ModTime(), f)
serveContent(w, req, fi, fi.ModTime(), f)
return true
}
35 changes: 2 additions & 33 deletions modules/public/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,8 @@ func fileSystem(dir string) http.FileSystem {
return Assets
}

func Asset(name string) ([]byte, error) {
f, err := Assets.Open("/" + name)
if err != nil {
return nil, err
}
defer f.Close()
return ioutil.ReadAll(f)
}

func AssetNames() []string {
realFS := Assets.(vfsgen۰FS)
var results = make([]string, 0, len(realFS))
for k := range realFS {
results = append(results, k[1:])
}
return results
}

func AssetIsDir(name string) (bool, error) {
if f, err := Assets.Open("/" + name); err != nil {
return false, err
} else {
defer f.Close()
if fi, err := f.Stat(); err != nil {
return false, err
} else {
return fi.IsDir(), nil
}
}
}

// ServeContent serve http content
func ServeContent(w http.ResponseWriter, req *http.Request, fi os.FileInfo, modtime time.Time, content io.ReadSeeker) {
// serveContent serve http content
func serveContent(w http.ResponseWriter, req *http.Request, fi os.FileInfo, modtime time.Time, content io.ReadSeeker) {
encodings := parseAcceptEncoding(req.Header.Get("Accept-Encoding"))
if encodings["gzip"] {
if cf, ok := fi.(*vfsgen۰CompressedFileInfo); ok {
Expand Down
7 changes: 3 additions & 4 deletions routers/routes/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ func InstallRoutes() *web.Route {
r.Use(installRecovery())
r.Use(routers.InstallInit)

r.Route("/assets/*", "GET, HEAD", corsHandler, public.Assets(&public.Options{
Directory: path.Join(setting.StaticRootPath, "public"),
SkipLogging: setting.DisableRouterLog,
Prefix: "/assets",
r.Route("/assets/*", "GET, HEAD", corsHandler, public.AssetsHandler(&public.Options{
Directory: path.Join(setting.StaticRootPath, "public"),
Prefix: "/assets",
}))

r.Get("/", routers.Install)
Expand Down
7 changes: 3 additions & 4 deletions routers/routes/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,9 @@ func WebRoutes() *web.Route {

routes.Use(Recovery())

routes.Route("/assets/*", "GET, HEAD", corsHandler, public.Assets(&public.Options{
Directory: path.Join(setting.StaticRootPath, "public"),
SkipLogging: setting.DisableRouterLog,
Prefix: "/assets",
routes.Route("/assets/*", "GET, HEAD", corsHandler, public.AssetsHandler(&public.Options{
Directory: path.Join(setting.StaticRootPath, "public"),
Prefix: "/assets",
}))

// We use r.Route here over r.Use because this prevents requests that are not for avatars having to go through this additional handler
Expand Down