fix: issues
This commit is contained in:
@@ -2,6 +2,7 @@ package medias
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/pkg/consts"
|
"backend/pkg/consts"
|
||||||
|
"backend/pkg/errorx"
|
||||||
"backend/pkg/pg"
|
"backend/pkg/pg"
|
||||||
"backend/providers/jwt"
|
"backend/providers/jwt"
|
||||||
|
|
||||||
@@ -48,6 +49,9 @@ func (c *Controller) Show(ctx fiber.Ctx) error {
|
|||||||
hash := ctx.Params("hash")
|
hash := ctx.Params("hash")
|
||||||
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
||||||
log.Debug(claim)
|
log.Debug(claim)
|
||||||
|
if claim == nil {
|
||||||
|
return errorx.RequestUnAuthorized
|
||||||
|
}
|
||||||
|
|
||||||
model, err := c.svc.GetMediaByHash(ctx.Context(), claim.TenantID, hash)
|
model, err := c.svc.GetMediaByHash(ctx.Context(), claim.TenantID, hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -75,6 +79,9 @@ func (c *Controller) MediaIndex(ctx fiber.Ctx) error {
|
|||||||
hash := ctx.Params("hash")
|
hash := ctx.Params("hash")
|
||||||
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
||||||
log.Debug(claim)
|
log.Debug(claim)
|
||||||
|
if claim == nil {
|
||||||
|
return errorx.RequestUnAuthorized
|
||||||
|
}
|
||||||
|
|
||||||
model, err := c.svc.GetMediaByHash(ctx.Context(), claim.TenantID, hash)
|
model, err := c.svc.GetMediaByHash(ctx.Context(), claim.TenantID, hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -113,6 +120,9 @@ func (c *Controller) MediaSegment(ctx fiber.Ctx) error {
|
|||||||
hash := ctx.Params("hash")
|
hash := ctx.Params("hash")
|
||||||
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
||||||
log.Debug(claim)
|
log.Debug(claim)
|
||||||
|
if claim == nil {
|
||||||
|
return errorx.RequestUnAuthorized
|
||||||
|
}
|
||||||
|
|
||||||
model, err := c.svc.GetMediaByHash(ctx.Context(), claim.TenantID, hash)
|
model, err := c.svc.GetMediaByHash(ctx.Context(), claim.TenantID, hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -129,6 +139,9 @@ func (c *Controller) Checkout(ctx fiber.Ctx) error {
|
|||||||
hash := ctx.Params("hash")
|
hash := ctx.Params("hash")
|
||||||
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
||||||
log.Debug(claim)
|
log.Debug(claim)
|
||||||
|
if claim == nil {
|
||||||
|
return errorx.RequestUnAuthorized
|
||||||
|
}
|
||||||
|
|
||||||
model, err := c.svc.GetMediaByHash(ctx.Context(), claim.TenantID, hash)
|
model, err := c.svc.GetMediaByHash(ctx.Context(), claim.TenantID, hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ func (c *Controller) List(ctx fiber.Ctx) error {
|
|||||||
func (c *Controller) Charge(ctx fiber.Ctx) error {
|
func (c *Controller) Charge(ctx fiber.Ctx) error {
|
||||||
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
||||||
log.Debug(claim)
|
log.Debug(claim)
|
||||||
|
if claim == nil {
|
||||||
|
return errorx.RequestUnAuthorized
|
||||||
|
}
|
||||||
|
|
||||||
// [tenantId, chargeAmount, timestamp]
|
// [tenantId, chargeAmount, timestamp]
|
||||||
code := ctx.Params("code")
|
code := ctx.Params("code")
|
||||||
@@ -41,6 +44,10 @@ func (c *Controller) Info(ctx fiber.Ctx) error {
|
|||||||
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
||||||
log.Debug(claim)
|
log.Debug(claim)
|
||||||
|
|
||||||
|
if claim == nil {
|
||||||
|
return errorx.RequestUnAuthorized
|
||||||
|
}
|
||||||
|
|
||||||
info := &UserInfo{}
|
info := &UserInfo{}
|
||||||
|
|
||||||
balance, err := c.svc.GetTenantUserBalance(ctx.Context(), claim.TenantID, claim.UserID)
|
balance, err := c.svc.GetTenantUserBalance(ctx.Context(), claim.TenantID, claim.UserID)
|
||||||
@@ -62,6 +69,9 @@ func (c *Controller) Info(ctx fiber.Ctx) error {
|
|||||||
func (c *Controller) GetChargeCodes(ctx fiber.Ctx) error {
|
func (c *Controller) GetChargeCodes(ctx fiber.Ctx) error {
|
||||||
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
||||||
log.Debug(claim)
|
log.Debug(claim)
|
||||||
|
if claim == nil {
|
||||||
|
return errorx.RequestUnAuthorized
|
||||||
|
}
|
||||||
|
|
||||||
tenant, err := c.svc.GetTenantByID(ctx.Context(), claim.TenantID)
|
tenant, err := c.svc.GetTenantByID(ctx.Context(), claim.TenantID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -98,6 +108,9 @@ func (c *Controller) GetChargeCodes(ctx fiber.Ctx) error {
|
|||||||
func (c *Controller) BalanceHistory(ctx fiber.Ctx) error {
|
func (c *Controller) BalanceHistory(ctx fiber.Ctx) error {
|
||||||
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
||||||
log.Debug(claim)
|
log.Debug(claim)
|
||||||
|
if claim == nil {
|
||||||
|
return errorx.RequestUnAuthorized
|
||||||
|
}
|
||||||
|
|
||||||
histories, err := c.svc.GetBalanceHistory(ctx.Context(), claim.TenantID, claim.UserID)
|
histories, err := c.svc.GetBalanceHistory(ctx.Context(), claim.TenantID, claim.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ func (r Response) Response(ctx fiber.Ctx) error {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
RequestParseError = Response{http.StatusBadRequest, http.StatusBadRequest, "请求解析错误"}
|
RequestParseError = Response{http.StatusBadRequest, http.StatusBadRequest, "请求解析错误"}
|
||||||
|
RequestUnAuthorized = Response{http.StatusUnauthorized, http.StatusUnauthorized, "未授权"}
|
||||||
InternalError = Response{http.StatusInternalServerError, http.StatusInternalServerError, "内部错误"}
|
InternalError = Response{http.StatusInternalServerError, http.StatusInternalServerError, "内部错误"}
|
||||||
UserBalanceNotEnough = Response{http.StatusPaymentRequired, 1001, "余额不足,请充值"}
|
UserBalanceNotEnough = Response{http.StatusPaymentRequired, 1001, "余额不足,请充值"}
|
||||||
InvalidChargeCode = Response{http.StatusPaymentRequired, 1002, "无效的充值码"}
|
InvalidChargeCode = Response{http.StatusPaymentRequired, 1002, "无效的充值码"}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func Provide(opts ...opt.Option) error {
|
|||||||
engine.Use(recover.New(recover.Config{
|
engine.Use(recover.New(recover.Config{
|
||||||
EnableStackTrace: true,
|
EnableStackTrace: true,
|
||||||
StackTraceHandler: func(c fiber.Ctx, e any) {
|
StackTraceHandler: func(c fiber.Ctx, e any) {
|
||||||
log.WithError(e.(error)).Error(fmt.Sprintf("panic: %v\n%s\n", e, debug.Stack()))
|
log.Error(fmt.Sprintf("panic: %v\n%s\n", e, debug.Stack()))
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user