66 "mjpclab.dev/ghfs/src/i18n"
77 "mjpclab.dev/ghfs/src/util"
88 "net/http"
9+ "net/url"
910 "os"
1011 "path"
1112 "path/filepath"
@@ -81,6 +82,8 @@ type sessionContext struct {
8182
8283 file * os.File
8384
85+ query url.Values
86+
8487 errors []error
8588}
8689
@@ -355,11 +358,11 @@ func (h *aliasHandler) getSessionData(r *http.Request) (session *sessionContext,
355358 reqPath := util .CleanUrlPath (vhostReqPath [len (h .url ):])
356359 fsPath := filepath .Clean (h .dir + reqPath )
357360
358- rawQuery := r .URL .RawQuery
361+ query := r .URL .Query ()
359362
360363 status := http .StatusOK
361364
362- needAuth , requestAuth := h .needAuth (rawQuery , vhostReqPath , fsPath )
365+ needAuth , requestAuth := h .needAuth (query , vhostReqPath , fsPath )
363366 authUserId , authUserName , _authErr := h .verifyAuth (r , vhostReqPath , fsPath )
364367 authSuccess := ! needAuth || _authErr == nil
365368 if ! authSuccess {
@@ -369,47 +372,39 @@ func (h *aliasHandler) getSessionData(r *http.Request) (session *sessionContext,
369372
370373 headers := h .getHeaders (vhostReqPath , fsPath , authSuccess )
371374
372- isSimple := false
373- isDownload := false
375+ isMutate := false
374376 isUpload := false
375377 isMkdir := false
376378 isDelete := false
377- isMutate := false
378379 switch {
379- case strings .HasPrefix (rawQuery , "simpledownload" ):
380- isSimple = true
381- isDownload = true
382- case strings .HasPrefix (rawQuery , "simple" ):
383- isSimple = true
384- case strings .HasPrefix (rawQuery , "download" ):
385- isDownload = true
386- case strings .HasPrefix (rawQuery , "upload" ) && r .Method == http .MethodPost :
380+ case query .Has ("upload" ):
381+ isMutate = true
387382 isUpload = true
383+ case query .Has ("mkdir" ):
388384 isMutate = true
389- case strings .HasPrefix (rawQuery , "mkdir" ):
390385 isMkdir = true
386+ case query .Has ("delete" ):
391387 isMutate = true
392- case strings .HasPrefix (r .URL .RawQuery , "delete" ):
393388 isDelete = true
394- isMutate = true
395389 }
396390
397391 isArchive := false
398392 var arFmt archiveFormat
399- if len (rawQuery ) == 3 || (len (rawQuery ) > 3 && rawQuery [3 ] == '&' ) {
400- switch rawQuery [:3 ] {
401- case "tar" :
402- isArchive = true
403- arFmt = tarFmt
404- case "tgz" :
405- isArchive = true
406- arFmt = tgzFmt
407- case "zip" :
408- isArchive = true
409- arFmt = zipFmt
410- }
393+ switch {
394+ case query .Has ("tar" ):
395+ isArchive = true
396+ arFmt = tarFmt
397+ case query .Has ("tgz" ):
398+ isArchive = true
399+ arFmt = tgzFmt
400+ case query .Has ("zip" ):
401+ isArchive = true
402+ arFmt = zipFmt
411403 }
412404
405+ isSimple := query .Has ("simple" )
406+ isDownload := query .Has ("download" )
407+
413408 accepts := acceptHeaders .ParseAccepts (r .Header .Get ("Accept" ))
414409 acceptIndex , _ , _ := accepts .GetPreferredValue (acceptContentTypes )
415410 wantJson := acceptIndex == acceptJsonIndex
@@ -489,7 +484,7 @@ func (h *aliasHandler) getSessionData(r *http.Request) (session *sessionContext,
489484 }
490485
491486 subItems = h .FilterItems (subItems )
492- rawSortBy , sortState := sortInfos (subItems , rawQuery , h .defaultSort )
487+ rawSortBy , sortState := sortInfos (subItems , query . Get ( "sort" ) , h .defaultSort )
493488
494489 if h .emptyRoot && status == http .StatusOK && len (vhostReqPath ) > 1 {
495490 status = http .StatusNotFound
@@ -535,6 +530,8 @@ func (h *aliasHandler) getSessionData(r *http.Request) (session *sessionContext,
535530
536531 file : file ,
537532
533+ query : query ,
534+
538535 errors : errs ,
539536 }
540537 data = & responseData {
0 commit comments