teldrive/routes/main.go

32 lines
784 B
Go
Raw Normal View History

2023-08-07 03:32:46 +08:00
package routes
2023-09-24 01:12:12 +08:00
import (
"net/http"
"strconv"
"github.com/divyam234/teldrive/database"
"github.com/gin-gonic/gin"
"go.etcd.io/bbolt"
)
2023-08-07 03:32:46 +08:00
2023-09-08 18:37:11 +08:00
func AddRoutes(router *gin.Engine) {
2023-08-07 03:32:46 +08:00
api := router.Group("/api")
2023-09-24 01:12:12 +08:00
api.GET("/bbolt", Authmiddleware, func(c *gin.Context) {
err := database.BoltDB.View(func(tx *bbolt.Tx) error {
c.Writer.Header().Set("Content-Type", "application/octet-stream")
c.Writer.Header().Set("Content-Disposition", `attachment; filename="teldrive.db"`)
c.Writer.Header().Set("Content-Length", strconv.Itoa(int(tx.Size())))
_, err := tx.WriteTo(c.Writer)
return err
})
if err != nil {
http.Error(c.Writer, err.Error(), http.StatusInternalServerError)
}
})
2023-08-12 19:21:42 +08:00
addAuthRoutes(api)
2023-08-07 03:32:46 +08:00
addFileRoutes(api)
2023-08-13 04:15:19 +08:00
addUploadRoutes(api)
2023-08-17 19:32:27 +08:00
addUserRoutes(api)
2023-08-07 03:32:46 +08:00
}