Updates
Former-commit-id: 8220f5660a75af69ee6358af3782416dae9aa185 [formerly 098749492c954879b5a01324076804e74947c780] [formerly 34f6dda3fafc72730b4e44d0c23ade6940bb90d4 [formerly 4b3ebca48c26220825e07a5f1f9c1718911532a4]] Former-commit-id: 722e71cd19b9ecceb627cc1e65572839bd2a55c8 [formerly 23d5ac81b9ff1f39b51cc042eb2ac12d2e5da6fc] Former-commit-id: c4e5ea0d6db7edcfdc3b551e0c43d1c77ef587c3
This commit is contained in:
46
assets.go
46
assets.go
@@ -1,46 +0,0 @@
|
||||
package filemanager
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"mime"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// assetsURL is the url where static assets are served.
|
||||
const assetsURL = "/_internal"
|
||||
|
||||
// Serve provides the needed assets for the front-end
|
||||
func serveAssets(c *requestContext, w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
// gets the filename to be used with Assets function
|
||||
filename := strings.TrimPrefix(r.URL.Path, assetsURL)
|
||||
|
||||
var file []byte
|
||||
var err error
|
||||
|
||||
switch {
|
||||
case strings.HasPrefix(filename, "/css"):
|
||||
filename = strings.Replace(filename, "/css/", "", 1)
|
||||
file, err = c.fm.assets.css.Bytes(filename)
|
||||
case strings.HasPrefix(filename, "/js"):
|
||||
filename = strings.Replace(filename, "/js/", "", 1)
|
||||
file, err = c.fm.assets.js.Bytes(filename)
|
||||
default:
|
||||
err = errors.New("not found")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return http.StatusNotFound, nil
|
||||
}
|
||||
|
||||
// Get the file extension and its mimetype
|
||||
extension := filepath.Ext(filename)
|
||||
mediatype := mime.TypeByExtension(extension)
|
||||
|
||||
// Write the header with the Content-Type and write the file
|
||||
// content to the buffer
|
||||
w.Header().Set("Content-Type", mediatype)
|
||||
w.Write(file)
|
||||
return 200, nil
|
||||
}
|
||||
Reference in New Issue
Block a user