143 lines
4.1 KiB
Go
143 lines
4.1 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{}
|
|
|
|
// @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 form formData dto.UploadForm true "Upload form"
|
|
// @Success 200 {object} dto.UploadResult
|
|
// @Bind user local key(__ctx_user)
|
|
// @Bind file file
|
|
// @Bind form body
|
|
func (c *Common) Upload(
|
|
ctx fiber.Ctx,
|
|
user *models.User,
|
|
file *multipart.FileHeader,
|
|
form *dto.UploadForm,
|
|
) (*dto.UploadResult, error) {
|
|
val := ""
|
|
if form != nil {
|
|
val = form.Type
|
|
}
|
|
return services.Common.Upload(ctx, 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)
|
|
}
|
|
|
|
// Check file hash for deduplication
|
|
//
|
|
// @Router /v1/upload/check [get]
|
|
// @Summary Check hash
|
|
// @Description Check if file hash exists
|
|
// @Tags Common
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param hash query string true "File MD5 Hash"
|
|
// @Success 200 {object} dto.UploadResult
|
|
// @Bind user local key(__ctx_user)
|
|
// @Bind hash query
|
|
func (c *Common) CheckHash(ctx fiber.Ctx, user *models.User, hash string) (*dto.UploadResult, error) {
|
|
return services.Common.CheckHash(ctx, user.ID, hash)
|
|
}
|
|
|
|
// @Router /v1/upload/init [post]
|
|
// @Summary Init multipart upload
|
|
// @Description Initialize multipart upload
|
|
// @Tags Common
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param form body dto.UploadInitForm true "Init form"
|
|
// @Success 200 {object} dto.UploadInitResponse
|
|
// @Bind user local key(__ctx_user)
|
|
// @Bind form body
|
|
func (c *Common) InitUpload(ctx fiber.Ctx, user *models.User, form *dto.UploadInitForm) (*dto.UploadInitResponse, error) {
|
|
return services.Common.InitUpload(ctx.Context(), user.ID, form)
|
|
}
|
|
|
|
// @Router /v1/upload/part [post]
|
|
// @Summary Upload part
|
|
// @Description Upload a part
|
|
// @Tags Common
|
|
// @Accept multipart/form-data
|
|
// @Produce json
|
|
// @Param file formData file true "Part File"
|
|
// @Param form formData dto.UploadPartForm true "Part form"
|
|
// @Success 200 {string} string "OK"
|
|
// @Bind user local key(__ctx_user)
|
|
// @Bind file file
|
|
// @Bind form body
|
|
func (c *Common) UploadPart(ctx fiber.Ctx, user *models.User, file *multipart.FileHeader, form *dto.UploadPartForm) error {
|
|
return services.Common.UploadPart(ctx.Context(), user.ID, file, form)
|
|
}
|
|
|
|
// @Router /v1/upload/complete [post]
|
|
// @Summary Complete upload
|
|
// @Description Complete multipart upload
|
|
// @Tags Common
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param form body dto.UploadCompleteForm true "Complete form"
|
|
// @Success 200 {object} dto.UploadResult
|
|
// @Bind user local key(__ctx_user)
|
|
// @Bind form body
|
|
func (c *Common) CompleteUpload(ctx fiber.Ctx, user *models.User, form *dto.UploadCompleteForm) (*dto.UploadResult, error) {
|
|
return services.Common.CompleteUpload(ctx.Context(), user.ID, form)
|
|
}
|
|
|
|
// @Router /v1/upload/:uploadId [delete]
|
|
// @Summary Abort upload
|
|
// @Description Abort multipart upload
|
|
// @Tags Common
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param uploadId path string true "Upload ID"
|
|
// @Success 200 {string} string "OK"
|
|
// @Bind user local key(__ctx_user)
|
|
// @Bind uploadId path
|
|
func (c *Common) AbortUpload(ctx fiber.Ctx, user *models.User, uploadId string) error {
|
|
return services.Common.AbortUpload(ctx.Context(), user.ID, uploadId)
|
|
}
|
|
|
|
// @Router /v1/media-assets/:id<int> [delete]
|
|
// @Summary Delete media asset
|
|
// @Description Delete media asset
|
|
// @Tags Common
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path int64 true "Asset ID"
|
|
// @Success 200 {string} string "OK"
|
|
// @Bind user local key(__ctx_user)
|
|
// @Bind id path
|
|
func (c *Common) DeleteMediaAsset(ctx fiber.Ctx, user *models.User, id int64) error {
|
|
return services.Common.DeleteMediaAsset(ctx.Context(), user.ID, id)
|
|
}
|
|
|
|
// Upload file
|