2017-10-30 23:47:59 +08:00
|
|
|
/*
|
2018-02-01 21:38:43 +08:00
|
|
|
Package filebrowser provides a web interface to access your files
|
2017-10-30 23:47:59 +08:00
|
|
|
wherever you are. To use this package as a middleware for your app,
|
2018-04-24 05:42:52 +08:00
|
|
|
you'll need to import both File Browser and File Browser HTTP packages.
|
2017-10-30 23:47:59 +08:00
|
|
|
|
|
|
|
import (
|
2018-02-01 21:38:43 +08:00
|
|
|
fm "github.com/filebrowser/filebrowser"
|
|
|
|
h "github.com/filebrowser/filebrowser/http"
|
2017-10-30 23:47:59 +08:00
|
|
|
)
|
|
|
|
|
2018-02-01 21:38:43 +08:00
|
|
|
Then, you should create a new FileBrowser object with your options. In this
|
2017-10-30 23:47:59 +08:00
|
|
|
case, I'm using BoltDB (via Storm package) as a Store. So, you'll also need
|
2018-02-01 21:38:43 +08:00
|
|
|
to import "github.com/filebrowser/filebrowser/bolt".
|
2017-10-30 23:47:59 +08:00
|
|
|
|
|
|
|
db, _ := storm.Open("bolt.db")
|
|
|
|
|
2018-02-01 21:38:43 +08:00
|
|
|
m := &fm.FileBrowser{
|
2017-10-30 23:47:59 +08:00
|
|
|
NoAuth: false,
|
2018-08-08 17:06:16 +08:00
|
|
|
Auth: {
|
|
|
|
Method: "default",
|
|
|
|
LoginHeader: "X-Fowarded-User"
|
|
|
|
},
|
2017-10-30 23:47:59 +08:00
|
|
|
DefaultUser: &fm.User{
|
|
|
|
AllowCommands: true,
|
|
|
|
AllowEdit: true,
|
|
|
|
AllowNew: true,
|
|
|
|
AllowPublish: true,
|
|
|
|
Commands: []string{"git"},
|
|
|
|
Rules: []*fm.Rule{},
|
|
|
|
Locale: "en",
|
|
|
|
CSS: "",
|
|
|
|
Scope: ".",
|
|
|
|
FileSystem: fileutils.Dir("."),
|
|
|
|
},
|
|
|
|
Store: &fm.Store{
|
|
|
|
Config: bolt.ConfigStore{DB: db},
|
|
|
|
Users: bolt.UsersStore{DB: db},
|
|
|
|
Share: bolt.ShareStore{DB: db},
|
|
|
|
},
|
|
|
|
NewFS: func(scope string) fm.FileSystem {
|
|
|
|
return fileutils.Dir(scope)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
The credentials for the first user are always 'admin' for both the user and
|
|
|
|
the password, and they can be changed later through the settings. The first
|
|
|
|
user is always an Admin and has all of the permissions set to 'true'.
|
|
|
|
|
|
|
|
Then, you should set the Prefix URL and the Base URL, using the following
|
|
|
|
functions:
|
|
|
|
|
|
|
|
m.SetBaseURL("/")
|
|
|
|
m.SetPrefixURL("/")
|
|
|
|
|
|
|
|
The Prefix URL is a part of the path that is already stripped from the
|
2018-04-24 05:42:52 +08:00
|
|
|
r.URL.Path variable before the request arrives to File Browser's handler.
|
2017-10-30 23:47:59 +08:00
|
|
|
This is a function that will rarely be used. You can see one example on Caddy
|
|
|
|
filemanager plugin.
|
|
|
|
|
2018-04-24 05:42:52 +08:00
|
|
|
The Base URL is the URL path where you want File Browser to be available in. If
|
2017-10-30 23:47:59 +08:00
|
|
|
you want to be available at the root path, you should call:
|
|
|
|
|
|
|
|
m.SetBaseURL("/")
|
|
|
|
|
|
|
|
But if you want to access it at '/admin', you would call:
|
|
|
|
|
|
|
|
m.SetBaseURL("/admin")
|
|
|
|
|
2018-04-24 05:42:52 +08:00
|
|
|
Now, that you already have a File Browser instance created, you just need to
|
2017-10-30 23:47:59 +08:00
|
|
|
add it to your handlers using m.ServeHTTP which is compatible to http.Handler.
|
|
|
|
We also have a m.ServeWithErrorsHTTP that returns the status code and an error.
|
|
|
|
|
|
|
|
One simple implementation for this, at port 80, in the root of the domain, would be:
|
|
|
|
|
|
|
|
http.ListenAndServe(":80", h.Handler(m))
|
|
|
|
*/
|
2018-08-22 05:42:03 +08:00
|
|
|
package lib
|