diff --git a/bolt/config.go b/bolt/config.go index 2ecfc663..aeb646b9 100644 --- a/bolt/config.go +++ b/bolt/config.go @@ -2,7 +2,7 @@ package bolt import ( "github.com/asdine/storm" - fm "github.com/filebrowser/filebrowser" + fb "github.com/filebrowser/filebrowser" ) // ConfigStore is a configuration store. @@ -14,7 +14,7 @@ type ConfigStore struct { func (c ConfigStore) Get(name string, to interface{}) error { err := c.DB.Get("config", name, to) if err == storm.ErrNotFound { - return fm.ErrNotExist + return fb.ErrNotExist } return err diff --git a/bolt/share.go b/bolt/share.go index df4c5796..c908bd36 100644 --- a/bolt/share.go +++ b/bolt/share.go @@ -3,7 +3,7 @@ package bolt import ( "github.com/asdine/storm" "github.com/asdine/storm/q" - fm "github.com/filebrowser/filebrowser" + fb "github.com/filebrowser/filebrowser" ) // ShareStore is a shareable links store. @@ -12,55 +12,55 @@ type ShareStore struct { } // Get gets a Share Link from an hash. -func (s ShareStore) Get(hash string) (*fm.ShareLink, error) { - var v fm.ShareLink +func (s ShareStore) Get(hash string) (*fb.ShareLink, error) { + var v fb.ShareLink err := s.DB.One("Hash", hash, &v) if err == storm.ErrNotFound { - return nil, fm.ErrNotExist + return nil, fb.ErrNotExist } return &v, err } // GetPermanent gets the permanent link from a path. -func (s ShareStore) GetPermanent(path string) (*fm.ShareLink, error) { - var v fm.ShareLink +func (s ShareStore) GetPermanent(path string) (*fb.ShareLink, error) { + var v fb.ShareLink err := s.DB.Select(q.Eq("Path", path), q.Eq("Expires", false)).First(&v) if err == storm.ErrNotFound { - return nil, fm.ErrNotExist + return nil, fb.ErrNotExist } return &v, err } // GetByPath gets all the links for a specific path. -func (s ShareStore) GetByPath(hash string) ([]*fm.ShareLink, error) { - var v []*fm.ShareLink +func (s ShareStore) GetByPath(hash string) ([]*fb.ShareLink, error) { + var v []*fb.ShareLink err := s.DB.Find("Path", hash, &v) if err == storm.ErrNotFound { - return v, fm.ErrNotExist + return v, fb.ErrNotExist } return v, err } // Gets retrieves all the shareable links. -func (s ShareStore) Gets() ([]*fm.ShareLink, error) { - var v []*fm.ShareLink +func (s ShareStore) Gets() ([]*fb.ShareLink, error) { + var v []*fb.ShareLink err := s.DB.All(&v) if err == storm.ErrNotFound { - return v, fm.ErrNotExist + return v, fb.ErrNotExist } return v, err } // Save stores a Share Link on the database. -func (s ShareStore) Save(l *fm.ShareLink) error { +func (s ShareStore) Save(l *fb.ShareLink) error { return s.DB.Save(l) } // Delete deletes a Share Link from the database. func (s ShareStore) Delete(hash string) error { - return s.DB.DeleteStruct(&fm.ShareLink{Hash: hash}) + return s.DB.DeleteStruct(&fb.ShareLink{Hash: hash}) } diff --git a/http/auth.go b/http/auth.go index 0219d3df..341e299c 100644 --- a/http/auth.go +++ b/http/auth.go @@ -9,7 +9,7 @@ import ( "github.com/dgrijalva/jwt-go" "github.com/dgrijalva/jwt-go/request" - fm "github.com/filebrowser/filebrowser" + fb "github.com/filebrowser/filebrowser" ) const reCaptchaAPI = "/recaptcha/api/siteverify" @@ -50,7 +50,7 @@ func reCaptcha(host, secret, response string) (bool, error) { } // authHandler processes the authentication for the user. -func authHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func authHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { // NoAuth instances shouldn't call this method. if c.NoAuth { return 0, nil @@ -86,7 +86,7 @@ func authHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, er } // Checks if the password is correct. - if !fm.CheckPasswordHash(cred.Password, u.Password) { + if !fb.CheckPasswordHash(cred.Password, u.Password) { return http.StatusForbidden, nil } @@ -96,7 +96,7 @@ func authHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, er // renewAuthHandler is used when the front-end already has a JWT token // and is checking if it is up to date. If so, updates its info. -func renewAuthHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func renewAuthHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { ok, u := validateAuth(c, r) if !ok { return http.StatusForbidden, nil @@ -108,15 +108,15 @@ func renewAuthHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (in // claims is the JWT claims. type claims struct { - fm.User + fb.User jwt.StandardClaims } // printToken prints the final JWT token to the user. -func printToken(c *fm.Context, w http.ResponseWriter) (int, error) { +func printToken(c *fb.Context, w http.ResponseWriter) (int, error) { // Creates a copy of the user and removes it password // hash so it never arrives to the user. - u := fm.User{} + u := fb.User{} u = *c.User u.Password = "" @@ -165,7 +165,7 @@ func (e extractor) ExtractToken(r *http.Request) (string, error) { // validateAuth is used to validate the authentication and returns the // User if it is valid. -func validateAuth(c *fm.Context, r *http.Request) (bool, *fm.User) { +func validateAuth(c *fb.Context, r *http.Request) (bool, *fb.User) { if c.NoAuth { c.User = c.DefaultUser return true, c.User diff --git a/http/download.go b/http/download.go index b28542bd..26431d92 100644 --- a/http/download.go +++ b/http/download.go @@ -7,14 +7,14 @@ import ( "path/filepath" "strings" - fm "github.com/filebrowser/filebrowser" + fb "github.com/filebrowser/filebrowser" "github.com/hacdias/fileutils" "github.com/mholt/archiver" ) // downloadHandler creates an archive in one of the supported formats (zip, tar, // tar.gz or tar.bz2) and sends it to be downloaded. -func downloadHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func downloadHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { // If the file isn't a directory, serve it using http.ServeFile. We display it // inline if it is requested. if !c.File.IsDir { @@ -77,7 +77,7 @@ func downloadHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int return 0, err } -func downloadFileHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func downloadFileHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { file, err := os.Open(c.File.Path) defer file.Close() diff --git a/http/http.go b/http/http.go index 4a1fd4d8..4816660e 100644 --- a/http/http.go +++ b/http/http.go @@ -10,13 +10,13 @@ import ( "strings" "time" - fm "github.com/filebrowser/filebrowser" + fb "github.com/filebrowser/filebrowser" ) // Handler returns a function compatible with http.HandleFunc. -func Handler(m *fm.FileBrowser) http.Handler { +func Handler(m *fb.FileBrowser) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - code, err := serve(&fm.Context{ + code, err := serve(&fb.Context{ FileBrowser: m, User: nil, File: nil, @@ -37,9 +37,9 @@ func Handler(m *fm.FileBrowser) http.Handler { } // serve is the main entry point of this HTML application. -func serve(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func serve(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { // Checks if the URL contains the baseURL and strips it. Otherwise, it just - // returns a 404 fm.Error because we're not supposed to be here! + // returns a 404 fb.Error because we're not supposed to be here! p := strings.TrimPrefix(r.URL.Path, c.BaseURL) if len(p) >= len(r.URL.Path) && c.BaseURL != "" { @@ -93,7 +93,7 @@ func serve(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { } // staticHandler handles the static assets path. -func staticHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func staticHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { if r.URL.Path != "/static/manifest.json" { http.FileServer(c.Assets.HTTPBox()).ServeHTTP(w, r) return 0, nil @@ -103,7 +103,7 @@ func staticHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, } // apiHandler is the main entry point for the /api endpoint. -func apiHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func apiHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { if r.URL.Path == "/auth/get" { return authHandler(c, w, r) } @@ -139,7 +139,7 @@ func apiHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, err if c.Router == "checksum" || c.Router == "download" { var err error - c.File, err = fm.GetInfo(r.URL, c.FileBrowser, c.User) + c.File, err = fb.GetInfo(r.URL, c.FileBrowser, c.User) if err != nil { return ErrorToHTTP(err, false), err } @@ -173,11 +173,11 @@ func apiHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, err } // serveChecksum calculates the hash of a file. Supports MD5, SHA1, SHA256 and SHA512. -func checksumHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func checksumHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { query := r.URL.Query().Get("algo") val, err := c.File.Checksum(query) - if err == fm.ErrInvalidOption { + if err == fb.ErrInvalidOption { return http.StatusBadRequest, err } else if err != nil { return http.StatusInternalServerError, err @@ -205,7 +205,7 @@ func splitURL(path string) (string, string) { } // renderFile renders a file using a template with some needed variables. -func renderFile(c *fm.Context, w http.ResponseWriter, file string) (int, error) { +func renderFile(c *fb.Context, w http.ResponseWriter, file string) (int, error) { tpl := template.Must(template.New("file").Parse(c.Assets.MustString(file))) var contentType string @@ -225,7 +225,7 @@ func renderFile(c *fm.Context, w http.ResponseWriter, file string) (int, error) data := map[string]interface{}{ "BaseURL": c.RootURL(), "NoAuth": c.NoAuth, - "Version": fm.Version, + "Version": fb.Version, "CSS": template.CSS(c.CSS), "ReCaptcha": c.ReCaptchaKey != "" && c.ReCaptchaSecret != "", "ReCaptchaHost": c.ReCaptchaHost, @@ -246,9 +246,9 @@ func renderFile(c *fm.Context, w http.ResponseWriter, file string) (int, error) } // sharePage build the share page. -func sharePage(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func sharePage(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { s, err := c.Store.Share.Get(r.URL.Path) - if err == fm.ErrNotExist { + if err == fb.ErrNotExist { w.WriteHeader(http.StatusNotFound) return renderFile(c, w, "static/share/404.html") } @@ -271,7 +271,7 @@ func sharePage(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, erro return ErrorToHTTP(err, false), err } - c.File = &fm.File{ + c.File = &fb.File{ Path: s.Path, Name: info.Name(), ModTime: info.ModTime(), diff --git a/http/resource.go b/http/resource.go index 83687e82..ce405c9e 100644 --- a/http/resource.go +++ b/http/resource.go @@ -13,7 +13,7 @@ import ( "strings" "time" - fm "github.com/filebrowser/filebrowser" + fb "github.com/filebrowser/filebrowser" "github.com/hacdias/fileutils" ) @@ -27,7 +27,7 @@ func sanitizeURL(url string) string { return path } -func resourceHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func resourceHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { r.URL.Path = sanitizeURL(r.URL.Path) switch r.Method { @@ -62,9 +62,9 @@ func resourceHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int return http.StatusNotImplemented, nil } -func resourceGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func resourceGetHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { // Gets the information of the directory/file. - f, err := fm.GetInfo(r.URL, c.FileBrowser, c.User) + f, err := fb.GetInfo(r.URL, c.FileBrowser, c.User) if err != nil { return ErrorToHTTP(err, false), err } @@ -104,7 +104,7 @@ func resourceGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) ( return renderJSON(w, f) } -func listingHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func listingHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { f := c.File f.Kind = "listing" @@ -133,7 +133,7 @@ func listingHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, return renderJSON(w, f) } -func resourceDeleteHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func resourceDeleteHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { // Prevent the removal of the root directory. if r.URL.Path == "/" || !c.User.AllowEdit { return http.StatusForbidden, nil @@ -158,7 +158,7 @@ func resourceDeleteHandler(c *fm.Context, w http.ResponseWriter, r *http.Request return http.StatusOK, nil } -func resourcePostPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func resourcePostPutHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { if !c.User.AllowNew && r.Method == http.MethodPost { return http.StatusForbidden, nil } @@ -240,7 +240,7 @@ func resourcePostPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Reques return http.StatusOK, nil } -func resourcePublishSchedule(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func resourcePublishSchedule(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { publish := r.Header.Get("Publish") schedule := r.Header.Get("Schedule") @@ -271,7 +271,7 @@ func resourcePublishSchedule(c *fm.Context, w http.ResponseWriter, r *http.Reque return http.StatusOK, nil } -func resourcePublish(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func resourcePublish(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { path := filepath.Join(c.User.Scope, r.URL.Path) // Before save command handler. @@ -293,7 +293,7 @@ func resourcePublish(c *fm.Context, w http.ResponseWriter, r *http.Request) (int } // resourcePatchHandler is the entry point for resource handler. -func resourcePatchHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func resourcePatchHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { if !c.User.AllowEdit { return http.StatusForbidden, nil } diff --git a/http/settings.go b/http/settings.go index 9256bdb4..1663f5e4 100644 --- a/http/settings.go +++ b/http/settings.go @@ -6,7 +6,7 @@ import ( "net/http" "reflect" - fm "github.com/filebrowser/filebrowser" + fb "github.com/filebrowser/filebrowser" "github.com/mitchellh/mapstructure" ) @@ -28,7 +28,7 @@ type option struct { func parsePutSettingsRequest(r *http.Request) (*modifySettingsRequest, error) { // Checks if the request body is empty. if r.Body == nil { - return nil, fm.ErrEmptyRequest + return nil, fb.ErrEmptyRequest } // Parses the request body and checks if it's well formed. @@ -40,13 +40,13 @@ func parsePutSettingsRequest(r *http.Request) (*modifySettingsRequest, error) { // Checks if the request type is right. if mod.What != "settings" { - return nil, fm.ErrWrongDataType + return nil, fb.ErrWrongDataType } return mod, nil } -func settingsHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func settingsHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { if r.URL.Path != "" && r.URL.Path != "/" { return http.StatusNotFound, nil } @@ -67,7 +67,7 @@ type settingsGetRequest struct { StaticGen []option `json:"staticGen"` } -func settingsGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func settingsGetHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { if !c.User.Admin { return http.StatusForbidden, nil } @@ -97,7 +97,7 @@ func settingsGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) ( return renderJSON(w, result) } -func settingsPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func settingsPutHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { if !c.User.Admin { return http.StatusForbidden, nil } diff --git a/http/share.go b/http/share.go index df307a17..df78d24d 100644 --- a/http/share.go +++ b/http/share.go @@ -8,10 +8,10 @@ import ( "strings" "time" - fm "github.com/filebrowser/filebrowser" + fb "github.com/filebrowser/filebrowser" ) -func shareHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func shareHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { r.URL.Path = sanitizeURL(r.URL.Path) switch r.Method { @@ -26,10 +26,10 @@ func shareHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, e return http.StatusNotImplemented, nil } -func shareGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func shareGetHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { path := filepath.Join(c.User.Scope, r.URL.Path) s, err := c.Store.Share.GetByPath(path) - if err == fm.ErrNotExist { + if err == fb.ErrNotExist { return http.StatusNotFound, nil } @@ -51,10 +51,10 @@ func shareGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int return renderJSON(w, s) } -func sharePostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func sharePostHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { path := filepath.Join(c.User.Scope, r.URL.Path) - var s *fm.ShareLink + var s *fb.ShareLink expire := r.URL.Query().Get("expires") unit := r.URL.Query().Get("unit") @@ -67,14 +67,14 @@ func sharePostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (in } } - bytes, err := fm.GenerateRandomBytes(6) + bytes, err := fb.GenerateRandomBytes(6) if err != nil { return http.StatusInternalServerError, err } str := base64.URLEncoding.EncodeToString(bytes) - s = &fm.ShareLink{ + s = &fb.ShareLink{ Path: path, Hash: str, Expires: expire != "", @@ -108,9 +108,9 @@ func sharePostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (in return renderJSON(w, s) } -func shareDeleteHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func shareDeleteHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { s, err := c.Store.Share.Get(strings.TrimPrefix(r.URL.Path, "/")) - if err == fm.ErrNotExist { + if err == fb.ErrNotExist { return http.StatusNotFound, nil } diff --git a/http/users.go b/http/users.go index 526bd441..f924e304 100644 --- a/http/users.go +++ b/http/users.go @@ -9,7 +9,7 @@ import ( "strconv" "strings" - fm "github.com/filebrowser/filebrowser" + fb "github.com/filebrowser/filebrowser" ) type modifyRequest struct { @@ -19,12 +19,12 @@ type modifyRequest struct { type modifyUserRequest struct { modifyRequest - Data *fm.User `json:"data"` + Data *fb.User `json:"data"` } // usersHandler is the entry point of the users API. It's just a router // to send the request to its -func usersHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func usersHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { // If the user isn't admin and isn't making a PUT // request, then return forbidden. if !c.User.Admin && r.Method != http.MethodPut { @@ -47,7 +47,7 @@ func usersHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, e // getUserID returns the id from the user which is present // in the request url. If the url is invalid and doesn't -// contain a valid ID, it returns an fm.Error. +// contain a valid ID, it returns an fb.Error. func getUserID(r *http.Request) (int, error) { // Obtains the ID in string from the URL and converts // it into an integer. @@ -63,11 +63,11 @@ func getUserID(r *http.Request) (int, error) { // getUser returns the user which is present in the request // body. If the body is empty or the JSON is invalid, it -// returns an fm.Error. -func getUser(c *fm.Context, r *http.Request) (*fm.User, string, error) { +// returns an fb.Error. +func getUser(c *fb.Context, r *http.Request) (*fb.User, string, error) { // Checks if the request body is empty. if r.Body == nil { - return nil, "", fm.ErrEmptyRequest + return nil, "", fb.ErrEmptyRequest } // Parses the request body and checks if it's well formed. @@ -79,14 +79,14 @@ func getUser(c *fm.Context, r *http.Request) (*fm.User, string, error) { // Checks if the request type is right. if mod.What != "user" { - return nil, "", fm.ErrWrongDataType + return nil, "", fb.ErrWrongDataType } mod.Data.FileSystem = c.NewFS(mod.Data.Scope) return mod.Data, mod.Which, nil } -func usersGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func usersGetHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { // Request for the default user data. if r.URL.Path == "/base" { return renderJSON(w, c.DefaultUser) @@ -118,7 +118,7 @@ func usersGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int } u, err := c.Store.Users.Get(id, c.NewFS) - if err == fm.ErrExist { + if err == fb.ErrExist { return http.StatusNotFound, err } @@ -130,7 +130,7 @@ func usersGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int return renderJSON(w, u) } -func usersPostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func usersPostHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { if r.URL.Path != "/" { return http.StatusMethodNotAllowed, nil } @@ -142,22 +142,22 @@ func usersPostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (in // Checks if username isn't empty. if u.Username == "" { - return http.StatusBadRequest, fm.ErrEmptyUsername + return http.StatusBadRequest, fb.ErrEmptyUsername } // Checks if scope isn't empty. if u.Scope == "" { - return http.StatusBadRequest, fm.ErrEmptyScope + return http.StatusBadRequest, fb.ErrEmptyScope } // Checks if password isn't empty. if u.Password == "" { - return http.StatusBadRequest, fm.ErrEmptyPassword + return http.StatusBadRequest, fb.ErrEmptyPassword } // Initialize rules if they're not initialized. if u.Rules == nil { - u.Rules = []*fm.Rule{} + u.Rules = []*fb.Rule{} } // If the view mode is empty, initialize with the default one. @@ -181,17 +181,17 @@ func usersPostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (in } // Hashes the password. - pw, err := fm.HashPassword(u.Password) + pw, err := fb.HashPassword(u.Password) if err != nil { return http.StatusInternalServerError, err } u.Password = pw - u.ViewMode = fm.MosaicViewMode + u.ViewMode = fb.MosaicViewMode // Saves the user to the database. err = c.Store.Users.Save(u) - if err == fm.ErrExist { + if err == fb.ErrExist { return http.StatusConflict, err } @@ -228,7 +228,7 @@ func checkFS(path string) (int, error) { return 0, nil } -func usersDeleteHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func usersDeleteHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { if r.URL.Path == "/" { return http.StatusMethodNotAllowed, nil } @@ -240,8 +240,8 @@ func usersDeleteHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) ( // Deletes the user from the database. err = c.Store.Users.Delete(id) - if err == fm.ErrNotExist { - return http.StatusNotFound, fm.ErrNotExist + if err == fb.ErrNotExist { + return http.StatusNotFound, fb.ErrNotExist } if err != nil { @@ -251,7 +251,7 @@ func usersDeleteHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) ( return http.StatusOK, nil } -func usersPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func usersPutHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { // New users should be created on /api/users. if r.URL.Path == "/" { return http.StatusMethodNotAllowed, nil @@ -298,14 +298,14 @@ func usersPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int // Updates the Password. if which == "password" { if u.Password == "" { - return http.StatusBadRequest, fm.ErrEmptyPassword + return http.StatusBadRequest, fb.ErrEmptyPassword } if id == c.User.ID && c.User.LockPassword { return http.StatusForbidden, nil } - c.User.Password, err = fm.HashPassword(u.Password) + c.User.Password, err = fb.HashPassword(u.Password) if err != nil { return http.StatusInternalServerError, err } @@ -320,17 +320,17 @@ func usersPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int // If can only be all. if which != "all" { - return http.StatusBadRequest, fm.ErrInvalidUpdateField + return http.StatusBadRequest, fb.ErrInvalidUpdateField } // Checks if username isn't empty. if u.Username == "" { - return http.StatusBadRequest, fm.ErrEmptyUsername + return http.StatusBadRequest, fb.ErrEmptyUsername } // Checks if filesystem isn't empty. if u.Scope == "" { - return http.StatusBadRequest, fm.ErrEmptyScope + return http.StatusBadRequest, fb.ErrEmptyScope } // Checks if the scope exists. @@ -340,7 +340,7 @@ func usersPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int // Initialize rules if they're not initialized. if u.Rules == nil { - u.Rules = []*fm.Rule{} + u.Rules = []*fb.Rule{} } // Initialize commands if not initialized. @@ -350,7 +350,7 @@ func usersPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int // Gets the current saved user from the in-memory map. suser, err := c.Store.Users.Get(id, c.NewFS) - if err == fm.ErrNotExist { + if err == fb.ErrNotExist { return http.StatusNotFound, nil } @@ -362,7 +362,7 @@ func usersPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int // Changes the password if the request wants it. if u.Password != "" { - pw, err := fm.HashPassword(u.Password) + pw, err := fb.HashPassword(u.Password) if err != nil { return http.StatusInternalServerError, err } diff --git a/http/websockets.go b/http/websockets.go index 64bf92cc..27d63c26 100644 --- a/http/websockets.go +++ b/http/websockets.go @@ -12,7 +12,7 @@ import ( "strings" "time" - fm "github.com/filebrowser/filebrowser" + fb "github.com/filebrowser/filebrowser" "github.com/gorilla/websocket" ) @@ -27,8 +27,8 @@ var ( ) // command handles the requests for VCS related commands: git, svn and mercurial -func command(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { - // Upgrades the connection to a websocket and checks for fm.Errors. +func command(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { + // Upgrades the connection to a websocket and checks for fb.Errors. conn, err := upgrader.Upgrade(w, r, nil) if err != nil { return 0, err @@ -93,7 +93,7 @@ func command(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) cmd.Stderr = buff cmd.Stdout = buff - // Starts the command and checks for fm.Errors. + // Starts the command and checks for fb.Errors. err = cmd.Start() if err != nil { return http.StatusInternalServerError, err @@ -241,8 +241,8 @@ func parseSearch(value string) *searchOptions { } // search searches for a file or directory. -func search(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { - // Upgrades the connection to a websocket and checks for fm.Errors. +func search(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { + // Upgrades the connection to a websocket and checks for fb.Errors. conn, err := upgrader.Upgrade(w, r, nil) if err != nil { return 0, err diff --git a/staticgen/hugo.go b/staticgen/hugo.go index dd79938b..284e46e7 100644 --- a/staticgen/hugo.go +++ b/staticgen/hugo.go @@ -10,7 +10,7 @@ import ( "path/filepath" "strings" - fm "github.com/filebrowser/filebrowser" + fb "github.com/filebrowser/filebrowser" "github.com/hacdias/varutils" ) @@ -64,7 +64,7 @@ func (h Hugo) Name() string { } // Hook is the pre-api handler. -func (h Hugo) Hook(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func (h Hugo) Hook(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { // If we are not using HTTP Post, we shall return Method Not Allowed // since we are only working with this method. if r.Method != http.MethodPost { @@ -108,7 +108,7 @@ func (h Hugo) Hook(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, } // Publish publishes a post. -func (h Hugo) Publish(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func (h Hugo) Publish(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { filename := filepath.Join(c.User.Scope, r.URL.Path) // We only run undraft command if it is a file. @@ -125,7 +125,7 @@ func (h Hugo) Publish(c *fm.Context, w http.ResponseWriter, r *http.Request) (in } // Preview handles the preview path. -func (h *Hugo) Preview(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func (h *Hugo) Preview(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { // Get a new temporary path if there is none. if h.previewPath == "" { path, err := ioutil.TempDir("", "") diff --git a/staticgen/jekyll.go b/staticgen/jekyll.go index 00bdeb2c..c8902798 100644 --- a/staticgen/jekyll.go +++ b/staticgen/jekyll.go @@ -9,7 +9,7 @@ import ( "path/filepath" "strings" - fm "github.com/filebrowser/filebrowser" + fb "github.com/filebrowser/filebrowser" ) // Jekyll is the Jekyll static website generator. @@ -39,12 +39,12 @@ func (j Jekyll) SettingsPath() string { } // Hook is the pre-api handler. -func (j Jekyll) Hook(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func (j Jekyll) Hook(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { return 0, nil } // Publish publishes a post. -func (j Jekyll) Publish(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func (j Jekyll) Publish(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { filename := filepath.Join(c.User.Scope, r.URL.Path) // We only run undraft command if it is a file. @@ -59,7 +59,7 @@ func (j Jekyll) Publish(c *fm.Context, w http.ResponseWriter, r *http.Request) ( } // Preview handles the preview path. -func (j *Jekyll) Preview(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { +func (j *Jekyll) Preview(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) { // Get a new temporary path if there is none. if j.previewPath == "" { path, err := ioutil.TempDir("", "")