55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package v1
|
|
|
|
import (
|
|
"mime/multipart"
|
|
|
|
"quyun/v2/app/http/v1/dto"
|
|
"quyun/v2/app/services"
|
|
"quyun/v2/database/models"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
)
|
|
|
|
// @provider
|
|
type Common struct{}
|
|
|
|
// Upload file
|
|
//
|
|
// @Router /v1/upload [post]
|
|
// @Summary Upload file
|
|
// @Description Upload file
|
|
// @Tags Common
|
|
// @Accept multipart/form-data
|
|
// @Produce json
|
|
// @Param file formData file true "File"
|
|
// @Param type formData string false "Type enum(image, video, audio)"
|
|
// @Success 200 {object} dto.UploadResult
|
|
// @Bind user local key(__ctx_user)
|
|
// @Bind file file
|
|
// @Bind typeArg body key(type)
|
|
func (c *Common) Upload(
|
|
ctx fiber.Ctx,
|
|
user *models.User,
|
|
file *multipart.FileHeader,
|
|
typeArg *string,
|
|
) (*dto.UploadResult, error) {
|
|
val := ""
|
|
if typeArg != nil {
|
|
val = *typeArg
|
|
}
|
|
return services.Common.Upload(ctx.Context(), user.ID, file, val)
|
|
}
|
|
|
|
// Get options (enums)
|
|
//
|
|
// @Router /v1/common/options [get]
|
|
// @Summary Get options
|
|
// @Description Get global options (enums)
|
|
// @Tags Common
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} dto.OptionsResponse
|
|
func (c *Common) GetOptions(ctx fiber.Ctx) (*dto.OptionsResponse, error) {
|
|
return services.Common.Options(ctx.Context())
|
|
}
|