🧼: types ---> lib

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
This commit is contained in:
Henrique Dias 2019-01-04 08:42:42 +00:00
parent 6811f205b4
commit 7673678b50
36 changed files with 153 additions and 153 deletions

View File

@ -6,11 +6,11 @@ import (
"net/url" "net/url"
"strings" "strings"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
) )
// MethodJSONAuth is used to identify json auth. // MethodJSONAuth is used to identify json auth.
const MethodJSONAuth types.AuthMethod = "json" const MethodJSONAuth lib.AuthMethod = "json"
type jsonCred struct { type jsonCred struct {
Password string `json:"password"` Password string `json:"password"`
@ -21,20 +21,20 @@ type jsonCred struct {
// JSONAuth is a json implementaion of an Auther. // JSONAuth is a json implementaion of an Auther.
type JSONAuth struct { type JSONAuth struct {
ReCaptcha *ReCaptcha ReCaptcha *ReCaptcha
instance *types.FileBrowser instance *lib.FileBrowser
} }
// Auth authenticates the user via a json in content body. // 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 var cred jsonCred
if r.Body == nil { if r.Body == nil {
return nil, types.ErrNoPermission return nil, lib.ErrNoPermission
} }
err := json.NewDecoder(r.Body).Decode(&cred) err := json.NewDecoder(r.Body).Decode(&cred)
if err != nil { if err != nil {
return nil, types.ErrNoPermission return nil, lib.ErrNoPermission
} }
// If ReCaptcha is enabled, check the code. // If ReCaptcha is enabled, check the code.
@ -46,20 +46,20 @@ func (a *JSONAuth) Auth(r *http.Request) (*types.User, error) {
} }
if !ok { if !ok {
return nil, types.ErrNoPermission return nil, lib.ErrNoPermission
} }
} }
u, err := a.instance.GetUser(cred.Username) u, err := a.instance.GetUser(cred.Username)
if err != nil || !types.CheckPwd(cred.Password, u.Password) { if err != nil || !lib.CheckPwd(cred.Password, u.Password) {
return nil, types.ErrNoPermission return nil, lib.ErrNoPermission
} }
return u, nil return u, nil
} }
// SetInstance attaches the instance to the auther. // SetInstance attaches the instance to the auther.
func (a *JSONAuth) SetInstance(i *types.FileBrowser) { func (a *JSONAuth) SetInstance(i *lib.FileBrowser) {
a.instance = i a.instance = i
} }

View File

@ -3,23 +3,23 @@ package auth
import ( import (
"net/http" "net/http"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
) )
// MethodNoAuth is used to identify no auth. // MethodNoAuth is used to identify no auth.
const MethodNoAuth types.AuthMethod = "noauth" const MethodNoAuth lib.AuthMethod = "noauth"
// NoAuth is no auth implementation of auther. // NoAuth is no auth implementation of auther.
type NoAuth struct { type NoAuth struct {
instance *types.FileBrowser instance *lib.FileBrowser
} }
// Auth uses authenticates user 1. // 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) return a.instance.GetUser(1)
} }
// SetInstance attaches the instance to the auther. // SetInstance attaches the instance to the auther.
func (a *NoAuth) SetInstance(i *types.FileBrowser) { func (a *NoAuth) SetInstance(i *lib.FileBrowser) {
a.instance = i a.instance = i
} }

View File

@ -3,30 +3,30 @@ package auth
import ( import (
"net/http" "net/http"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
) )
// MethodProxyAuth is used to identify no auth. // 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. // ProxyAuth is a proxy implementation of an auther.
type ProxyAuth struct { type ProxyAuth struct {
Header string Header string
instance *types.FileBrowser instance *lib.FileBrowser
} }
// Auth authenticates the user via an HTTP header. // 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) username := r.Header.Get(a.Header)
user, err := a.instance.GetUser(username) user, err := a.instance.GetUser(username)
if err == types.ErrNotExist { if err == lib.ErrNotExist {
return nil, types.ErrNoPermission return nil, lib.ErrNoPermission
} }
return user, err return user, err
} }
// SetInstance attaches the instance to the auther. // SetInstance attaches the instance to the auther.
func (a *ProxyAuth) SetInstance(i *types.FileBrowser) { func (a *ProxyAuth) SetInstance(i *lib.FileBrowser) {
a.instance = i a.instance = i
} }

