@@ -246,66 +246,52 @@ func getItemName(item os.FileInfo, r *http.Request) (itemName string) {
246
246
return
247
247
}
248
248
249
- func (h * handler ) getCanUpload (item os.FileInfo , rawReqPath , reqFsPath string ) bool {
250
- if item == nil || ! item .IsDir () {
251
- return false
252
- }
253
-
254
- if h .globalUpload {
255
- return true
256
- }
257
-
258
- for _ , uploadUrl := range h .uploadUrls {
259
- if util .HasUrlPrefixDir (rawReqPath , uploadUrl ) {
249
+ func hasUrlOrDirPrefix (urls []string , reqUrl string , dirs []string , reqDir string ) bool {
250
+ for _ , url := range urls {
251
+ if util .HasUrlPrefixDir (reqUrl , url ) {
260
252
return true
261
253
}
262
254
}
263
255
264
- for _ , uploadDir := range h . uploadDirs {
265
- if util .HasFsPrefixDir (reqFsPath , uploadDir ) {
256
+ for _ , dir := range dirs {
257
+ if util .HasFsPrefixDir (reqDir , dir ) {
266
258
return true
267
259
}
268
260
}
269
261
270
262
return false
271
263
}
272
264
273
- func (h * handler ) getCanArchive ( subItems [] os.FileInfo , rawReqPath , reqFsPath string ) bool {
274
- if len ( subItems ) == 0 {
265
+ func (h * handler ) getCanUpload ( item os.FileInfo , rawReqPath , reqFsPath string ) bool {
266
+ if item == nil || ! item . IsDir () {
275
267
return false
276
268
}
277
269
278
- if h .globalArchive {
270
+ if h .globalUpload {
279
271
return true
280
272
}
281
273
282
- for _ , archiveUrl := range h .archiveUrls {
283
- if util .HasUrlPrefixDir (rawReqPath , archiveUrl ) {
284
- return true
285
- }
274
+ return hasUrlOrDirPrefix (h .uploadUrls , rawReqPath , h .uploadDirs , reqFsPath )
275
+ }
276
+
277
+ func (h * handler ) getCanArchive (subItems []os.FileInfo , rawReqPath , reqFsPath string ) bool {
278
+ if len (subItems ) == 0 {
279
+ return false
286
280
}
287
281
288
- for _ , archiveDir := range h .archiveDirs {
289
- if util .HasFsPrefixDir (reqFsPath , archiveDir ) {
290
- return true
291
- }
282
+ if h .globalArchive {
283
+ return true
292
284
}
293
285
294
- return false
286
+ return hasUrlOrDirPrefix ( h . archiveUrls , rawReqPath , h . archiveDirs , reqFsPath )
295
287
}
296
288
297
- func (h * handler ) getCanCors (rawReqPath string ) bool {
289
+ func (h * handler ) getCanCors (rawReqPath , reqFsPath string ) bool {
298
290
if h .globalCors {
299
291
return true
300
292
}
301
293
302
- for _ , corsUrl := range h .corsUrls {
303
- if util .HasUrlPrefixDir (rawReqPath , corsUrl ) {
304
- return true
305
- }
306
- }
307
-
308
- return false
294
+ return hasUrlOrDirPrefix (h .corsUrls , rawReqPath , h .corsDirs , reqFsPath )
309
295
}
310
296
311
297
func (h * handler ) getPageData (r * http.Request ) (data * pageData , notFound , internalError bool ) {
@@ -355,7 +341,7 @@ func (h *handler) getPageData(r *http.Request) (data *pageData, notFound, intern
355
341
356
342
canUpload := h .getCanUpload (item , rawReqPath , reqFsPath )
357
343
canArchive := h .getCanArchive (subItems , rawReqPath , reqFsPath )
358
- canCors := h .getCanCors (rawReqPath )
344
+ canCors := h .getCanCors (rawReqPath , reqFsPath )
359
345
360
346
data = & pageData {
361
347
rawReqPath : rawReqPath ,
0 commit comments