inleft
2022-08-25 d807fd2490a86bc99bb5abbe9566a63af63a6131
snowy-main/src/main/java/vip/xiaonuo/modular/blogFile/BlogFileController.java
@@ -24,24 +24,22 @@
 */
package vip.xiaonuo.modular.blogFile;
import cn.hutool.core.util.StrUtil;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.core.annotion.BusinessLog;
import vip.xiaonuo.core.consts.MyConstant;
import vip.xiaonuo.core.context.constant.ConstantContextHolder;
import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
import vip.xiaonuo.core.exception.BlogException;
import vip.xiaonuo.core.pojo.response.ResponseData;
import vip.xiaonuo.core.pojo.response.SuccessResponseData;
import vip.xiaonuo.modular.blogarticle.service.BlogArticleService;
import vip.xiaonuo.modular.blogarticletype.service.BlogArticleTypeService;
import vip.xiaonuo.sys.modular.file.service.SysFileInfoService;
import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import static vip.xiaonuo.sys.config.FileConfig.DEFAULT_BUCKET;
/**
 * blog文件控制器 (提供给外部blog系统查询)
@@ -55,13 +53,6 @@
public class BlogFileController {
    @Resource
    private BlogArticleService blogArticleService;
    @Resource
    private BlogArticleTypeService blogArticleTypeService;
    @Resource
    private SysFileInfoService fileInfoService;
    /**
@@ -73,18 +64,18 @@
    @PostMapping("/sysFileInfo/upload")
    @BusinessLog(title = "文件信息表_上传文件", opType = LogAnnotionOpTypeEnum.OTHER)
    public ResponseData upload(@RequestPart("file") MultipartFile file,
                               @NotNull @RequestParam Integer fileType,
                               @NotNull @RequestParam String bucketName,
                               @NotEmpty @RequestParam String authCode) {
        if (!MyConstant.FileTypeList.contains(fileType)) {
            throw new BlogException("错误文件类型");
        if (StrUtil.isEmpty(authCode) || !authCode.equals(ConstantContextHolder.getPushCode())) {
            throw new BlogException("授权码错误");
        }
//        if (StrUtil.isEmpty(authCode) || !authCode.equals(ConstantContextHolder.getAuthCode())) {
//            throw new BlogException("授权码错误");
//        }
        String bucket = MyConstant.uploadFileBucketMap.getOrDefault(fileType, DEFAULT_BUCKET);
        if (!MyConstant.uploadFileBucketList.contains(bucketName)) {
            throw new BlogException("错误bucket名称");
        }
        Long fileId = fileInfoService.uploadFileBlog(file, bucket);
        Long fileId = fileInfoService.uploadFileBlog(file, bucketName);
        return new SuccessResponseData(fileId);
    }