rebuilding js
Former-commit-id: 027e2f6546614d28750e437b9a3545cb95235d9d [formerly 6dbfe621a5774304295c17f216b5c96beaaaa95a] [formerly d44822f30d9a3649b20daa7a3cdbf86c87e63c99 [formerly 325855234967d92bf42b77b17fd8affdcc7f1392]] Former-commit-id: 7f34ddc1b32076c6ad2c2a4374b170b7f5d84000 [formerly aaafd299a933d25ebcb5fdebe1b00cb9e8309d7a] Former-commit-id: 7bb183c165ba2c9711ba1c04e3af6e2048245ded
This commit is contained in:
43
assets.go
Normal file
43
assets.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package filemanager
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"mime"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 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