Skip to content

Commit 511de40

Browse files
committed
refactor(serverHandler): extract get perm funcs
1 parent f77776a commit 511de40

File tree

2 files changed

+62
-56
lines changed

2 files changed

+62
-56
lines changed

src/serverHandler/perm.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package serverHandler
2+
3+
import (
4+
"../util"
5+
"os"
6+
)
7+
8+
func hasUrlOrDirPrefix(urls []string, reqUrl string, dirs []string, reqDir string) bool {
9+
for _, url := range urls {
10+
if util.HasUrlPrefixDir(reqUrl, url) {
11+
return true
12+
}
13+
}
14+
15+
for _, dir := range dirs {
16+
if util.HasFsPrefixDir(reqDir, dir) {
17+
return true
18+
}
19+
}
20+
21+
return false
22+
}
23+
24+
func (h *handler) getCanUpload(item os.FileInfo, rawReqPath, reqFsPath string) bool {
25+
if item == nil || !item.IsDir() {
26+
return false
27+
}
28+
29+
if h.globalUpload {
30+
return true
31+
}
32+
33+
return hasUrlOrDirPrefix(h.uploadUrls, rawReqPath, h.uploadDirs, reqFsPath)
34+
}
35+
36+
func (h *handler) getCanArchive(subItems []os.FileInfo, rawReqPath, reqFsPath string) bool {
37+
if len(subItems) == 0 {
38+
return false
39+
}
40+
41+
if h.globalArchive {
42+
return true
43+
}
44+
45+
return hasUrlOrDirPrefix(h.archiveUrls, rawReqPath, h.archiveDirs, reqFsPath)
46+
}
47+
48+
func (h *handler) getCanCors(rawReqPath, reqFsPath string) bool {
49+
if h.globalCors {
50+
return true
51+
}
52+
53+
return hasUrlOrDirPrefix(h.corsUrls, rawReqPath, h.corsDirs, reqFsPath)
54+
}
55+
56+
func (h *handler) getNeedAuth(rawReqPath, reqFsPath string) bool {
57+
if h.globalAuth {
58+
return true
59+
}
60+
61+
return hasUrlOrDirPrefix(h.authUrls, rawReqPath, h.authDirs, reqFsPath)
62+
}

src/serverHandler/responseData.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -207,62 +207,6 @@ func getItemName(item os.FileInfo, r *http.Request) (itemName string) {
207207
return
208208
}
209209

210-
func hasUrlOrDirPrefix(urls []string, reqUrl string, dirs []string, reqDir string) bool {
211-
for _, url := range urls {
212-
if util.HasUrlPrefixDir(reqUrl, url) {
213-
return true
214-
}
215-
}
216-
217-
for _, dir := range dirs {
218-
if util.HasFsPrefixDir(reqDir, dir) {
219-
return true
220-
}
221-
}
222-
223-
return false
224-
}
225-
226-
func (h *handler) getCanUpload(item os.FileInfo, rawReqPath, reqFsPath string) bool {
227-
if item == nil || !item.IsDir() {
228-
return false
229-
}
230-
231-
if h.globalUpload {
232-
return true
233-
}
234-
235-
return hasUrlOrDirPrefix(h.uploadUrls, rawReqPath, h.uploadDirs, reqFsPath)
236-
}
237-
238-
func (h *handler) getCanArchive(subItems []os.FileInfo, rawReqPath, reqFsPath string) bool {
239-
if len(subItems) == 0 {
240-
return false
241-
}
242-
243-
if h.globalArchive {
244-
return true
245-
}
246-
247-
return hasUrlOrDirPrefix(h.archiveUrls, rawReqPath, h.archiveDirs, reqFsPath)
248-
}
249-
250-
func (h *handler) getCanCors(rawReqPath, reqFsPath string) bool {
251-
if h.globalCors {
252-
return true
253-
}
254-
255-
return hasUrlOrDirPrefix(h.corsUrls, rawReqPath, h.corsDirs, reqFsPath)
256-
}
257-
258-
func (h *handler) getNeedAuth(rawReqPath, reqFsPath string) bool {
259-
if h.globalAuth {
260-
return true
261-
}
262-
263-
return hasUrlOrDirPrefix(h.authUrls, rawReqPath, h.authDirs, reqFsPath)
264-
}
265-
266210
func (h *handler) getResponseData(r *http.Request) (data *responseData) {
267211
requestUri := r.URL.Path
268212
tailSlash := requestUri[len(requestUri)-1] == '/'

0 commit comments

Comments
 (0)