MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / Init

Function Init

server/router.go:18–116  ·  view source on GitHub ↗
(e *gin.Engine)

Source from the content-addressed store, hash-verified

16)
17
18func Init(e *gin.Engine) {
19 e.ContextWithFallback = true
20 if !utils.SliceContains([]string{"", "/"}, conf.URL.Path) {
21 e.GET("/", func(c *gin.Context) {
22 c.Redirect(302, conf.URL.Path)
23 })
24 }
25 Cors(e)
26 g := e.Group(conf.URL.Path)
27 if conf.Conf.Scheme.HttpPort != -1 && conf.Conf.Scheme.HttpsPort != -1 && conf.Conf.Scheme.ForceHttps {
28 e.Use(middlewares.ForceHttps)
29 }
30 g.Any("/ping", func(c *gin.Context) {
31 c.String(200, "pong")
32 })
33 g.GET("/favicon.ico", handles.Favicon)
34 g.GET("/robots.txt", handles.Robots)
35 g.GET("/manifest.json", static.ManifestJSON)
36 g.GET("/i/:link_name", handles.Plist)
37 common.SecretKey = []byte(conf.Conf.JwtSecret)
38 g.Use(middlewares.StoragesLoaded)
39 if conf.Conf.MaxConnections > 0 {
40 g.Use(middlewares.MaxAllowed(conf.Conf.MaxConnections))
41 }
42 WebDav(g.Group("/dav"))
43 S3(g.Group("/s3"))
44 MCP(g)
45
46 downloadLimiter := middlewares.DownloadRateLimiter(stream.ClientDownloadLimit)
47 signCheck := middlewares.Down(sign.Verify)
48 g.GET("/d/*path", middlewares.PathParse, signCheck, downloadLimiter, handles.Down)
49 g.GET("/p/*path", middlewares.PathParse, signCheck, downloadLimiter, handles.Proxy)
50 g.HEAD("/d/*path", middlewares.PathParse, signCheck, handles.Down)
51 g.HEAD("/p/*path", middlewares.PathParse, signCheck, handles.Proxy)
52 archiveSignCheck := middlewares.Down(sign.VerifyArchive)
53 g.GET("/ad/*path", middlewares.PathParse, archiveSignCheck, downloadLimiter, handles.ArchiveDown)
54 g.GET("/ap/*path", middlewares.PathParse, archiveSignCheck, downloadLimiter, handles.ArchiveProxy)
55 g.GET("/ae/*path", middlewares.PathParse, archiveSignCheck, downloadLimiter, handles.ArchiveInternalExtract)
56 g.HEAD("/ad/*path", middlewares.PathParse, archiveSignCheck, handles.ArchiveDown)
57 g.HEAD("/ap/*path", middlewares.PathParse, archiveSignCheck, handles.ArchiveProxy)
58 g.HEAD("/ae/*path", middlewares.PathParse, archiveSignCheck, handles.ArchiveInternalExtract)
59
60 g.GET("/sd/:sid", middlewares.EmptyPathParse, middlewares.SharingIdParse, downloadLimiter, handles.SharingDown)
61 g.GET("/sd/:sid/*path", middlewares.PathParse, middlewares.SharingIdParse, downloadLimiter, handles.SharingDown)
62 g.HEAD("/sd/:sid", middlewares.EmptyPathParse, middlewares.SharingIdParse, handles.SharingDown)
63 g.HEAD("/sd/:sid/*path", middlewares.PathParse, middlewares.SharingIdParse, handles.SharingDown)
64 g.GET("/sad/:sid", middlewares.EmptyPathParse, middlewares.SharingIdParse, downloadLimiter, handles.SharingArchiveExtract)
65 g.GET("/sad/:sid/*path", middlewares.PathParse, middlewares.SharingIdParse, downloadLimiter, handles.SharingArchiveExtract)
66 g.HEAD("/sad/:sid", middlewares.EmptyPathParse, middlewares.SharingIdParse, handles.SharingArchiveExtract)
67 g.HEAD("/sad/:sid/*path", middlewares.PathParse, middlewares.SharingIdParse, handles.SharingArchiveExtract)
68
69 api := g.Group("/api")
70 auth := api.Group("", middlewares.Auth(false))
71 webauthn := api.Group("/authn", middlewares.Authn)
72
73 api.POST("/auth/login", handles.Login)
74 api.POST("/auth/login/hash", handles.LoginHash)
75 api.POST("/auth/login/ldap", handles.LoginLdap)

Callers 1

StartFunction · 0.92

Calls 15

SliceContainsFunction · 0.92
MaxAllowedFunction · 0.92
DownloadRateLimiterFunction · 0.92
DownFunction · 0.92
AuthFunction · 0.92
StaticFunction · 0.92
_fsFunction · 0.85
fsAndShareFunction · 0.85
_taskFunction · 0.85
_sharingFunction · 0.85
adminFunction · 0.85
debugFunction · 0.85

Tested by

no test coverage detected