added bbolt file download

This commit is contained in:
divyam234 2023-09-23 22:42:12 +05:30
parent 859e35c1a4
commit 7b3220732e
2 changed files with 22 additions and 2 deletions

View file

@ -1,9 +1,29 @@
package routes
import "github.com/gin-gonic/gin"
import (
"net/http"
"strconv"
"github.com/divyam234/teldrive/database"
"github.com/gin-gonic/gin"
"go.etcd.io/bbolt"
)
func AddRoutes(router *gin.Engine) {
api := router.Group("/api")
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)
}
})
addAuthRoutes(api)
addFileRoutes(api)
addUploadRoutes(api)

@ -1 +1 @@
Subproject commit e69660100478be62c9e4ff9b5a3d2b4a53811d3e
Subproject commit a2d12d64157b72ef3d7daa359db0f6a07917d5ec