package api

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.guxuan/haibei/internal/config"
	"github.guxuan/haibei/internal/mods/common/biz"
	"github.guxuan/haibei/pkg/util"
)

type Upload struct {
	UploadBIZ *biz.Upload
}

func (a *Upload) SaveFile(c *gin.Context) {
	file, err := c.FormFile("file")
	if err != nil {
		util.ResError(c, err)
		return
	}
	result, err := a.UploadBIZ.SaveFile(c, file)
	fileURL := fmt.Sprintf("%s/%s", config.C.FileConfig.StaticPrefix, result)
	util.ResSuccess(c, fileURL)
}
