@@ -32,6 +32,20 @@ type responseData struct {
3232 AuthUserName string
3333 AuthSuccess bool
3434
35+ IsDownload bool
36+ IsUpload bool
37+ IsMkdir bool
38+ IsDelete bool
39+ IsMutate bool
40+ WantJson bool
41+
42+ CanUpload bool
43+ CanMkdir bool
44+ CanDelete bool
45+ HasDeletable bool
46+ CanArchive bool
47+ CanCors bool
48+
3549 errors []error
3650 Status int
3751
@@ -49,20 +63,6 @@ type responseData struct {
4963 SortState SortState
5064 Context * pathContext
5165
52- CanUpload bool
53- CanMkdir bool
54- CanDelete bool
55- HasDeletable bool
56- CanArchive bool
57- CanCors bool
58-
59- IsDownload bool
60- IsUpload bool
61- IsMkdir bool
62- IsDelete bool
63- IsMutate bool
64- WantJson bool
65-
6666 Lang string
6767 Trans * i18n.Translation
6868}
@@ -280,10 +280,30 @@ func (h *handler) getResponseData(r *http.Request) *responseData {
280280 authUserName , authSuccess = h .verifyAuth (r )
281281 }
282282
283+ rawQuery := r .URL .RawQuery
284+ isDownload := false
285+ isUpload := false
286+ isMkdir := false
287+ isDelete := false
288+ isMutate := false
289+ switch {
290+ case strings .HasPrefix (rawQuery , "download" ):
291+ isDownload = true
292+ case strings .HasPrefix (rawQuery , "upload" ) && r .Method == http .MethodPost :
293+ isUpload = true
294+ isMutate = true
295+ case strings .HasPrefix (rawQuery , "mkdir" ):
296+ isMkdir = true
297+ isMutate = true
298+ case strings .HasPrefix (r .URL .RawQuery , "delete" ):
299+ isDelete = true
300+ isMutate = true
301+ }
302+ wantJson := strings .HasPrefix (rawQuery , "json" ) || strings .Contains (rawQuery , "&json" )
303+
283304 errs := []error {}
284305 status := http .StatusOK
285306 isRoot := rawReqPath == "/"
286- rawQuery := r .URL .RawQuery
287307
288308 pathEntries := getPathEntries (rawReqPath , tailSlash )
289309 var rootRelPath string
@@ -315,7 +335,7 @@ func (h *handler) getResponseData(r *http.Request) *responseData {
315335
316336 itemName := getItemName (item , r )
317337
318- subItems , _readdirErr := readdir (file , item , authSuccess && needResponseBody (r .Method ))
338+ subItems , _readdirErr := readdir (file , item , authSuccess && ! isMutate && needResponseBody (r .Method ))
319339 if _readdirErr != nil {
320340 errs = append (errs , _readdirErr )
321341 status = http .StatusInternalServerError
@@ -343,26 +363,6 @@ func (h *handler) getResponseData(r *http.Request) *responseData {
343363 canArchive := h .getCanArchive (subItems , rawReqPath , reqFsPath )
344364 canCors := h .getCanCors (rawReqPath , reqFsPath )
345365
346- isDownload := false
347- isUpload := false
348- isMkdir := false
349- isDelete := false
350- isMutate := false
351- switch {
352- case strings .HasPrefix (rawQuery , "download" ):
353- isDownload = true
354- case strings .HasPrefix (rawQuery , "upload" ) && r .Method == http .MethodPost :
355- isUpload = true
356- isMutate = true
357- case strings .HasPrefix (rawQuery , "mkdir" ):
358- isMkdir = true
359- isMutate = true
360- case strings .HasPrefix (r .URL .RawQuery , "delete" ):
361- isDelete = true
362- isMutate = true
363- }
364- wantJson := strings .HasPrefix (rawQuery , "json" ) || strings .Contains (rawQuery , "&json" )
365-
366366 context := & pathContext {
367367 download : isDownload ,
368368 sort : rawSortBy ,
@@ -377,6 +377,20 @@ func (h *handler) getResponseData(r *http.Request) *responseData {
377377 AuthUserName : authUserName ,
378378 AuthSuccess : authSuccess ,
379379
380+ IsDownload : isDownload ,
381+ IsUpload : isUpload ,
382+ IsMkdir : isMkdir ,
383+ IsDelete : isDelete ,
384+ IsMutate : isMutate ,
385+ WantJson : wantJson ,
386+
387+ CanUpload : canUpload ,
388+ CanMkdir : canMkdir ,
389+ CanDelete : canDelete ,
390+ HasDeletable : hasDeletable ,
391+ CanArchive : canArchive ,
392+ CanCors : canCors ,
393+
380394 errors : errs ,
381395 Status : status ,
382396
@@ -393,19 +407,5 @@ func (h *handler) getResponseData(r *http.Request) *responseData {
393407 SubItemPrefix : subItemPrefix ,
394408 SortState : sortState ,
395409 Context : context ,
396-
397- CanUpload : canUpload ,
398- CanMkdir : canMkdir ,
399- CanDelete : canDelete ,
400- HasDeletable : hasDeletable ,
401- CanArchive : canArchive ,
402- CanCors : canCors ,
403-
404- IsDownload : isDownload ,
405- IsUpload : isUpload ,
406- IsMkdir : isMkdir ,
407- IsDelete : isDelete ,
408- IsMutate : isMutate ,
409- WantJson : wantJson ,
410410 }
411411}
0 commit comments