mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
move some stuff
This commit is contained in:
parent
df888b604a
commit
5fce287cd2
30
file/info.go
30
file/info.go
@ -10,7 +10,7 @@ import (
|
||||
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/hacdias/caddy-filemanager/config"
|
||||
"github.com/hacdias/caddy-filemanager/utils"
|
||||
"github.com/hacdias/caddy-filemanager/utils/errors"
|
||||
)
|
||||
|
||||
// Info contains the information about a particular file or directory
|
||||
@ -41,7 +41,7 @@ func GetInfo(url *url.URL, c *config.Config, u *config.User) (*Info, int, error)
|
||||
|
||||
i.FileInfo, err = os.Stat(i.Path)
|
||||
if err != nil {
|
||||
return i, utils.ErrorToHTTPCode(err, false), err
|
||||
return i, errors.ErrorToHTTPCode(err, false), err
|
||||
}
|
||||
|
||||
return i, 0, nil
|
||||
@ -74,6 +74,32 @@ func (i Info) HumanModTime(format string) string {
|
||||
return i.ModTime().Format(format)
|
||||
}
|
||||
|
||||
// CanBeEdited checks if the extension of a file is supported by the editor
|
||||
func (i Info) CanBeEdited() bool {
|
||||
if i.Type == "text" {
|
||||
return true
|
||||
}
|
||||
|
||||
extensions := [...]string{
|
||||
"md", "markdown", "mdown", "mmark",
|
||||
"asciidoc", "adoc", "ad",
|
||||
"rst",
|
||||
".json", ".toml", ".yaml",
|
||||
".css", ".sass", ".scss",
|
||||
".js",
|
||||
".html",
|
||||
".txt",
|
||||
}
|
||||
|
||||
for _, extension := range extensions {
|
||||
if strings.HasSuffix(i.Name(), extension) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func simplifyMediaType(name string) string {
|
||||
if strings.HasPrefix(name, "video") {
|
||||
return "video"
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/hacdias/caddy-filemanager/utils"
|
||||
"github.com/hacdias/caddy-filemanager/utils/variables"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
@ -126,9 +126,9 @@ func rawToPretty(config interface{}, parent *Block) *Content {
|
||||
}
|
||||
|
||||
for name, element := range cnf {
|
||||
if utils.IsMap(element) {
|
||||
if variables.IsMap(element) {
|
||||
objects = append(objects, handleObjects(element, parent, name))
|
||||
} else if utils.IsSlice(element) {
|
||||
} else if variables.IsSlice(element) {
|
||||
arrays = append(arrays, handleArrays(element, parent, name))
|
||||
} else {
|
||||
if name == "title" && parent.Name == mainName {
|
||||
|
@ -1,10 +1,11 @@
|
||||
package file
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/hacdias/caddy-filemanager/file"
|
||||
"github.com/hacdias/caddy-filemanager/frontmatter"
|
||||
"github.com/spf13/hugo/parser"
|
||||
)
|
||||
@ -18,7 +19,7 @@ type Editor struct {
|
||||
}
|
||||
|
||||
// GetEditor gets the editor based on a FileInfo struct
|
||||
func (i *Info) GetEditor() (*Editor, error) {
|
||||
func GetEditor(i *file.Info) (*Editor, error) {
|
||||
// Create a new editor variable and set the mode
|
||||
editor := new(Editor)
|
||||
editor.Mode = strings.TrimPrefix(filepath.Ext(i.Name()), ".")
|
||||
@ -81,29 +82,3 @@ func (i *Info) GetEditor() (*Editor, error) {
|
||||
|
||||
return editor, nil
|
||||
}
|
||||
|
||||
// CanBeEdited checks if the extension of a file is supported by the editor
|
||||
func (i Info) CanBeEdited() bool {
|
||||
if i.Type == "text" {
|
||||
return true
|
||||
}
|
||||
|
||||
extensions := [...]string{
|
||||
"md", "markdown", "mdown", "mmark",
|
||||
"asciidoc", "adoc", "ad",
|
||||
"rst",
|
||||
".json", ".toml", ".yaml",
|
||||
".css", ".sass", ".scss",
|
||||
".js",
|
||||
".html",
|
||||
".txt",
|
||||
}
|
||||
|
||||
for _, extension := range extensions {
|
||||
if strings.HasSuffix(i.Name(), extension) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
@ -9,7 +9,7 @@ import (
|
||||
"github.com/hacdias/caddy-filemanager/config"
|
||||
"github.com/hacdias/caddy-filemanager/file"
|
||||
"github.com/hacdias/caddy-filemanager/page"
|
||||
"github.com/hacdias/caddy-filemanager/utils"
|
||||
"github.com/hacdias/caddy-filemanager/utils/errors"
|
||||
"github.com/mholt/caddy/caddyhttp/httpserver"
|
||||
)
|
||||
|
||||
@ -20,7 +20,7 @@ func ServeListing(w http.ResponseWriter, r *http.Request, c *config.Config, u *c
|
||||
// Loads the content of the directory
|
||||
listing, err := file.GetListing(u, i.VirtualPath, r.URL.Path)
|
||||
if err != nil {
|
||||
return utils.ErrorToHTTPCode(err, true), err
|
||||
return errors.ErrorToHTTPCode(err, true), err
|
||||
}
|
||||
|
||||
listing.Context = httpserver.Context{
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"github.com/hacdias/caddy-filemanager/config"
|
||||
"github.com/hacdias/caddy-filemanager/file"
|
||||
"github.com/hacdias/caddy-filemanager/page"
|
||||
"github.com/hacdias/caddy-filemanager/utils"
|
||||
"github.com/hacdias/caddy-filemanager/utils/errors"
|
||||
)
|
||||
|
||||
// ServeSingle serves a single file in an editor (if it is editable), shows the
|
||||
@ -14,7 +14,7 @@ import (
|
||||
func ServeSingle(w http.ResponseWriter, r *http.Request, c *config.Config, u *config.User, i *file.Info) (int, error) {
|
||||
err := i.Read()
|
||||
if err != nil {
|
||||
return utils.ErrorToHTTPCode(err, true), err
|
||||
return errors.ErrorToHTTPCode(err, true), err
|
||||
}
|
||||
|
||||
p := &page.Page{
|
||||
@ -29,7 +29,7 @@ func ServeSingle(w http.ResponseWriter, r *http.Request, c *config.Config, u *co
|
||||
}
|
||||
|
||||
if i.CanBeEdited() && u.AllowEdit {
|
||||
p.Data, err = i.GetEditor()
|
||||
p.Data, err = GetEditor(i)
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
|
||||
"github.com/hacdias/caddy-filemanager/assets"
|
||||
"github.com/hacdias/caddy-filemanager/config"
|
||||
"github.com/hacdias/caddy-filemanager/utils"
|
||||
"github.com/hacdias/caddy-filemanager/utils/variables"
|
||||
)
|
||||
|
||||
// Page contains the informations and functions needed to show the Page
|
||||
@ -81,7 +81,7 @@ func (p Page) PrintAsHTML(w http.ResponseWriter, templates ...string) (int, erro
|
||||
// Create the functions map, then the template, check for erros and
|
||||
// execute the template if there aren't errors
|
||||
functions := template.FuncMap{
|
||||
"Defined": utils.Defined,
|
||||
"Defined": variables.Defined,
|
||||
"CSS": func(s string) template.CSS {
|
||||
return template.CSS(s)
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
package utils
|
||||
package errors
|
||||
|
||||
import (
|
||||
"net/http"
|
@ -1,4 +1,4 @@
|
||||
package utils
|
||||
package variables
|
||||
|
||||
import "reflect"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package utils
|
||||
package variables
|
||||
|
||||
import (
|
||||
"errors"
|
@ -1,4 +1,4 @@
|
||||
package utils
|
||||
package variables
|
||||
|
||||
import "testing"
|
||||
|
Loading…
Reference in New Issue
Block a user