forked from uadmin/uadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_handler.go
56 lines (48 loc) · 1.04 KB
/
api_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package uadmin
import (
"net/http"
"strings"
)
// apiHandler !
func apiHandler(w http.ResponseWriter, r *http.Request) {
session := IsAuthenticated(r)
Path := strings.TrimPrefix(r.URL.Path, RootURL+"api")
// Handle requests for dAPI
if strings.HasPrefix(Path, "/d/") || Path == "/d" {
dAPIHandler(w, r, session)
return
}
if DisableAdminUI {
return
}
// For all other APIs, if the user is not authenticated
// then send them to login page
if session == nil {
loginHandler(w, r)
return
}
if strings.HasPrefix(Path, "/trail") {
trailAPIHandler(w, r)
return
}
if strings.HasPrefix(Path, "/upload_image") {
UploadImageHandler(w, r, session)
return
}
//if strings.HasPrefix(Path, "/upload_image_base64") {
// UploadImageHandler(w, r, session)
// return
//}
if strings.HasPrefix(Path, "/search") {
searchApiHandler(w, r, session)
return
}
if strings.HasPrefix(Path, "/get_models") {
GetModelsAPI(w, r, session)
return
}
if strings.HasPrefix(Path, "/get_fields") {
GetFieldsAPI(w, r, session)
return
}
}