package org.dromara.system.controller.system;


import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.system.domain.SysOss;
import org.dromara.system.service.IQiNiuContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@Slf4j
@RestController
@RequestMapping("/api/qiniu")
//@Api(tags = "七牛云存储管理")
public class QiNiuController {

    @Autowired
    private IQiNiuContentService qiNiuService;

    //    @ApiOperation("上传文件")
    @PostMapping("/upload")
    public R<SysOss> uploadByPrefix(@RequestParam MultipartFile file) {
        SysOss qiniuContent = qiNiuService.upload(file);
        if (StrUtil.isNotBlank(qiniuContent.getUrl())) {
            SysOss ossFile = new SysOss();
            ossFile.setOssId(qiniuContent.getOssId());
            ossFile.setFileName(qiniuContent.getOriginalName());
            ossFile.setUrl(qiniuContent.getUrl());
            return R.ok("上传成功！", ossFile);
        }

        return R.fail("上传失败！");
    }
}
