You've already forked filebrowser
mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-11-26 14:25:26 +08:00
Better Plugin Parsing
Former-commit-id: 8f0d86770072714575223249ab59cb0bcb11d1af [formerly 745c8318de08dc06bd9eece0d185528e4ed0872c] [formerly 61cda90693313822ad2e106dbc5a64104f2b5716 [formerly 722ca4b47f]]
Former-commit-id: c2dad3e81d44f3a92c61d3c21eb6d2113b333ed4 [formerly 898013a275bf0e2b86395f3fa8d5479b08c692d8]
Former-commit-id: 6e7c0f06a65cecdb2307df35db361f24d2353e00
This commit is contained in:
24
settings.go
24
settings.go
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
@@ -63,12 +64,33 @@ func pluginsHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (
|
||||
return http.StatusMethodNotAllowed, nil
|
||||
}
|
||||
|
||||
type pluginOption struct {
|
||||
Variable string `json:"variable"`
|
||||
Name string `json:"name"`
|
||||
Value interface{} `json:"value"`
|
||||
}
|
||||
|
||||
func pluginsGetHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
if !c.User.Admin {
|
||||
return http.StatusForbidden, nil
|
||||
}
|
||||
|
||||
return renderJSON(w, c.FM.Plugins)
|
||||
plugins := map[string][]pluginOption{}
|
||||
|
||||
for name, p := range c.FM.Plugins {
|
||||
plugins[name] = []pluginOption{}
|
||||
|
||||
t := reflect.TypeOf(p).Elem()
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
plugins[name] = append(plugins[name], pluginOption{
|
||||
Variable: t.Field(i).Name,
|
||||
Name: t.Field(i).Tag.Get("name"),
|
||||
Value: reflect.ValueOf(p).Elem().FieldByName(t.Field(i).Name).Interface(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return renderJSON(w, plugins)
|
||||
}
|
||||
|
||||
func pluginsPutHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
|
||||
Reference in New Issue
Block a user