mirror of
https://github.com/owncast/owncast.git
synced 2024-12-18 07:12:33 +03:00
Fix some pathing and caching issues with admin controller
This commit is contained in:
parent
a58a1f67d6
commit
01b3489287
1 changed files with 13 additions and 4 deletions
|
@ -2,6 +2,7 @@ package admin
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -14,13 +15,23 @@ import (
|
|||
|
||||
// ServeAdmin will return admin web assets.
|
||||
func ServeAdmin(w http.ResponseWriter, r *http.Request) {
|
||||
// If the ETags match then return a StatusNotModified
|
||||
if responseCode := middleware.ProcessEtags(w, r); responseCode != 0 {
|
||||
w.WriteHeader(responseCode)
|
||||
return
|
||||
}
|
||||
|
||||
adminFiles := static.GetAdmin()
|
||||
path := strings.TrimPrefix(r.URL.Path, "/")
|
||||
|
||||
// Determine if the requested path is a directory.
|
||||
// If so, append index.html to the request.
|
||||
path := strings.TrimPrefix(r.URL.Path, "/")
|
||||
if strings.HasSuffix(path, "/") {
|
||||
if info, err := fs.Stat(adminFiles, path); err == nil && info.IsDir() {
|
||||
path = filepath.Join(path, "index.html")
|
||||
} else if _, err := fs.Stat(adminFiles, path+"index.html"); err == nil {
|
||||
path = filepath.Join(path, "index.html")
|
||||
} else if err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
|
||||
f, err := adminFiles.Open(path)
|
||||
|
@ -30,7 +41,6 @@ func ServeAdmin(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
info, err := f.Stat()
|
||||
|
||||
if os.IsNotExist(err) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
|
@ -38,7 +48,6 @@ func ServeAdmin(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// Set a cache control max-age header
|
||||
middleware.SetCachingHeaders(w, r)
|
||||
|
||||
d, err := adminFiles.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
|
|
Loading…
Reference in a new issue