reduces cyclomatic complexity by actually using data already in scope
This commit is contained in:
parent
dba8d53c9f
commit
01c16aeb91
@ -37,8 +37,7 @@ func wsErr(ws *websocket.Conn, r *http.Request, status int, err error) { //nolin
|
||||
}
|
||||
}
|
||||
|
||||
func commandsHandler (enableExec bool) handleFunc {
|
||||
return withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
|
||||
var commandsHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
|
||||
conn, err := upgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
@ -60,7 +59,7 @@ func commandsHandler (enableExec bool) handleFunc {
|
||||
}
|
||||
}
|
||||
|
||||
if !enableExec || !d.user.CanExecute(strings.Split(raw, " ")[0]) {
|
||||
if !d.server.EnableExec || !d.user.CanExecute(strings.Split(raw, " ")[0]) {
|
||||
if err := conn.WriteMessage(websocket.TextMessage, cmdNotAllowed); err != nil { //nolint:shadow
|
||||
wsErr(conn, r, http.StatusInternalServerError, err)
|
||||
}
|
||||
@ -108,5 +107,4 @@ func commandsHandler (enableExec bool) handleFunc {
|
||||
}
|
||||
|
||||
return 0, nil
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@ -61,7 +61,7 @@ func NewHandler(imgSvc ImgService, fileCache FileCache, store *storage.Storage,
|
||||
api.PathPrefix("/raw").Handler(monkey(rawHandler, "/api/raw")).Methods("GET")
|
||||
api.PathPrefix("/preview/{size}/{path:.*}").
|
||||
Handler(monkey(previewHandler(imgSvc, fileCache, server.EnableThumbnails, server.ResizePreview), "/api/preview")).Methods("GET")
|
||||
api.PathPrefix("/command").Handler(monkey(commandsHandler(server.EnableExec), "/api/command")).Methods("GET")
|
||||
api.PathPrefix("/command").Handler(monkey(commandsHandler, "/api/command")).Methods("GET")
|
||||
api.PathPrefix("/search").Handler(monkey(searchHandler, "/api/search")).Methods("GET")
|
||||
|
||||
public := api.PathPrefix("/public").Subrouter()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user