mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
Add Commands option
Former-commit-id: 2fd6defee4579de1aa0b59335f6f98efb269f4df [formerly c42dfd64305c057bb8910983a42418328157a1ee] [formerly dfaf23ff66681114a04bca84c7cb13667b52499e [formerly 66a32dc331
]]
Former-commit-id: 01fb2c6ec83c134619696cafefbdcdd7ce2b0b61 [formerly 2b42ee8c84ba52c44928bd35a04964718dbd72ee]
Former-commit-id: db59756eff3f49cfdf04eb6147e37867963f7090
This commit is contained in:
parent
b4067cc423
commit
a072d47f5b
@ -143,10 +143,6 @@ func New(database string, base User) (*FileManager, error) {
|
||||
assets: rice.MustFindBox("./assets/dist"),
|
||||
}
|
||||
|
||||
m.Commands = map[string][]string{
|
||||
"before_save": []string{"cmd /c \"echo %file%\""},
|
||||
}
|
||||
|
||||
// Tries to open a database on the location provided. This
|
||||
// function will automatically create a new one if it doesn't
|
||||
// exist.
|
||||
@ -167,6 +163,21 @@ func New(database string, base User) (*FileManager, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Tries to get the event commands from the database.
|
||||
// If they don't exist, initialize them.
|
||||
err = db.Get("config", "commands", &m.Commands)
|
||||
if err != nil && err == storm.ErrNotFound {
|
||||
m.Commands = map[string][]string{
|
||||
"before_save": []string{},
|
||||
"after_save": []string{},
|
||||
}
|
||||
err = db.Set("config", "commands", m.Commands)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Tries to fetch the users from the database and if there are
|
||||
// any, add them to the current File Manager instance.
|
||||
var users []User
|
||||
@ -285,7 +296,7 @@ func (r *Regexp) MatchString(s string) bool {
|
||||
return r.regexp.MatchString(s)
|
||||
}
|
||||
|
||||
// Runner ...
|
||||
// Runner runs the commands for a certain event type.
|
||||
func (m FileManager) Runner(event string, path string) error {
|
||||
for _, command := range m.Commands[event] {
|
||||
args := strings.Split(command, " ")
|
||||
|
Loading…
Reference in New Issue
Block a user