mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2026-10-19 16:14:39 +00:00
chore (refactoring): cleanup middleware
This commit is contained in:
@@ -5,8 +5,8 @@ import (
|
||||
"time"
|
||||
_ "unsafe"
|
||||
|
||||
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
|
||||
. "github.com/mickael-kerjean/filestash/server/pkg/core"
|
||||
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -21,16 +21,15 @@ func init() {
|
||||
}
|
||||
|
||||
func NewMiddlewareChain(fn HandlerFunc, m []Middleware) http.HandlerFunc {
|
||||
for i := len(m) - 1; i >= 0; i-- {
|
||||
fn = m[i](fn)
|
||||
}
|
||||
return func(res http.ResponseWriter, req *http.Request) {
|
||||
var f func(*App, http.ResponseWriter, *http.Request) = fn
|
||||
for i := len(m) - 1; i >= 0; i-- {
|
||||
f = m[i](f)
|
||||
}
|
||||
var (
|
||||
app = App{Context: req.Context()}
|
||||
resw = NewResponseWriter(res)
|
||||
)
|
||||
f(&app, &resw, req)
|
||||
fn(&app, &resw, req)
|
||||
if req.Body != nil {
|
||||
req.Body.Close()
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
package share
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"encoding/base64"
|
||||
"strings"
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
. "github.com/mickael-kerjean/filestash/server/pkg/config"
|
||||
. "github.com/mickael-kerjean/filestash/server/pkg/core"
|
||||
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
|
||||
"github.com/mickael-kerjean/filestash/server/pkg/env"
|
||||
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func FromRequest(req *http.Request) (Share, error) {
|
||||
var err error
|
||||
share_id := _extractShareId(req)
|
||||
if share_id == "" {
|
||||
shareID := _extractShareId(req)
|
||||
if shareID == "" {
|
||||
return Share{}, nil
|
||||
}
|
||||
if Config.Get("features.share.enable").Bool() == false {
|
||||
@@ -26,7 +26,7 @@ func FromRequest(req *http.Request) (Share, error) {
|
||||
return Share{}, NewError("Feature isn't enabled, contact your administrator", 405)
|
||||
}
|
||||
|
||||
s, err := ShareGet(share_id)
|
||||
s, err := ShareGet(shareID)
|
||||
if err != nil {
|
||||
return Share{}, nil
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"strings"
|
||||
|
||||
. "github.com/mickael-kerjean/filestash/server/pkg/config"
|
||||
. "github.com/mickael-kerjean/filestash/server/pkg/env"
|
||||
"github.com/mickael-kerjean/filestash/server/pkg/cookie"
|
||||
. "github.com/mickael-kerjean/filestash/server/pkg/env"
|
||||
)
|
||||
|
||||
func From(req *http.Request) string {
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
|
||||
. "github.com/mickael-kerjean/filestash/server/common"
|
||||
"github.com/mickael-kerjean/filestash/server/middleware"
|
||||
"github.com/mickael-kerjean/filestash/server/model"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/patrickmn/go-cache"
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"sync"
|
||||
|
||||
. "github.com/mickael-kerjean/filestash/server/common"
|
||||
. "github.com/mickael-kerjean/filestash/server/model"
|
||||
. "github.com/mickael-kerjean/filestash/server/plugin/plg_search_sqlitefts/config"
|
||||
. "github.com/mickael-kerjean/filestash/server/plugin/plg_search_sqlitefts/crawler"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user