View File

@ -2,7 +2,7 @@ package bolt
import "github.com/asdine/storm" import "github.com/asdine/storm"
// Backend implements types.StorageBackend. // Backend implements lib.StorageBackend.
type Backend struct { type Backend struct {
DB *storm.DB DB *storm.DB
} }

View File

@ -3,13 +3,13 @@ package bolt
import ( import (
"github.com/asdine/storm" "github.com/asdine/storm"
"github.com/filebrowser/filebrowser/auth" "github.com/filebrowser/filebrowser/auth"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
) )
func (b Backend) get(name string, to interface{}) error { func (b Backend) get(name string, to interface{}) error {
err := b.DB.Get("config", name, to) err := b.DB.Get("config", name, to)
if err == storm.ErrNotFound { if err == storm.ErrNotFound {
return types.ErrNotExist return lib.ErrNotExist
} }
return err return err
@ -19,17 +19,17 @@ func (b Backend) save(name string, from interface{}) error {
return b.DB.Set("config", name, from) return b.DB.Set("config", name, from)
} }
func (b Backend) GetSettings() (*types.Settings, error) { func (b Backend) GetSettings() (*lib.Settings, error) {
settings := &types.Settings{} settings := &lib.Settings{}
return settings, b.get("settings", 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) return b.save("settings", s)
} }
func (b Backend) GetAuther(t types.AuthMethod) (types.Auther, error) { func (b Backend) GetAuther(t lib.AuthMethod) (lib.Auther, error) {
var auther types.Auther var auther lib.Auther
switch t { switch t {
case auth.MethodJSONAuth: case auth.MethodJSONAuth:
@ -39,12 +39,12 @@ func (b Backend) GetAuther(t types.AuthMethod) (types.Auther, error) {
case auth.MethodNoAuth: case auth.MethodNoAuth:
auther = &auth.NoAuth{} auther = &auth.NoAuth{}
default: default:
return nil, types.ErrInvalidAuthMethod return nil, lib.ErrInvalidAuthMethod
} }
return auther, b.get("auther", auther) 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) return b.save("auther", a)
} }

View File

@ -3,43 +3,43 @@ package bolt
import ( import (
"github.com/asdine/storm" "github.com/asdine/storm"
"github.com/asdine/storm/q" "github.com/asdine/storm/q"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
) )
func (s Backend) GetLinkByHash(hash string) (*types.ShareLink, error) { func (s Backend) GetLinkByHash(hash string) (*lib.ShareLink, error) {
var v types.ShareLink var v lib.ShareLink
err := s.DB.One("Hash", hash, &v) err := s.DB.One("Hash", hash, &v)
if err == storm.ErrNotFound { if err == storm.ErrNotFound {
return nil, types.ErrNotExist return nil, lib.ErrNotExist
} }
return &v, err return &v, err
} }
func (s Backend) GetLinkPermanent(path string) (*types.ShareLink, error) { func (s Backend) GetLinkPermanent(path string) (*lib.ShareLink, error) {
var v types.ShareLink var v lib.ShareLink
err := s.DB.Select(q.Eq("Path", path), q.Eq("Expires", false)).First(&v) err := s.DB.Select(q.Eq("Path", path), q.Eq("Expires", false)).First(&v)
if err == storm.ErrNotFound { if err == storm.ErrNotFound {
return nil, types.ErrNotExist return nil, lib.ErrNotExist
} }
return &v, err return &v, err
} }
func (s Backend) GetLinksByPath(hash string) ([]*types.ShareLink, error) { func (s Backend) GetLinksByPath(hash string) ([]*lib.ShareLink, error) {
var v []*types.ShareLink var v []*lib.ShareLink
err := s.DB.Find("Path", hash, &v) err := s.DB.Find("Path", hash, &v)
if err == storm.ErrNotFound { if err == storm.ErrNotFound {
return v, types.ErrNotExist return v, lib.ErrNotExist
} }
return v, err return v, err
} }
func (s Backend) SaveLink(l *types.ShareLink) error { func (s Backend) SaveLink(l *lib.ShareLink) error {
return s.DB.Save(l) return s.DB.Save(l)
} }
func (s Backend) DeleteLink(hash string) error { func (s Backend) DeleteLink(hash string) error {
return s.DB.DeleteStruct(&types.ShareLink{Hash: hash}) return s.DB.DeleteStruct(&lib.ShareLink{Hash: hash})
} }

View File

@ -4,14 +4,14 @@ import (
"reflect" "reflect"
"github.com/asdine/storm" "github.com/asdine/storm"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
) )
func (st Backend) GetUserByID(id uint) (*types.User, error) { func (st Backend) GetUserByID(id uint) (*lib.User, error) {
user := &types.User{} user := &lib.User{}
err := st.DB.One("ID", id, user) err := st.DB.One("ID", id, user)
if err == storm.ErrNotFound { if err == storm.ErrNotFound {
return nil, types.ErrNotExist return nil, lib.ErrNotExist
} }
if err != nil { if err != nil {
@ -21,11 +21,11 @@ func (st Backend) GetUserByID(id uint) (*types.User, error) {
return user, nil return user, nil
} }
func (st Backend) GetUserByUsername(username string) (*types.User, error) { func (st Backend) GetUserByUsername(username string) (*lib.User, error) {
user := &types.User{} user := &lib.User{}
err := st.DB.One("Username", username, user) err := st.DB.One("Username", username, user)
if err == storm.ErrNotFound { if err == storm.ErrNotFound {
return nil, types.ErrNotExist return nil, lib.ErrNotExist
} }
if err != nil { if err != nil {
@ -35,11 +35,11 @@ func (st Backend) GetUserByUsername(username string) (*types.User, error) {
return user, nil return user, nil
} }
func (st Backend) GetUsers() ([]*types.User, error) { func (st Backend) GetUsers() ([]*lib.User, error) {
users := []*types.User{} users := []*lib.User{}
err := st.DB.All(&users) err := st.DB.All(&users)
if err == storm.ErrNotFound { if err == storm.ErrNotFound {
return nil, types.ErrNotExist return nil, lib.ErrNotExist
} }
if err != nil { if err != nil {
@ -49,7 +49,7 @@ func (st Backend) GetUsers() ([]*types.User, error) {
return users, err 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 { if len(fields) == 0 {
return st.SaveUser(user) return st.SaveUser(user)
} }
@ -64,16 +64,16 @@ func (st Backend) UpdateUser(user *types.User, fields ...string) error {
return nil return nil
} }
func (st Backend) SaveUser(user *types.User) error { func (st Backend) SaveUser(user *lib.User) error {
err := st.DB.Save(user) err := st.DB.Save(user)
if err == storm.ErrAlreadyExists { if err == storm.ErrAlreadyExists {
return types.ErrExist return lib.ErrExist
} }
return err return err
} }
func (st Backend) DeleteUserByID(id uint) error { 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 { func (st Backend) DeleteUserByUsername(username string) error {

View File

@ -9,7 +9,7 @@ import (
"text/tabwriter" "text/tabwriter"
"github.com/filebrowser/filebrowser/auth" "github.com/filebrowser/filebrowser/auth"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
"github.com/spf13/cobra" "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") cmd.Flags().Bool("branding.disableExternal", false, "disable external links such as GitHub links")
} }
func getAuthentication(cmd *cobra.Command) (types.AuthMethod, types.Auther) { func getAuthentication(cmd *cobra.Command) (lib.AuthMethod, lib.Auther) {
method := types.AuthMethod(mustGetString(cmd, "auth.method")) method := lib.AuthMethod(mustGetString(cmd, "auth.method"))
var auther types.Auther var auther lib.Auther
if method == auth.MethodProxyAuth { if method == auth.MethodProxyAuth {
header := mustGetString(cmd, "auth.header") header := mustGetString(cmd, "auth.header")
if header == "" { if header == "" {
@ -81,13 +81,13 @@ func getAuthentication(cmd *cobra.Command) (types.AuthMethod, types.Auther) {
} }
if auther == nil { if auther == nil {
panic(types.ErrInvalidAuthMethod) panic(lib.ErrInvalidAuthMethod)
} }
return method, auther 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) w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
fmt.Fprintf(w, "\nBase URL:\t%s\n", s.BaseURL) fmt.Fprintf(w, "\nBase URL:\t%s\n", s.BaseURL)

View File

@ -7,7 +7,7 @@ import (
"strings" "strings"
"github.com/asdine/storm" "github.com/asdine/storm"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -32,7 +32,7 @@ override the options.`,
panic(errors.New(databasePath + " already exists")) panic(errors.New(databasePath + " already exists"))
} }
defaults := types.UserDefaults{} defaults := lib.UserDefaults{}
getUserDefaults(cmd, &defaults, true) getUserDefaults(cmd, &defaults, true)
authMethod, auther := getAuthentication(cmd) authMethod, auther := getAuthentication(cmd)
@ -47,7 +47,7 @@ override the options.`,
settings.Shell = strings.Split(strings.TrimSpace(mustGetString(cmd, "shell")), " ") settings.Shell = strings.Split(strings.TrimSpace(mustGetString(cmd, "shell")), " ")
settings.Defaults = defaults settings.Defaults = defaults
settings.AuthMethod = authMethod settings.AuthMethod = authMethod
settings.Branding = types.Branding{ settings.Branding = lib.Branding{
Name: mustGetString(cmd, "branding.name"), Name: mustGetString(cmd, "branding.name"),
DisableExternal: mustGetBool(cmd, "branding.disableExternal"), DisableExternal: mustGetBool(cmd, "branding.disableExternal"),
Files: mustGetString(cmd, "branding.files"), Files: mustGetString(cmd, "branding.files"),

View File

@ -3,7 +3,7 @@ package cmd
import ( import (
"strings" "strings"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
@ -48,7 +48,7 @@ you want to change.`,
getUserDefaults(cmd, &s.Defaults, false) getUserDefaults(cmd, &s.Defaults, false)
var auther types.Auther var auther lib.Auther
var err error var err error
if auth { if auth {
s.AuthMethod, auther = getAuthentication(cmd) s.AuthMethod, auther = getAuthentication(cmd)

View File

@ -12,7 +12,7 @@ import (
"github.com/asdine/storm" "github.com/asdine/storm"
"github.com/filebrowser/filebrowser/auth" "github.com/filebrowser/filebrowser/auth"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
fhttp "github.com/filebrowser/filebrowser/http" fhttp "github.com/filebrowser/filebrowser/http"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -97,10 +97,10 @@ func quickSetup(cmd *cobra.Command) {
settings.BaseURL = "" settings.BaseURL = ""
settings.Signup = false settings.Signup = false
settings.AuthMethod = auth.MethodJSONAuth settings.AuthMethod = auth.MethodJSONAuth
settings.Defaults = types.UserDefaults{ settings.Defaults = lib.UserDefaults{
Scope: scope, Scope: scope,
Locale: "en", Locale: "en",
Perm: types.Permissions{ Perm: lib.Permissions{
Admin: false, Admin: false,
Execute: true, Execute: true,
Create: true, Create: true,
@ -118,10 +118,10 @@ func quickSetup(cmd *cobra.Command) {
err = fb.SaveAuther(&auth.JSONAuth{}) err = fb.SaveAuther(&auth.JSONAuth{})
checkErr(err) checkErr(err)
password, err := types.HashPwd("admin") password, err := lib.HashPwd("admin")
checkErr(err) checkErr(err)
user := &types.User{ user := &lib.User{
Username: "admin", Username: "admin",
Password: password, Password: password,
LockPassword: false, LockPassword: false,

View File

@ -6,7 +6,7 @@ import (
"os" "os"
"text/tabwriter" "text/tabwriter"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "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) 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") 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().StringSlice("commands", nil, "a list of the commands a user can execute")
cmd.Flags().String("scope", "", "scope for users") cmd.Flags().String("scope", "", "scope for users")
cmd.Flags().String("locale", "en", "locale 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 { func getViewMode(cmd *cobra.Command) lib.ViewMode {
viewMode := types.ViewMode(mustGetString(cmd, "viewMode")) viewMode := lib.ViewMode(mustGetString(cmd, "viewMode"))
if viewMode != types.ListViewMode && viewMode != types.MosaicViewMode { if viewMode != lib.ListViewMode && viewMode != lib.MosaicViewMode {
checkErr(errors.New("view mode must be \"" + string(types.ListViewMode) + "\" or \"" + string(types.MosaicViewMode) + "\"")) checkErr(errors.New("view mode must be \"" + string(lib.ListViewMode) + "\" or \"" + string(lib.MosaicViewMode) + "\""))
} }
return viewMode 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) { visit := func(flag *pflag.Flag) {
switch flag.Name { switch flag.Name {
case "scope": case "scope":

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -36,8 +36,8 @@ var findUsers = func(cmd *cobra.Command, args []string) {
id, _ := cmd.Flags().GetUint("id") id, _ := cmd.Flags().GetUint("id")
var err error var err error
var users []*types.User var users []*lib.User
var user *types.User var user *lib.User
if username != "" { if username != "" {
user, err = st.GetUser(username) user, err = st.GetUser(username)
@ -50,7 +50,7 @@ var findUsers = func(cmd *cobra.Command, args []string) {
checkErr(err) checkErr(err)
if user != nil { if user != nil {
users = []*types.User{user} users = []*lib.User{user}
} }
printUsers(users) printUsers(users)

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -29,10 +29,10 @@ var usersNewCmd = &cobra.Command{
getUserDefaults(cmd, &settings.Defaults, false) getUserDefaults(cmd, &settings.Defaults, false)
password, _ := cmd.Flags().GetString("password") password, _ := cmd.Flags().GetString("password")
password, err := types.HashPwd(password) password, err := lib.HashPwd(password)
checkErr(err) checkErr(err)
user := &types.User{ user := &lib.User{
Username: mustGetString(cmd, "username"), Username: mustGetString(cmd, "username"),
Password: password, Password: password,
LockPassword: mustGetBool(cmd, "lockPassword"), LockPassword: mustGetBool(cmd, "lockPassword"),
@ -41,6 +41,6 @@ var usersNewCmd = &cobra.Command{
st.ApplyDefaults(user) st.ApplyDefaults(user)
err = st.SaveUser(user) err = st.SaveUser(user)
checkErr(err) checkErr(err)
printUsers([]*types.User{user}) printUsers([]*lib.User{user})
}, },
} }

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -29,7 +29,7 @@ options you want to change.`,
username := mustGetString(cmd, "username") username := mustGetString(cmd, "username")
password := mustGetString(cmd, "password") password := mustGetString(cmd, "password")
var user *types.User var user *lib.User
var err error var err error
if id != 0 { if id != 0 {
@ -40,7 +40,7 @@ options you want to change.`,
checkErr(err) checkErr(err)
defaults := types.UserDefaults{ defaults := lib.UserDefaults{
Scope: user.Scope, Scope: user.Scope,
Locale: user.Locale, Locale: user.Locale,
ViewMode: user.ViewMode, ViewMode: user.ViewMode,
@ -62,12 +62,12 @@ options you want to change.`,
} }
if password != "" { if password != "" {
user.Password, err = types.HashPwd(password) user.Password, err = lib.HashPwd(password)
checkErr(err) checkErr(err)
} }
err = st.UpdateUser(user) err = st.UpdateUser(user)
checkErr(err) checkErr(err)
printUsers([]*types.User{user}) printUsers([]*lib.User{user})
}, },
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/asdine/storm" "github.com/asdine/storm"
"github.com/filebrowser/filebrowser/bolt" "github.com/filebrowser/filebrowser/bolt"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -38,8 +38,8 @@ func getDB() *storm.DB {
return db return db
} }
func getFileBrowser(db *storm.DB) *types.FileBrowser { func getFileBrowser(db *storm.DB) *lib.FileBrowser {
fb, err := types.NewFileBrowser(&bolt.Backend{DB: db}) fb, err := lib.NewFileBrowser(&bolt.Backend{DB: db})
checkErr(err) checkErr(err)
return fb return fb
} }

View File

@ -3,7 +3,7 @@ package cmd
import ( import (
"fmt" "fmt"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -15,6 +15,6 @@ var versionCmd = &cobra.Command{
Use: "version", Use: "version",
Short: "Print the version number", Short: "Print the version number",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Println("File Browser Version " + types.Version) fmt.Println("File Browser Version " + lib.Version)
}, },
} }

View File

@ -9,13 +9,13 @@ import (
"github.com/dgrijalva/jwt-go" "github.com/dgrijalva/jwt-go"
"github.com/dgrijalva/jwt-go/request" "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) { func (e *Env) loginHandler(w http.ResponseWriter, r *http.Request) {
user, err := e.Auther.Auth(r) user, err := e.Auther.Auth(r)
if err == types.ErrNoPermission { if err == lib.ErrNoPermission {
httpErr(w, r, http.StatusForbidden, nil) httpErr(w, r, http.StatusForbidden, nil)
} else if err != nil { } else if err != nil {
httpErr(w, r, http.StatusInternalServerError, err) httpErr(w, r, http.StatusInternalServerError, err)
@ -58,13 +58,13 @@ func (e *Env) signupHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
user := &types.User{ user := &lib.User{
Username: info.Username, Username: info.Username,
} }
e.ApplyDefaults(user) e.ApplyDefaults(user)
pwd, err := types.HashPwd(info.Password) pwd, err := lib.HashPwd(info.Password)
if err != nil { if err != nil {
httpErr(w, r, http.StatusInternalServerError, err) httpErr(w, r, http.StatusInternalServerError, err)
return return
@ -72,7 +72,7 @@ func (e *Env) signupHandler(w http.ResponseWriter, r *http.Request) {
user.Password = pwd user.Password = pwd
err = e.SaveUser(user) err = e.SaveUser(user)
if err == types.ErrExist { if err == lib.ErrExist {
httpErr(w, r, http.StatusConflict, nil) httpErr(w, r, http.StatusConflict, nil)
return return
} else if err != nil { } else if err != nil {
@ -86,8 +86,8 @@ func (e *Env) signupHandler(w http.ResponseWriter, r *http.Request) {
type userInfo struct { type userInfo struct {
ID uint `json:"id"` ID uint `json:"id"`
Locale string `json:"locale"` Locale string `json:"locale"`
ViewMode types.ViewMode `json:"viewMode"` ViewMode lib.ViewMode `json:"viewMode"`
Perm types.Permissions `json:"perm"` Perm lib.Permissions `json:"perm"`
Commands []string `json:"commands"` Commands []string `json:"commands"`
LockPassword bool `json:"lockPassword"` LockPassword bool `json:"lockPassword"`
} }
@ -154,7 +154,7 @@ func (e *Env) renew(w http.ResponseWriter, r *http.Request) {
e.printToken(w, r, user) 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{ claims := &authToken{
User: userInfo{ User: userInfo{
ID: user.ID, ID: user.ID,

View File

@ -7,7 +7,7 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
) )
@ -25,8 +25,8 @@ type modifyRequest struct {
// Env contains the required info for FB to run. // Env contains the required info for FB to run.
type Env struct { type Env struct {
*types.FileBrowser *lib.FileBrowser
Auther types.Auther Auther lib.Auther
} }
// Handler ... // 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) id := r.Context().Value(keyUserID).(uint)
user, err := e.GetUser(id) user, err := e.GetUser(id)
if err == types.ErrNotExist { if err == lib.ErrNotExist {
httpErr(w, r, http.StatusForbidden, nil) httpErr(w, r, http.StatusForbidden, nil)
return nil, false return nil, false
} }
@ -115,7 +115,7 @@ func (e *Env) getUser(w http.ResponseWriter, r *http.Request) (*types.User, bool
return user, true 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) user, ok := e.getUser(w, r)
if !ok { if !ok {
return nil, false return nil, false

View File

@ -7,14 +7,14 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
"github.com/hacdias/fileutils" "github.com/hacdias/fileutils"
"github.com/mholt/archiver" "github.com/mholt/archiver"
) )
const apiRawPrefix = "/api/raw" 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{} files := []string{}
names := strings.Split(r.URL.Query().Get("files"), ",") 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) fd, err := user.Fs.Open(file.Path)
if err != nil { if err != nil {
httpErr(w, r, http.StatusInternalServerError, err) httpErr(w, r, http.StatusInternalServerError, err)

View File

@ -10,7 +10,7 @@ import (
"strings" "strings"
"github.com/filebrowser/filebrowser/fileutils" "github.com/filebrowser/filebrowser/fileutils"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
) )
const apiResourcePrefix = "/api/resources" 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) user, ok := e.getUser(w, r)
if !ok { if !ok {
return "", nil, 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 != "" { if checksum := r.URL.Query().Get("checksum"); checksum != "" {
err = e.Checksum(file,user, checksum) err = e.Checksum(file,user, checksum)
if err == types.ErrInvalidOption { if err == lib.ErrInvalidOption {
httpErr(w, r, http.StatusBadRequest, nil) httpErr(w, r, http.StatusBadRequest, nil)
return return
} else if err != nil { } else if err != nil {

View File

@ -4,15 +4,15 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
) )
type settingsData struct { type settingsData struct {
Signup bool `json:"signup"` Signup bool `json:"signup"`
Defaults types.UserDefaults `json:"defaults"` Defaults lib.UserDefaults `json:"defaults"`
Rules []types.Rule `json:"rules"` Rules []lib.Rule `json:"rules"`
Branding types.Branding `json:"branding"` Branding lib.Branding `json:"branding"`
Shell []string `json:"shell"` Shell []string `json:"shell"`
Commands map[string][]string `json:"commands"` Commands map[string][]string `json:"commands"`
} }
@ -52,7 +52,7 @@ func (e *Env) settingsPutHandler(w http.ResponseWriter, r *http.Request) {
} }
e.RLockSettings() e.RLockSettings()
settings := &types.Settings{} settings := &lib.Settings{}
err = copier.Copy(settings, e.GetSettings()) err = copier.Copy(settings, e.GetSettings())
e.RUnlockSettings() e.RUnlockSettings()

View File

@ -8,7 +8,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
) )
const apiSharePrefix = "/api/share" const apiSharePrefix = "/api/share"
@ -34,8 +34,8 @@ func (e *Env) shareGetHandler(w http.ResponseWriter, r *http.Request) {
} }
s, err := e.GetLinksByPath(path) s, err := e.GetLinksByPath(path)
if err == types.ErrNotExist { if err == lib.ErrNotExist {
renderJSON(w, r, []*types.ShareLink{}) renderJSON(w, r, []*lib.ShareLink{})
return return
} }
@ -85,7 +85,7 @@ func (e *Env) sharePostHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
var s *types.ShareLink var s *lib.ShareLink
expire := r.URL.Query().Get("expires") expire := r.URL.Query().Get("expires")
unit := r.URL.Query().Get("unit") 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) str := base64.URLEncoding.EncodeToString(bytes)
s = &types.ShareLink{ s = &lib.ShareLink{
Path: path, Path: path,
Hash: str, Hash: str,
Expires: expire != "", Expires: expire != "",

View File

@ -11,7 +11,7 @@ import (
"github.com/GeertJohan/go.rice" "github.com/GeertJohan/go.rice"
"github.com/filebrowser/filebrowser/auth" "github.com/filebrowser/filebrowser/auth"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
) )
func (e *Env) getStaticData() map[string]interface{} { func (e *Env) getStaticData() map[string]interface{} {
@ -26,7 +26,7 @@ func (e *Env) getStaticData() map[string]interface{} {
"Name": settings.Branding.Name, "Name": settings.Branding.Name,
"DisableExternal": settings.Branding.DisableExternal, "DisableExternal": settings.Branding.DisableExternal,
"BaseURL": settings.BaseURL, "BaseURL": settings.BaseURL,
"Version": types.Version, "Version": lib.Version,
"StaticURL": staticURL, "StaticURL": staticURL,
"Signup": settings.Signup, "Signup": settings.Signup,
"NoAuth": settings.AuthMethod == auth.MethodNoAuth, "NoAuth": settings.AuthMethod == auth.MethodNoAuth,

View File

@ -7,7 +7,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/filebrowser/filebrowser/types" "github.com/filebrowser/filebrowser/lib"
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
@ -22,7 +22,7 @@ func getUserID(r *http.Request) (uint, error) {
type modifyUserRequest struct { type modifyUserRequest struct {
modifyRequest modifyRequest
Data *types.User `json:"data"` Data *lib.User `json:"data"`
} }
func getUser(w http.ResponseWriter, r *http.Request) (*modifyUserRequest, bool) { 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) 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) user, ok := e.getUser(w, r)
if !ok { if !ok {
return nil, 0, false return nil, 0, false
@ -101,7 +101,7 @@ func (e *Env) userGetHandler(w http.ResponseWriter, r *http.Request) {
} }
u, err := e.GetUser(id) u, err := e.GetUser(id)
if err == types.ErrNotExist { if err == lib.ErrNotExist {
httpErr(w, r, http.StatusNotFound, nil) httpErr(w, r, http.StatusNotFound, nil)
return return
} }
@ -122,7 +122,7 @@ func (e *Env) userDeleteHandler(w http.ResponseWriter, r *http.Request) {
} }
err := e.DeleteUser(id) err := e.DeleteUser(id)
if err == types.ErrNotExist { if err == lib.ErrNotExist {
httpErr(w, r, http.StatusNotFound, nil) httpErr(w, r, http.StatusNotFound, nil)
return return
} }
@ -149,12 +149,12 @@ func (e *Env) userPostHandler(w http.ResponseWriter, r *http.Request) {
} }
if req.Data.Password == "" { if req.Data.Password == "" {
httpErr(w, r, http.StatusBadRequest, types.ErrEmptyPassword) httpErr(w, r, http.StatusBadRequest, lib.ErrEmptyPassword)
return return
} }
var err error var err error
req.Data.Password, err = types.HashPwd(req.Data.Password) req.Data.Password, err = lib.HashPwd(req.Data.Password)
if err != nil { if err != nil {
httpErr(w, r, http.StatusInternalServerError, err) httpErr(w, r, http.StatusInternalServerError, err)
return return
@ -195,9 +195,9 @@ func (e *Env) userPutHandler(w http.ResponseWriter, r *http.Request) {
} }
if req.Data.Password != "" { if req.Data.Password != "" {
req.Data.Password, err = types.HashPwd(req.Data.Password) req.Data.Password, err = lib.HashPwd(req.Data.Password)
} else { } else {
var suser *types.User var suser *lib.User
suser, err = e.GetUser(modifiedID) suser, err = e.GetUser(modifiedID)
req.Data.Password = suser.Password req.Data.Password = suser.Password
} }
@ -217,7 +217,7 @@ func (e *Env) userPutHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
req.Data.Password, err = types.HashPwd(req.Data.Password) req.Data.Password, err = lib.HashPwd(req.Data.Password)
if err != nil { if err != nil {
httpErr(w, r, http.StatusInternalServerError, err) httpErr(w, r, http.StatusInternalServerError, err)
return return

View File

@ -1,4 +1,4 @@
package types package lib
import "net/http" import "net/http"

View File

@ -1,4 +1,4 @@
package types package lib
import "errors" import "errors"

View File

@ -1,4 +1,4 @@
package types package lib
import ( import (
"crypto/md5" "crypto/md5"

View File

@ -1,4 +1,4 @@
package types package lib
import ( import (
"os" "os"

View File

@ -1,4 +1,4 @@
package types package lib
import ( import (
"regexp" "regexp"

View File

@ -1,4 +1,4 @@
package types package lib
// Settings contain the main settings of the application. // Settings contain the main settings of the application.
type Settings struct { type Settings struct {

View File

@ -1,4 +1,4 @@
package types package lib
import "time" import "time"

View File

@ -1,4 +1,4 @@
package types package lib
import ( import (
"strings" "strings"

View File

@ -1,4 +1,4 @@
package types package lib
import ( import (
"path/filepath" "path/filepath"

View File

@ -1,4 +1,4 @@
package types package lib
import ( import (
"crypto/rand" "crypto/rand"

View File

@ -1,4 +1,4 @@
package types package lib
const ( const (
// Version is the current File Browser version. // Version is the current File Browser version.