-
Notifications
You must be signed in to change notification settings - Fork 4
/
dash_urls.go
50 lines (45 loc) · 1.64 KB
/
dash_urls.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
package korm
import (
"net/http"
"github.com/kamalshkeir/ksmux"
)
func init() {
const kormKeyUser = "korm-user"
ksmux.BeforeRenderHtml("korm-user", func(c *ksmux.Context, data *map[string]any) {
user, ok := c.GetKey(kormKeyUser)
if ok {
(*data)["IsAuthenticated"] = true
(*data)["User"] = user
} else {
(*data)["IsAuthenticated"] = false
(*data)["User"] = nil
}
})
}
func initAdminUrlPatterns(r *ksmux.Router) {
media_root := http.FileServer(http.Dir("./" + mediaDir))
r.Get(`/`+mediaDir+`/*path`, func(c *ksmux.Context) {
http.StripPrefix("/"+mediaDir+"/", media_root).ServeHTTP(c.ResponseWriter, c.Request)
})
r.Get("/mon/ping", func(c *ksmux.Context) { c.Status(200).Text("pong") })
r.Get("/offline", OfflineView)
r.Get("/manifest.webmanifest", ManifestView)
r.Get("/sw.js", ServiceWorkerView)
r.Get("/robots.txt", RobotsTxtView)
adminGroup := r.Group(adminPathNameGroup)
adminGroup.Get("/", Admin(IndexView))
adminGroup.Get("/login", Auth(LoginView))
adminGroup.Post("/login", Auth(LoginPOSTView))
adminGroup.Get("/logout", LogoutView)
adminGroup.Get("/logs", Admin(LogsView))
adminGroup.Post("/delete/row", Admin(DeleteRowPost))
adminGroup.Post("/update/row", Admin(UpdateRowPost))
adminGroup.Post("/create/row", Admin(CreateModelView))
adminGroup.Post("/drop/table", Admin(DropTablePost))
adminGroup.Get("/table/:model", Admin(AllModelsGet))
adminGroup.Post("/table/:model/search", Admin(AllModelsSearch))
adminGroup.Get("/get/:model/:id", Admin(SingleModelGet))
adminGroup.Get("/export/:table", Admin(ExportView))
adminGroup.Get("/export/:table/csv", Admin(ExportCSVView))
adminGroup.Post("/import", Admin(ImportView))
}