Files
quyun-v2/backend/app/http/v1/common.go
Rogee 221b068a84 feat: add file deduplication and hash checking for uploads
- Implemented SHA-256 hashing for uploaded files to enable deduplication.
- Added CheckHash method to verify if a file with the same hash already exists.
- Updated Upload method to reuse existing media assets if a duplicate is found.
- Introduced a new hash column in the media_assets table to store file hashes.
- Enhanced the upload process to include progress tracking and hash calculation.
- Modified frontend to check for existing files before uploading and to show upload progress.
- Added vuedraggable for drag-and-drop functionality in the content editing view.
2025-12-31 19:16:02 +08:00

69 lines
1.6 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 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)
}