Skip to content

Commit

Permalink
refactor creation of new request
Browse files Browse the repository at this point in the history
  • Loading branch information
tenox7 committed Nov 29, 2022
1 parent 02350c9 commit 3998441
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,26 @@ type wfmRequest struct {
}

func wfmMain(w http.ResponseWriter, r *http.Request) {
wfm := new(wfmRequest)
r.ParseMultipartForm(10 << 20)
wfm.userName, wfm.rwAccess = auth(w, r)
if wfm.userName == "" {
uName, uAccess := auth(w, r)
if uName == "" {
return
}
go log.Printf("req from=%q user=%q uri=%q form=%v", r.RemoteAddr, wfm.userName, r.RequestURI, noText(r.Form))
go log.Printf("req from=%q user=%q uri=%q form=%v", r.RemoteAddr, uName, r.RequestURI, noText(r.Form))

// TODO(tenox): allow fs per user
wfm.fs = wfmFs
wfm.w = w
wfm.remAddr = r.RemoteAddr
wfm.eSort = r.FormValue("sort")
if strings.HasPrefix(r.UserAgent(), "Mozilla/5") {
wfm.modern = true
wfm := &wfmRequest{
userName: uName,
rwAccess: uAccess,
remAddr: r.RemoteAddr,
w: w,
eSort: r.FormValue("sort"),
modern: strings.HasPrefix(r.UserAgent(), "Mozilla/5"),
fs: wfmFs, // TODO(tenox): per user FS/homedir
uFbn: filepath.Base(r.FormValue("file")),
uDir: filepath.Clean(r.FormValue("dir")),
}
wfm.uFbn = filepath.Base(r.FormValue("file"))
wfm.uDir = filepath.Clean(r.FormValue("dir"))
// directory can come from form value or URI Path

// directory can come either from form value or URI Path
if wfm.uDir == "" || wfm.uDir == "." {
// TODO(tenox): use url.Parse() instead
u, _ := url.PathUnescape(r.URL.Path)
Expand Down

0 comments on commit 3998441

Please sign in to comment.