✨ Billing status displaying
This commit is contained in:
parent
8b02381392
commit
aa0f4d292e
@ -2,6 +2,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/spf13/viper"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
||||||
@ -13,6 +14,25 @@ import (
|
|||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func getBillingStatus(c *fiber.Ctx) error {
|
||||||
|
if err := sec.EnsureAuthenticated(c); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
user := c.Locals("nex_user").(*sec.UserInfo)
|
||||||
|
|
||||||
|
currentBytes, err := services.GetLastDayUploadedBytes(user.ID)
|
||||||
|
if err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
|
}
|
||||||
|
discountFileSize := viper.GetInt64("payment.discount")
|
||||||
|
|
||||||
|
return c.JSON(fiber.Map{
|
||||||
|
"current_bytes": currentBytes,
|
||||||
|
"discount_file_size": discountFileSize,
|
||||||
|
"included_ratio": float64(currentBytes) / float64(discountFileSize),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func openAttachment(c *fiber.Ctx) error {
|
func openAttachment(c *fiber.Ctx) error {
|
||||||
id := c.Params("id")
|
id := c.Params("id")
|
||||||
region := c.Query("region")
|
region := c.Query("region")
|
||||||
|
@ -9,6 +9,7 @@ func MapAPIs(app *fiber.App, baseURL string) {
|
|||||||
api := app.Group(baseURL).Name("API")
|
api := app.Group(baseURL).Name("API")
|
||||||
{
|
{
|
||||||
api.Get("/destinations", listDestination)
|
api.Get("/destinations", listDestination)
|
||||||
|
api.Get("/billing", getBillingStatus)
|
||||||
|
|
||||||
boost := api.Group("/boosts").Name("Boosts API")
|
boost := api.Group("/boosts").Name("Boosts API")
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user