mirror of https://github.com/pikami/cosmium.git
Implement state export endpoint
This commit is contained in:
parent
16f41a5479
commit
332be181ef
|
@ -0,0 +1,12 @@
|
||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/pikami/cosmium/internal/repositories"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CosmiumExport(c *gin.Context) {
|
||||||
|
c.IndentedJSON(http.StatusOK, repositories.GetState())
|
||||||
|
}
|
|
@ -13,7 +13,9 @@ import (
|
||||||
func Authentication() gin.HandlerFunc {
|
func Authentication() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
requestUrl := c.Request.URL.String()
|
requestUrl := c.Request.URL.String()
|
||||||
if config.Config.DisableAuth || strings.HasPrefix(requestUrl, "/_explorer") {
|
if config.Config.DisableAuth ||
|
||||||
|
strings.HasPrefix(requestUrl, "/_explorer") ||
|
||||||
|
strings.HasPrefix(requestUrl, "/cosmium") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,8 @@ func CreateRouter() *gin.Engine {
|
||||||
router.GET("/offers", handlers.GetOffers)
|
router.GET("/offers", handlers.GetOffers)
|
||||||
router.GET("/", handlers.GetServerInfo)
|
router.GET("/", handlers.GetServerInfo)
|
||||||
|
|
||||||
|
router.GET("/cosmium/export", handlers.CosmiumExport)
|
||||||
|
|
||||||
handlers.RegisterExplorerHandlers(router)
|
handlers.RegisterExplorerHandlers(router)
|
||||||
|
|
||||||
return router
|
return router
|
||||||
|
|
|
@ -29,3 +29,11 @@ func LoadStateFS(filePath string) {
|
||||||
collections = state.Collections
|
collections = state.Collections
|
||||||
documents = state.Documents
|
documents = state.Documents
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetState() map[string]interface{} {
|
||||||
|
return map[string]interface{}{
|
||||||
|
"databases": databases,
|
||||||
|
"collections": collections,
|
||||||
|
"documents": documents,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue