teldrive/pkg/controller/upload.go

59 lines
1.1 KiB
Go
Raw Normal View History

2023-12-03 03:47:23 +08:00
package controller
import (
"net/http"
2024-04-19 04:46:47 +08:00
"strconv"
2023-12-03 03:47:23 +08:00
"github.com/divyam234/teldrive/pkg/httputil"
2024-04-19 04:46:47 +08:00
"github.com/divyam234/teldrive/pkg/services"
2023-12-03 03:47:23 +08:00
"github.com/gin-gonic/gin"
)
func (uc *Controller) GetUploadFileById(c *gin.Context) {
res, err := uc.UploadService.GetUploadFileById(c)
if err != nil {
httputil.NewError(c, err.Code, err.Error)
return
}
c.JSON(http.StatusOK, res)
}
func (uc *Controller) DeleteUploadFile(c *gin.Context) {
res, err := uc.UploadService.DeleteUploadFile(c)
if err != nil {
httputil.NewError(c, err.Code, err.Error)
return
}
c.JSON(http.StatusOK, res)
}
func (uc *Controller) UploadFile(c *gin.Context) {
res, err := uc.UploadService.UploadFile(c)
if err != nil {
httputil.NewError(c, err.Code, err.Error)
return
}
c.JSON(http.StatusCreated, res)
}
2024-04-19 04:46:47 +08:00
func (uc *Controller) UploadStats(c *gin.Context) {
userId, _ := services.GetUserAuth(c)
days := 7
if c.Query("days") != "" {
days, _ = strconv.Atoi(c.Query("days"))
}
res, err := uc.UploadService.GetUploadStats(userId, days)
if err != nil {
httputil.NewError(c, err.Code, err.Error)
return
}
c.JSON(http.StatusCreated, res)
}