From 7673678b5075572826cc227c79a470e4a30ae7f6 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Fri, 4 Jan 2019 08:42:42 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=BC:=20types=20--->=20lib?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit License: MIT Signed-off-by: Henrique Dias --- auth/json.go | 20 ++++++++++---------- auth/none.go | 10 +++++----- auth/proxy.go | 14 +++++++------- bolt/bolt.go | 2 +- bolt/config.go | 18 +++++++++--------- bolt/share.go | 24 ++++++++++++------------ bolt/users.go | 28 ++++++++++++++-------------- cmd/config.go | 12 ++++++------ cmd/config_init.go | 6 +++--- cmd/config_set.go | 4 ++-- cmd/root.go | 10 +++++----- cmd/users.go | 16 ++++++++-------- cmd/users_find.go | 8 ++++---- cmd/users_new.go | 8 ++++---- cmd/users_update.go | 10 +++++----- cmd/utils.go | 6 +++--- cmd/version.go | 4 ++-- http/auth.go | 16 ++++++++-------- http/http.go | 12 ++++++------ http/raw.go | 6 +++--- http/resource.go | 6 +++--- http/settings.go | 10 +++++----- http/share.go | 10 +++++----- http/static.go | 4 ++-- http/users.go | 20 ++++++++++---------- {types => lib}/auth.go | 2 +- {types => lib}/errors.go | 2 +- {types => lib}/filebrowser.go | 2 +- {types => lib}/files.go | 2 +- {types => lib}/rule.go | 2 +- {types => lib}/settings.go | 2 +- {types => lib}/share.go | 2 +- {types => lib}/storage.go | 2 +- {types => lib}/user.go | 2 +- {types => lib}/utils.go | 2 +- {types => lib}/version.go | 2 +- 36 files changed, 153 insertions(+), 153 deletions(-) rename {types => lib}/auth.go (95%) rename {types => lib}/errors.go (97%) rename {types => lib}/filebrowser.go (99%) rename {types => lib}/files.go (99%) rename {types => lib}/rule.go (98%) rename {types => lib}/settings.go (98%) rename {types => lib}/share.go (95%) rename {types => lib}/storage.go (99%) rename {types => lib}/user.go (99%) rename {types => lib}/utils.go (98%) rename {types => lib}/version.go (85%) diff --git a/auth/json.go b/auth/json.go index 481b3889..da91798a 100644 --- a/auth/json.go +++ b/auth/json.go @@ -6,11 +6,11 @@ import ( "net/url" "strings" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" ) // MethodJSONAuth is used to identify json auth. -const MethodJSONAuth types.AuthMethod = "json" +const MethodJSONAuth lib.AuthMethod = "json" type jsonCred struct { Password string `json:"password"` @@ -21,20 +21,20 @@ type jsonCred struct { // JSONAuth is a json implementaion of an Auther. type JSONAuth struct { ReCaptcha *ReCaptcha - instance *types.FileBrowser + instance *lib.FileBrowser } // Auth authenticates the user via a json in content body. -func (a *JSONAuth) Auth(r *http.Request) (*types.User, error) { +func (a *JSONAuth) Auth(r *http.Request) (*lib.User, error) { var cred jsonCred if r.Body == nil { - return nil, types.ErrNoPermission + return nil, lib.ErrNoPermission } err := json.NewDecoder(r.Body).Decode(&cred) if err != nil { - return nil, types.ErrNoPermission + return nil, lib.ErrNoPermission } // If ReCaptcha is enabled, check the code. @@ -46,20 +46,20 @@ func (a *JSONAuth) Auth(r *http.Request) (*types.User, error) { } if !ok { - return nil, types.ErrNoPermission + return nil, lib.ErrNoPermission } } u, err := a.instance.GetUser(cred.Username) - if err != nil || !types.CheckPwd(cred.Password, u.Password) { - return nil, types.ErrNoPermission + if err != nil || !lib.CheckPwd(cred.Password, u.Password) { + return nil, lib.ErrNoPermission } return u, nil } // SetInstance attaches the instance to the auther. -func (a *JSONAuth) SetInstance(i *types.FileBrowser) { +func (a *JSONAuth) SetInstance(i *lib.FileBrowser) { a.instance = i } diff --git a/auth/none.go b/auth/none.go index b542f807..ffe4aeb8 100644 --- a/auth/none.go +++ b/auth/none.go @@ -3,23 +3,23 @@ package auth import ( "net/http" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" ) // MethodNoAuth is used to identify no auth. -const MethodNoAuth types.AuthMethod = "noauth" +const MethodNoAuth lib.AuthMethod = "noauth" // NoAuth is no auth implementation of auther. type NoAuth struct { - instance *types.FileBrowser + instance *lib.FileBrowser } // Auth uses authenticates user 1. -func (a *NoAuth) Auth(r *http.Request) (*types.User, error) { +func (a *NoAuth) Auth(r *http.Request) (*lib.User, error) { return a.instance.GetUser(1) } // SetInstance attaches the instance to the auther. -func (a *NoAuth) SetInstance(i *types.FileBrowser) { +func (a *NoAuth) SetInstance(i *lib.FileBrowser) { a.instance = i } diff --git a/auth/proxy.go b/auth/proxy.go index 0a913b80..9d6a5876 100644 --- a/auth/proxy.go +++ b/auth/proxy.go @@ -3,30 +3,30 @@ package auth import ( "net/http" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" ) // MethodProxyAuth is used to identify no auth. -const MethodProxyAuth types.AuthMethod = "proxy" +const MethodProxyAuth lib.AuthMethod = "proxy" // ProxyAuth is a proxy implementation of an auther. type ProxyAuth struct { Header string - instance *types.FileBrowser + instance *lib.FileBrowser } // Auth authenticates the user via an HTTP header. -func (a *ProxyAuth) Auth(r *http.Request) (*types.User, error) { +func (a *ProxyAuth) Auth(r *http.Request) (*lib.User, error) { username := r.Header.Get(a.Header) user, err := a.instance.GetUser(username) - if err == types.ErrNotExist { - return nil, types.ErrNoPermission + if err == lib.ErrNotExist { + return nil, lib.ErrNoPermission } return user, err } // SetInstance attaches the instance to the auther. -func (a *ProxyAuth) SetInstance(i *types.FileBrowser) { +func (a *ProxyAuth) SetInstance(i *lib.FileBrowser) { a.instance = i } diff --git a/bolt/bolt.go b/bolt/bolt.go index 92be59ee..2bd3d08e 100644 --- a/bolt/bolt.go +++ b/bolt/bolt.go @@ -2,7 +2,7 @@ package bolt import "github.com/asdine/storm" -// Backend implements types.StorageBackend. +// Backend implements lib.StorageBackend. type Backend struct { DB *storm.DB } diff --git a/bolt/config.go b/bolt/config.go index 1ff926dd..a00ed897 100644 --- a/bolt/config.go +++ b/bolt/config.go @@ -3,13 +3,13 @@ package bolt import ( "github.com/asdine/storm" "github.com/filebrowser/filebrowser/auth" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" ) func (b Backend) get(name string, to interface{}) error { err := b.DB.Get("config", name, to) if err == storm.ErrNotFound { - return types.ErrNotExist + return lib.ErrNotExist } return err @@ -19,17 +19,17 @@ func (b Backend) save(name string, from interface{}) error { return b.DB.Set("config", name, from) } -func (b Backend) GetSettings() (*types.Settings, error) { - settings := &types.Settings{} +func (b Backend) GetSettings() (*lib.Settings, error) { + settings := &lib.Settings{} return settings, b.get("settings", settings) } -func (b Backend) SaveSettings(s *types.Settings) error { +func (b Backend) SaveSettings(s *lib.Settings) error { return b.save("settings", s) } -func (b Backend) GetAuther(t types.AuthMethod) (types.Auther, error) { - var auther types.Auther +func (b Backend) GetAuther(t lib.AuthMethod) (lib.Auther, error) { + var auther lib.Auther switch t { case auth.MethodJSONAuth: @@ -39,12 +39,12 @@ func (b Backend) GetAuther(t types.AuthMethod) (types.Auther, error) { case auth.MethodNoAuth: auther = &auth.NoAuth{} default: - return nil, types.ErrInvalidAuthMethod + return nil, lib.ErrInvalidAuthMethod } return auther, b.get("auther", auther) } -func (b Backend) SaveAuther(a types.Auther) error { +func (b Backend) SaveAuther(a lib.Auther) error { return b.save("auther", a) } diff --git a/bolt/share.go b/bolt/share.go index 62cbe6bc..ef1c6303 100644 --- a/bolt/share.go +++ b/bolt/share.go @@ -3,43 +3,43 @@ package bolt import ( "github.com/asdine/storm" "github.com/asdine/storm/q" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" ) -func (s Backend) GetLinkByHash(hash string) (*types.ShareLink, error) { - var v types.ShareLink +func (s Backend) GetLinkByHash(hash string) (*lib.ShareLink, error) { + var v lib.ShareLink err := s.DB.One("Hash", hash, &v) if err == storm.ErrNotFound { - return nil, types.ErrNotExist + return nil, lib.ErrNotExist } return &v, err } -func (s Backend) GetLinkPermanent(path string) (*types.ShareLink, error) { - var v types.ShareLink +func (s Backend) GetLinkPermanent(path string) (*lib.ShareLink, error) { + var v lib.ShareLink err := s.DB.Select(q.Eq("Path", path), q.Eq("Expires", false)).First(&v) if err == storm.ErrNotFound { - return nil, types.ErrNotExist + return nil, lib.ErrNotExist } return &v, err } -func (s Backend) GetLinksByPath(hash string) ([]*types.ShareLink, error) { - var v []*types.ShareLink +func (s Backend) GetLinksByPath(hash string) ([]*lib.ShareLink, error) { + var v []*lib.ShareLink err := s.DB.Find("Path", hash, &v) if err == storm.ErrNotFound { - return v, types.ErrNotExist + return v, lib.ErrNotExist } return v, err } -func (s Backend) SaveLink(l *types.ShareLink) error { +func (s Backend) SaveLink(l *lib.ShareLink) error { return s.DB.Save(l) } func (s Backend) DeleteLink(hash string) error { - return s.DB.DeleteStruct(&types.ShareLink{Hash: hash}) + return s.DB.DeleteStruct(&lib.ShareLink{Hash: hash}) } diff --git a/bolt/users.go b/bolt/users.go index fe9a2f9c..085ad2d2 100644 --- a/bolt/users.go +++ b/bolt/users.go @@ -4,14 +4,14 @@ import ( "reflect" "github.com/asdine/storm" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" ) -func (st Backend) GetUserByID(id uint) (*types.User, error) { - user := &types.User{} +func (st Backend) GetUserByID(id uint) (*lib.User, error) { + user := &lib.User{} err := st.DB.One("ID", id, user) if err == storm.ErrNotFound { - return nil, types.ErrNotExist + return nil, lib.ErrNotExist } if err != nil { @@ -21,11 +21,11 @@ func (st Backend) GetUserByID(id uint) (*types.User, error) { return user, nil } -func (st Backend) GetUserByUsername(username string) (*types.User, error) { - user := &types.User{} +func (st Backend) GetUserByUsername(username string) (*lib.User, error) { + user := &lib.User{} err := st.DB.One("Username", username, user) if err == storm.ErrNotFound { - return nil, types.ErrNotExist + return nil, lib.ErrNotExist } if err != nil { @@ -35,11 +35,11 @@ func (st Backend) GetUserByUsername(username string) (*types.User, error) { return user, nil } -func (st Backend) GetUsers() ([]*types.User, error) { - users := []*types.User{} +func (st Backend) GetUsers() ([]*lib.User, error) { + users := []*lib.User{} err := st.DB.All(&users) if err == storm.ErrNotFound { - return nil, types.ErrNotExist + return nil, lib.ErrNotExist } if err != nil { @@ -49,7 +49,7 @@ func (st Backend) GetUsers() ([]*types.User, error) { return users, err } -func (st Backend) UpdateUser(user *types.User, fields ...string) error { +func (st Backend) UpdateUser(user *lib.User, fields ...string) error { if len(fields) == 0 { return st.SaveUser(user) } @@ -64,16 +64,16 @@ func (st Backend) UpdateUser(user *types.User, fields ...string) error { return nil } -func (st Backend) SaveUser(user *types.User) error { +func (st Backend) SaveUser(user *lib.User) error { err := st.DB.Save(user) if err == storm.ErrAlreadyExists { - return types.ErrExist + return lib.ErrExist } return err } func (st Backend) DeleteUserByID(id uint) error { - return st.DB.DeleteStruct(&types.User{ID: id}) + return st.DB.DeleteStruct(&lib.User{ID: id}) } func (st Backend) DeleteUserByUsername(username string) error { diff --git a/cmd/config.go b/cmd/config.go index 8e10ad84..6a7e15b0 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -9,7 +9,7 @@ import ( "text/tabwriter" "github.com/filebrowser/filebrowser/auth" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" "github.com/spf13/cobra" ) @@ -46,10 +46,10 @@ func addConfigFlags(cmd *cobra.Command) { cmd.Flags().Bool("branding.disableExternal", false, "disable external links such as GitHub links") } -func getAuthentication(cmd *cobra.Command) (types.AuthMethod, types.Auther) { - method := types.AuthMethod(mustGetString(cmd, "auth.method")) +func getAuthentication(cmd *cobra.Command) (lib.AuthMethod, lib.Auther) { + method := lib.AuthMethod(mustGetString(cmd, "auth.method")) - var auther types.Auther + var auther lib.Auther if method == auth.MethodProxyAuth { header := mustGetString(cmd, "auth.header") if header == "" { @@ -81,13 +81,13 @@ func getAuthentication(cmd *cobra.Command) (types.AuthMethod, types.Auther) { } if auther == nil { - panic(types.ErrInvalidAuthMethod) + panic(lib.ErrInvalidAuthMethod) } return method, auther } -func printSettings(s *types.Settings, auther types.Auther) { +func printSettings(s *lib.Settings, auther lib.Auther) { w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) fmt.Fprintf(w, "\nBase URL:\t%s\n", s.BaseURL) diff --git a/cmd/config_init.go b/cmd/config_init.go index 8d8b4f65..23b95746 100644 --- a/cmd/config_init.go +++ b/cmd/config_init.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/asdine/storm" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" "github.com/spf13/cobra" ) @@ -32,7 +32,7 @@ override the options.`, panic(errors.New(databasePath + " already exists")) } - defaults := types.UserDefaults{} + defaults := lib.UserDefaults{} getUserDefaults(cmd, &defaults, true) authMethod, auther := getAuthentication(cmd) @@ -47,7 +47,7 @@ override the options.`, settings.Shell = strings.Split(strings.TrimSpace(mustGetString(cmd, "shell")), " ") settings.Defaults = defaults settings.AuthMethod = authMethod - settings.Branding = types.Branding{ + settings.Branding = lib.Branding{ Name: mustGetString(cmd, "branding.name"), DisableExternal: mustGetBool(cmd, "branding.disableExternal"), Files: mustGetString(cmd, "branding.files"), diff --git a/cmd/config_set.go b/cmd/config_set.go index 13301590..073f7993 100644 --- a/cmd/config_set.go +++ b/cmd/config_set.go @@ -3,7 +3,7 @@ package cmd import ( "strings" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -48,7 +48,7 @@ you want to change.`, getUserDefaults(cmd, &s.Defaults, false) - var auther types.Auther + var auther lib.Auther var err error if auth { s.AuthMethod, auther = getAuthentication(cmd) diff --git a/cmd/root.go b/cmd/root.go index dbb44b32..f0089fbe 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,7 +12,7 @@ import ( "github.com/asdine/storm" "github.com/filebrowser/filebrowser/auth" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" fhttp "github.com/filebrowser/filebrowser/http" "github.com/spf13/cobra" @@ -97,10 +97,10 @@ func quickSetup(cmd *cobra.Command) { settings.BaseURL = "" settings.Signup = false settings.AuthMethod = auth.MethodJSONAuth - settings.Defaults = types.UserDefaults{ + settings.Defaults = lib.UserDefaults{ Scope: scope, Locale: "en", - Perm: types.Permissions{ + Perm: lib.Permissions{ Admin: false, Execute: true, Create: true, @@ -118,10 +118,10 @@ func quickSetup(cmd *cobra.Command) { err = fb.SaveAuther(&auth.JSONAuth{}) checkErr(err) - password, err := types.HashPwd("admin") + password, err := lib.HashPwd("admin") checkErr(err) - user := &types.User{ + user := &lib.User{ Username: "admin", Password: password, LockPassword: false, diff --git a/cmd/users.go b/cmd/users.go index 84aa5a4c..018a162a 100644 --- a/cmd/users.go +++ b/cmd/users.go @@ -6,7 +6,7 @@ import ( "os" "text/tabwriter" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -26,7 +26,7 @@ var usersCmd = &cobra.Command{ }, } -func printUsers(users []*types.User) { +func printUsers(users []*lib.User) { w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) fmt.Fprintln(w, "ID\tUsername\tScope\tLocale\tV. Mode\tAdmin\tExecute\tCreate\tRename\tModify\tDelete\tShare\tDownload\tPwd Lock") @@ -78,18 +78,18 @@ func addUserFlags(cmd *cobra.Command) { cmd.Flags().StringSlice("commands", nil, "a list of the commands a user can execute") cmd.Flags().String("scope", "", "scope for users") cmd.Flags().String("locale", "en", "locale for users") - cmd.Flags().String("viewMode", string(types.ListViewMode), "view mode for users") + cmd.Flags().String("viewMode", string(lib.ListViewMode), "view mode for users") } -func getViewMode(cmd *cobra.Command) types.ViewMode { - viewMode := types.ViewMode(mustGetString(cmd, "viewMode")) - if viewMode != types.ListViewMode && viewMode != types.MosaicViewMode { - checkErr(errors.New("view mode must be \"" + string(types.ListViewMode) + "\" or \"" + string(types.MosaicViewMode) + "\"")) +func getViewMode(cmd *cobra.Command) lib.ViewMode { + viewMode := lib.ViewMode(mustGetString(cmd, "viewMode")) + if viewMode != lib.ListViewMode && viewMode != lib.MosaicViewMode { + checkErr(errors.New("view mode must be \"" + string(lib.ListViewMode) + "\" or \"" + string(lib.MosaicViewMode) + "\"")) } return viewMode } -func getUserDefaults(cmd *cobra.Command, defaults *types.UserDefaults, all bool) { +func getUserDefaults(cmd *cobra.Command, defaults *lib.UserDefaults, all bool) { visit := func(flag *pflag.Flag) { switch flag.Name { case "scope": diff --git a/cmd/users_find.go b/cmd/users_find.go index 9a2de82f..afd71b78 100644 --- a/cmd/users_find.go +++ b/cmd/users_find.go @@ -1,7 +1,7 @@ package cmd import ( - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" "github.com/spf13/cobra" ) @@ -36,8 +36,8 @@ var findUsers = func(cmd *cobra.Command, args []string) { id, _ := cmd.Flags().GetUint("id") var err error - var users []*types.User - var user *types.User + var users []*lib.User + var user *lib.User if username != "" { user, err = st.GetUser(username) @@ -50,7 +50,7 @@ var findUsers = func(cmd *cobra.Command, args []string) { checkErr(err) if user != nil { - users = []*types.User{user} + users = []*lib.User{user} } printUsers(users) diff --git a/cmd/users_new.go b/cmd/users_new.go index 1950bab3..e94bc036 100644 --- a/cmd/users_new.go +++ b/cmd/users_new.go @@ -1,7 +1,7 @@ package cmd import ( - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" "github.com/spf13/cobra" ) @@ -29,10 +29,10 @@ var usersNewCmd = &cobra.Command{ getUserDefaults(cmd, &settings.Defaults, false) password, _ := cmd.Flags().GetString("password") - password, err := types.HashPwd(password) + password, err := lib.HashPwd(password) checkErr(err) - user := &types.User{ + user := &lib.User{ Username: mustGetString(cmd, "username"), Password: password, LockPassword: mustGetBool(cmd, "lockPassword"), @@ -41,6 +41,6 @@ var usersNewCmd = &cobra.Command{ st.ApplyDefaults(user) err = st.SaveUser(user) checkErr(err) - printUsers([]*types.User{user}) + printUsers([]*lib.User{user}) }, } diff --git a/cmd/users_update.go b/cmd/users_update.go index f20e96f1..9d6193bf 100644 --- a/cmd/users_update.go +++ b/cmd/users_update.go @@ -1,7 +1,7 @@ package cmd import ( - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" "github.com/spf13/cobra" ) @@ -29,7 +29,7 @@ options you want to change.`, username := mustGetString(cmd, "username") password := mustGetString(cmd, "password") - var user *types.User + var user *lib.User var err error if id != 0 { @@ -40,7 +40,7 @@ options you want to change.`, checkErr(err) - defaults := types.UserDefaults{ + defaults := lib.UserDefaults{ Scope: user.Scope, Locale: user.Locale, ViewMode: user.ViewMode, @@ -62,12 +62,12 @@ options you want to change.`, } if password != "" { - user.Password, err = types.HashPwd(password) + user.Password, err = lib.HashPwd(password) checkErr(err) } err = st.UpdateUser(user) checkErr(err) - printUsers([]*types.User{user}) + printUsers([]*lib.User{user}) }, } diff --git a/cmd/utils.go b/cmd/utils.go index 73bac359..10a3ef33 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -6,7 +6,7 @@ import ( "github.com/asdine/storm" "github.com/filebrowser/filebrowser/bolt" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" "github.com/spf13/cobra" ) @@ -38,8 +38,8 @@ func getDB() *storm.DB { return db } -func getFileBrowser(db *storm.DB) *types.FileBrowser { - fb, err := types.NewFileBrowser(&bolt.Backend{DB: db}) +func getFileBrowser(db *storm.DB) *lib.FileBrowser { + fb, err := lib.NewFileBrowser(&bolt.Backend{DB: db}) checkErr(err) return fb } diff --git a/cmd/version.go b/cmd/version.go index 98f8fa1e..1ba4f81c 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -3,7 +3,7 @@ package cmd import ( "fmt" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" "github.com/spf13/cobra" ) @@ -15,6 +15,6 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "Print the version number", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("File Browser Version " + types.Version) + fmt.Println("File Browser Version " + lib.Version) }, } diff --git a/http/auth.go b/http/auth.go index 4f790dca..aa7737b4 100644 --- a/http/auth.go +++ b/http/auth.go @@ -9,13 +9,13 @@ import ( "github.com/dgrijalva/jwt-go" "github.com/dgrijalva/jwt-go/request" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" ) func (e *Env) loginHandler(w http.ResponseWriter, r *http.Request) { user, err := e.Auther.Auth(r) - if err == types.ErrNoPermission { + if err == lib.ErrNoPermission { httpErr(w, r, http.StatusForbidden, nil) } else if err != nil { httpErr(w, r, http.StatusInternalServerError, err) @@ -58,13 +58,13 @@ func (e *Env) signupHandler(w http.ResponseWriter, r *http.Request) { return } - user := &types.User{ + user := &lib.User{ Username: info.Username, } e.ApplyDefaults(user) - pwd, err := types.HashPwd(info.Password) + pwd, err := lib.HashPwd(info.Password) if err != nil { httpErr(w, r, http.StatusInternalServerError, err) return @@ -72,7 +72,7 @@ func (e *Env) signupHandler(w http.ResponseWriter, r *http.Request) { user.Password = pwd err = e.SaveUser(user) - if err == types.ErrExist { + if err == lib.ErrExist { httpErr(w, r, http.StatusConflict, nil) return } else if err != nil { @@ -86,8 +86,8 @@ func (e *Env) signupHandler(w http.ResponseWriter, r *http.Request) { type userInfo struct { ID uint `json:"id"` Locale string `json:"locale"` - ViewMode types.ViewMode `json:"viewMode"` - Perm types.Permissions `json:"perm"` + ViewMode lib.ViewMode `json:"viewMode"` + Perm lib.Permissions `json:"perm"` Commands []string `json:"commands"` LockPassword bool `json:"lockPassword"` } @@ -154,7 +154,7 @@ func (e *Env) renew(w http.ResponseWriter, r *http.Request) { e.printToken(w, r, user) } -func (e *Env) printToken(w http.ResponseWriter, r *http.Request, user *types.User) { +func (e *Env) printToken(w http.ResponseWriter, r *http.Request, user *lib.User) { claims := &authToken{ User: userInfo{ ID: user.ID, diff --git a/http/http.go b/http/http.go index 3091b6fa..3237767f 100644 --- a/http/http.go +++ b/http/http.go @@ -7,7 +7,7 @@ import ( "strconv" "time" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" "github.com/gorilla/mux" "github.com/gorilla/websocket" ) @@ -25,8 +25,8 @@ type modifyRequest struct { // Env contains the required info for FB to run. type Env struct { - *types.FileBrowser - Auther types.Auther + *lib.FileBrowser + Auther lib.Auther } // Handler ... @@ -99,10 +99,10 @@ func renderJSON(w http.ResponseWriter, r *http.Request, data interface{}) { } } -func (e *Env) getUser(w http.ResponseWriter, r *http.Request) (*types.User, bool) { +func (e *Env) getUser(w http.ResponseWriter, r *http.Request) (*lib.User, bool) { id := r.Context().Value(keyUserID).(uint) user, err := e.GetUser(id) - if err == types.ErrNotExist { + if err == lib.ErrNotExist { httpErr(w, r, http.StatusForbidden, nil) return nil, false } @@ -115,7 +115,7 @@ func (e *Env) getUser(w http.ResponseWriter, r *http.Request) (*types.User, bool return user, true } -func (e *Env) getAdminUser(w http.ResponseWriter, r *http.Request) (*types.User, bool) { +func (e *Env) getAdminUser(w http.ResponseWriter, r *http.Request) (*lib.User, bool) { user, ok := e.getUser(w, r) if !ok { return nil, false diff --git a/http/raw.go b/http/raw.go index c1e10478..a1eb1abf 100644 --- a/http/raw.go +++ b/http/raw.go @@ -7,14 +7,14 @@ import ( "path/filepath" "strings" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" "github.com/hacdias/fileutils" "github.com/mholt/archiver" ) const apiRawPrefix = "/api/raw" -func parseQueryFiles(r *http.Request, f *types.File, u *types.User) ([]string, error) { +func parseQueryFiles(r *http.Request, f *lib.File, u *lib.User) ([]string, error) { files := []string{} names := strings.Split(r.URL.Query().Get("files"), ",") @@ -141,7 +141,7 @@ func (e *Env) rawHandler(w http.ResponseWriter, r *http.Request) { } } -func fileHandler(w http.ResponseWriter, r *http.Request, file *types.File, user *types.User) { +func fileHandler(w http.ResponseWriter, r *http.Request, file *lib.File, user *lib.User) { fd, err := user.Fs.Open(file.Path) if err != nil { httpErr(w, r, http.StatusInternalServerError, err) diff --git a/http/resource.go b/http/resource.go index 67d6c0e8..3160bd2a 100644 --- a/http/resource.go +++ b/http/resource.go @@ -10,7 +10,7 @@ import ( "strings" "github.com/filebrowser/filebrowser/fileutils" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" ) const apiResourcePrefix = "/api/resources" @@ -30,7 +30,7 @@ func httpFsErr(err error) int { } } -func (e *Env) getResourceData(w http.ResponseWriter, r *http.Request, prefix string) (string, *types.User, bool) { +func (e *Env) getResourceData(w http.ResponseWriter, r *http.Request, prefix string) (string, *lib.User, bool) { user, ok := e.getUser(w, r) if !ok { return "", nil, ok @@ -71,7 +71,7 @@ func (e *Env) resourceGetHandler(w http.ResponseWriter, r *http.Request) { if checksum := r.URL.Query().Get("checksum"); checksum != "" { err = e.Checksum(file,user, checksum) - if err == types.ErrInvalidOption { + if err == lib.ErrInvalidOption { httpErr(w, r, http.StatusBadRequest, nil) return } else if err != nil { diff --git a/http/settings.go b/http/settings.go index 3d9ca103..36039cf9 100644 --- a/http/settings.go +++ b/http/settings.go @@ -4,15 +4,15 @@ import ( "encoding/json" "net/http" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" "github.com/jinzhu/copier" ) type settingsData struct { Signup bool `json:"signup"` - Defaults types.UserDefaults `json:"defaults"` - Rules []types.Rule `json:"rules"` - Branding types.Branding `json:"branding"` + Defaults lib.UserDefaults `json:"defaults"` + Rules []lib.Rule `json:"rules"` + Branding lib.Branding `json:"branding"` Shell []string `json:"shell"` Commands map[string][]string `json:"commands"` } @@ -52,7 +52,7 @@ func (e *Env) settingsPutHandler(w http.ResponseWriter, r *http.Request) { } e.RLockSettings() - settings := &types.Settings{} + settings := &lib.Settings{} err = copier.Copy(settings, e.GetSettings()) e.RUnlockSettings() diff --git a/http/share.go b/http/share.go index 2ed08d8e..efc0bee1 100644 --- a/http/share.go +++ b/http/share.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" ) const apiSharePrefix = "/api/share" @@ -34,8 +34,8 @@ func (e *Env) shareGetHandler(w http.ResponseWriter, r *http.Request) { } s, err := e.GetLinksByPath(path) - if err == types.ErrNotExist { - renderJSON(w, r, []*types.ShareLink{}) + if err == lib.ErrNotExist { + renderJSON(w, r, []*lib.ShareLink{}) return } @@ -85,7 +85,7 @@ func (e *Env) sharePostHandler(w http.ResponseWriter, r *http.Request) { return } - var s *types.ShareLink + var s *lib.ShareLink expire := r.URL.Query().Get("expires") unit := r.URL.Query().Get("unit") @@ -107,7 +107,7 @@ func (e *Env) sharePostHandler(w http.ResponseWriter, r *http.Request) { str := base64.URLEncoding.EncodeToString(bytes) - s = &types.ShareLink{ + s = &lib.ShareLink{ Path: path, Hash: str, Expires: expire != "", diff --git a/http/static.go b/http/static.go index 52dbe370..d7a08596 100644 --- a/http/static.go +++ b/http/static.go @@ -11,7 +11,7 @@ import ( "github.com/GeertJohan/go.rice" "github.com/filebrowser/filebrowser/auth" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" ) func (e *Env) getStaticData() map[string]interface{} { @@ -26,7 +26,7 @@ func (e *Env) getStaticData() map[string]interface{} { "Name": settings.Branding.Name, "DisableExternal": settings.Branding.DisableExternal, "BaseURL": settings.BaseURL, - "Version": types.Version, + "Version": lib.Version, "StaticURL": staticURL, "Signup": settings.Signup, "NoAuth": settings.AuthMethod == auth.MethodNoAuth, diff --git a/http/users.go b/http/users.go index be25eb71..559dfe93 100644 --- a/http/users.go +++ b/http/users.go @@ -7,7 +7,7 @@ import ( "strconv" "strings" - "github.com/filebrowser/filebrowser/types" + "github.com/filebrowser/filebrowser/lib" "github.com/gorilla/mux" ) @@ -22,7 +22,7 @@ func getUserID(r *http.Request) (uint, error) { type modifyUserRequest struct { modifyRequest - Data *types.User `json:"data"` + Data *lib.User `json:"data"` } func getUser(w http.ResponseWriter, r *http.Request) (*modifyUserRequest, bool) { @@ -74,7 +74,7 @@ func (e *Env) usersGetHandler(w http.ResponseWriter, r *http.Request) { renderJSON(w, r, users) } -func (e *Env) userSelfOrAdmin(w http.ResponseWriter, r *http.Request) (*types.User, uint, bool) { +func (e *Env) userSelfOrAdmin(w http.ResponseWriter, r *http.Request) (*lib.User, uint, bool) { user, ok := e.getUser(w, r) if !ok { return nil, 0, false @@ -101,7 +101,7 @@ func (e *Env) userGetHandler(w http.ResponseWriter, r *http.Request) { } u, err := e.GetUser(id) - if err == types.ErrNotExist { + if err == lib.ErrNotExist { httpErr(w, r, http.StatusNotFound, nil) return } @@ -122,7 +122,7 @@ func (e *Env) userDeleteHandler(w http.ResponseWriter, r *http.Request) { } err := e.DeleteUser(id) - if err == types.ErrNotExist { + if err == lib.ErrNotExist { httpErr(w, r, http.StatusNotFound, nil) return } @@ -149,12 +149,12 @@ func (e *Env) userPostHandler(w http.ResponseWriter, r *http.Request) { } if req.Data.Password == "" { - httpErr(w, r, http.StatusBadRequest, types.ErrEmptyPassword) + httpErr(w, r, http.StatusBadRequest, lib.ErrEmptyPassword) return } var err error - req.Data.Password, err = types.HashPwd(req.Data.Password) + req.Data.Password, err = lib.HashPwd(req.Data.Password) if err != nil { httpErr(w, r, http.StatusInternalServerError, err) return @@ -195,9 +195,9 @@ func (e *Env) userPutHandler(w http.ResponseWriter, r *http.Request) { } if req.Data.Password != "" { - req.Data.Password, err = types.HashPwd(req.Data.Password) + req.Data.Password, err = lib.HashPwd(req.Data.Password) } else { - var suser *types.User + var suser *lib.User suser, err = e.GetUser(modifiedID) req.Data.Password = suser.Password } @@ -217,7 +217,7 @@ func (e *Env) userPutHandler(w http.ResponseWriter, r *http.Request) { return } - req.Data.Password, err = types.HashPwd(req.Data.Password) + req.Data.Password, err = lib.HashPwd(req.Data.Password) if err != nil { httpErr(w, r, http.StatusInternalServerError, err) return diff --git a/types/auth.go b/lib/auth.go similarity index 95% rename from types/auth.go rename to lib/auth.go index 00c2ed1e..2404742e 100644 --- a/types/auth.go +++ b/lib/auth.go @@ -1,4 +1,4 @@ -package types +package lib import "net/http" diff --git a/types/errors.go b/lib/errors.go similarity index 97% rename from types/errors.go rename to lib/errors.go index f45dbb3f..c44507f4 100644 --- a/types/errors.go +++ b/lib/errors.go @@ -1,4 +1,4 @@ -package types +package lib import "errors" diff --git a/types/filebrowser.go b/lib/filebrowser.go similarity index 99% rename from types/filebrowser.go rename to lib/filebrowser.go index 384abcef..736fed58 100644 --- a/types/filebrowser.go +++ b/lib/filebrowser.go @@ -1,4 +1,4 @@ -package types +package lib import ( "crypto/md5" diff --git a/types/files.go b/lib/files.go similarity index 99% rename from types/files.go rename to lib/files.go index da003d00..19012087 100644 --- a/types/files.go +++ b/lib/files.go @@ -1,4 +1,4 @@ -package types +package lib import ( "os" diff --git a/types/rule.go b/lib/rule.go similarity index 98% rename from types/rule.go rename to lib/rule.go index c4c36462..1acc5034 100644 --- a/types/rule.go +++ b/lib/rule.go @@ -1,4 +1,4 @@ -package types +package lib import ( "regexp" diff --git a/types/settings.go b/lib/settings.go similarity index 98% rename from types/settings.go rename to lib/settings.go index 067fdfa3..01eb3bd0 100644 --- a/types/settings.go +++ b/lib/settings.go @@ -1,4 +1,4 @@ -package types +package lib // Settings contain the main settings of the application. type Settings struct { diff --git a/types/share.go b/lib/share.go similarity index 95% rename from types/share.go rename to lib/share.go index 710fce7f..0f9f7167 100644 --- a/types/share.go +++ b/lib/share.go @@ -1,4 +1,4 @@ -package types +package lib import "time" diff --git a/types/storage.go b/lib/storage.go similarity index 99% rename from types/storage.go rename to lib/storage.go index 06c5dc03..54d3670b 100644 --- a/types/storage.go +++ b/lib/storage.go @@ -1,4 +1,4 @@ -package types +package lib import ( "strings" diff --git a/types/user.go b/lib/user.go similarity index 99% rename from types/user.go rename to lib/user.go index 4934f259..9973fee2 100644 --- a/types/user.go +++ b/lib/user.go @@ -1,4 +1,4 @@ -package types +package lib import ( "path/filepath" diff --git a/types/utils.go b/lib/utils.go similarity index 98% rename from types/utils.go rename to lib/utils.go index 14b48afd..ee828dfb 100644 --- a/types/utils.go +++ b/lib/utils.go @@ -1,4 +1,4 @@ -package types +package lib import ( "crypto/rand" diff --git a/types/version.go b/lib/version.go similarity index 85% rename from types/version.go rename to lib/version.go index 845426c8..95359653 100644 --- a/types/version.go +++ b/lib/version.go @@ -1,4 +1,4 @@ -package types +package lib const ( // Version is the current File Browser version.