@@ -12,12 +12,22 @@ import (
1212 "strings"
1313)
1414
15+ type redirectAction int
16+
1517const (
1618 noRedirect redirectAction = iota
1719 addSlashSuffix
1820 removeSlashSuffix
1921)
2022
23+ type archiveFormat int
24+
25+ const (
26+ tarFmt archiveFormat = iota
27+ tgzFmt
28+ zipFmt
29+ )
30+
2131const contentTypeJson = "application/json"
2232
2333var acceptContentTypes = []string {
@@ -41,8 +51,6 @@ type itemHtml struct {
4151 DeleteUrl string
4252}
4353
44- type redirectAction int
45-
4654type sessionContext struct {
4755 prefixReqPath string
4856 vhostReqPath string
@@ -62,6 +70,14 @@ type sessionContext struct {
6270
6371 wantJson bool
6472
73+ isUpload bool
74+ isMkdir bool
75+ isDelete bool
76+ isMutate bool
77+
78+ isArchive bool
79+ archiveFormat archiveFormat
80+
6581 file * os.File
6682
6783 errors []error
@@ -72,12 +88,6 @@ type responseData struct {
7288
7389 IsDownload bool
7490 IsDownloadFile bool
75- IsUpload bool
76- IsMkdir bool
77- IsDelete bool
78- IsMutate bool
79- IsArchive bool
80- ArchiveFormat string
8191
8292 CanIndex bool
8393 CanUpload bool
@@ -382,19 +392,18 @@ func (h *aliasHandler) getSessionData(r *http.Request) (session *sessionContext,
382392 }
383393
384394 isArchive := false
385- archiveFormat := ""
395+ var arFmt archiveFormat
386396 if len (rawQuery ) == 3 || (len (rawQuery ) > 3 && rawQuery [3 ] == '&' ) {
387- rawQuery3 := rawQuery [:3 ]
388- switch rawQuery3 {
397+ switch rawQuery [:3 ] {
389398 case "tar" :
390399 isArchive = true
391- archiveFormat = rawQuery3
400+ arFmt = tarFmt
392401 case "tgz" :
393402 isArchive = true
394- archiveFormat = rawQuery3
403+ arFmt = tgzFmt
395404 case "zip" :
396405 isArchive = true
397- archiveFormat = rawQuery3
406+ arFmt = zipFmt
398407 }
399408 }
400409
@@ -494,13 +503,6 @@ func (h *aliasHandler) getSessionData(r *http.Request) (session *sessionContext,
494503 canCors := allowAccess && authSuccess && h .cors .match (vhostReqPath , fsPath , authUserId )
495504 loginAvail := len (authUserName ) == 0 && h .users .Len () > 0
496505
497- context := pathContext {
498- download : isDownload ,
499- downloadfile : isDownloadFile ,
500- sort : rawSortBy ,
501- defaultSort : h .defaultSort ,
502- }
503-
504506 session = & sessionContext {
505507 prefixReqPath : prefixReqPath ,
506508 vhostReqPath : vhostReqPath ,
@@ -520,6 +522,14 @@ func (h *aliasHandler) getSessionData(r *http.Request) (session *sessionContext,
520522
521523 wantJson : wantJson ,
522524
525+ isUpload : isUpload ,
526+ isMkdir : isMkdir ,
527+ isDelete : isDelete ,
528+ isMutate : isMutate ,
529+
530+ isArchive : isArchive ,
531+ archiveFormat : arFmt ,
532+
523533 file : file ,
524534
525535 errors : errs ,
@@ -529,12 +539,6 @@ func (h *aliasHandler) getSessionData(r *http.Request) (session *sessionContext,
529539
530540 IsDownload : isDownload ,
531541 IsDownloadFile : isDownloadFile ,
532- IsUpload : isUpload ,
533- IsMkdir : isMkdir ,
534- IsDelete : isDelete ,
535- IsMutate : isMutate ,
536- IsArchive : isArchive ,
537- ArchiveFormat : archiveFormat ,
538542
539543 CanIndex : canIndex ,
540544 CanUpload : canUpload ,
@@ -559,7 +563,12 @@ func (h *aliasHandler) getSessionData(r *http.Request) (session *sessionContext,
559563 SubItemsHtml : nil ,
560564 SubItemPrefix : subItemPrefix ,
561565 SortState : sortState ,
562- Context : context ,
566+ Context : pathContext {
567+ download : isDownload ,
568+ downloadfile : isDownloadFile ,
569+ sort : rawSortBy ,
570+ defaultSort : h .defaultSort ,
571+ },
563572 }
564573 return
565574}
0 commit comments