11package serverHandler
22
3- import (
4- "mjpclab.dev/ghfs/src/util"
5- "os"
6- )
3+ import "mjpclab.dev/ghfs/src/util"
74
85type hierarchyAvailability struct {
96 global bool
@@ -28,6 +25,24 @@ func newHierarchyAvailability(
2825 }
2926}
3027
28+ func (ha * hierarchyAvailability ) match (urlPath , fsPath string , userId int ) bool {
29+ if ha .global {
30+ return true
31+ }
32+
33+ if hasUrlOrDirPrefix (ha .urls , urlPath , ha .dirs , fsPath ) {
34+ return true
35+ }
36+
37+ if userId >= 0 {
38+ if _ , match := hasUrlOrDirPrefixUsers (ha .urlsUsers , urlPath , ha .dirsUsers , fsPath , userId ); match {
39+ return true
40+ }
41+ }
42+
43+ return false
44+ }
45+
3146func hasUrlOrDirPrefix (urls []string , reqUrl string , dirs []string , reqDir string ) bool {
3247 for _ , url := range urls {
3348 if util .HasUrlPrefixDir (reqUrl , url ) {
@@ -79,117 +94,3 @@ func hasUrlOrDirPrefixUsers(urlsUsers pathIntsList, reqUrl string, dirsUsers pat
7994
8095 return
8196}
82-
83- func (h * aliasHandler ) getCanIndex (rawReqPath , reqFsPath string , userId int ) bool {
84- if h .index .global {
85- return true
86- }
87-
88- if hasUrlOrDirPrefix (h .index .urls , rawReqPath , h .index .dirs , reqFsPath ) {
89- return true
90- }
91-
92- if userId >= 0 {
93- if _ , match := hasUrlOrDirPrefixUsers (h .index .urlsUsers , rawReqPath , h .index .dirsUsers , reqFsPath , userId ); match {
94- return true
95- }
96- }
97-
98- return false
99- }
100-
101- func (h * aliasHandler ) getCanUpload (info os.FileInfo , rawReqPath , reqFsPath string , userId int ) bool {
102- if info == nil || ! info .IsDir () {
103- return false
104- }
105-
106- if h .upload .global {
107- return true
108- }
109-
110- if hasUrlOrDirPrefix (h .upload .urls , rawReqPath , h .upload .dirs , reqFsPath ) {
111- return true
112- }
113-
114- if userId >= 0 {
115- if _ , match := hasUrlOrDirPrefixUsers (h .upload .urlsUsers , rawReqPath , h .upload .dirsUsers , reqFsPath , userId ); match {
116- return true
117- }
118- }
119-
120- return false
121- }
122-
123- func (h * aliasHandler ) getCanMkdir (info os.FileInfo , rawReqPath , reqFsPath string , userId int ) bool {
124- if info == nil || ! info .IsDir () {
125- return false
126- }
127-
128- if h .mkdir .global {
129- return true
130- }
131-
132- if hasUrlOrDirPrefix (h .mkdir .urls , rawReqPath , h .mkdir .dirs , reqFsPath ) {
133- return true
134- }
135-
136- if userId >= 0 {
137- if _ , match := hasUrlOrDirPrefixUsers (h .mkdir .urlsUsers , rawReqPath , h .mkdir .dirsUsers , reqFsPath , userId ); match {
138- return true
139- }
140- }
141-
142- return false
143- }
144-
145- func (h * aliasHandler ) getCanDelete (info os.FileInfo , rawReqPath , reqFsPath string , userId int ) bool {
146- if info == nil || ! info .IsDir () {
147- return false
148- }
149-
150- if h .delete .global {
151- return true
152- }
153-
154- if hasUrlOrDirPrefix (h .delete .urls , rawReqPath , h .delete .dirs , reqFsPath ) {
155- return true
156- }
157-
158- if userId >= 0 {
159- if _ , match := hasUrlOrDirPrefixUsers (h .delete .urlsUsers , rawReqPath , h .delete .dirsUsers , reqFsPath , userId ); match {
160- return true
161- }
162- }
163-
164- return false
165- }
166-
167- func (h * aliasHandler ) getCanArchive (subInfos []os.FileInfo , rawReqPath , reqFsPath string , userId int ) bool {
168- if len (subInfos ) == 0 {
169- return false
170- }
171-
172- if h .archive .global {
173- return true
174- }
175-
176- if hasUrlOrDirPrefix (h .archive .urls , rawReqPath , h .archive .dirs , reqFsPath ) {
177- return true
178- }
179-
180- if userId >= 0 {
181- if _ , match := hasUrlOrDirPrefixUsers (h .archive .urlsUsers , rawReqPath , h .archive .dirsUsers , reqFsPath , userId ); match {
182- return true
183- }
184- }
185-
186- return false
187- }
188-
189- func (h * aliasHandler ) getCanCors (rawReqPath , reqFsPath string ) bool {
190- if h .cors .global {
191- return true
192- }
193-
194- return hasUrlOrDirPrefix (h .cors .urls , rawReqPath , h .cors .dirs , reqFsPath )
195- }
0 commit comments