package com.xunwang.file.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.xunwang.servicebase.utils.JwtUtils;
import com.xunwang.servicebase.utils.R;
import com.xunwang.file.util.MinioUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@ApiSupport(author = "Long")
@Api("文件相关")
@RestController
@RequestMapping("/file")
public class FileUpload {

    @Resource
    private MinioUtil minioUtil;

/**
 * TODO
 *
 * @Description
 * @Author Paul  Email:8203193@qq.com
 * @Version 1.0
 * @Date 2023/6/13 15:19
 *
 */
    @PostMapping("/uploading")
    public R uploading(@RequestParam("file") MultipartFile file,
                       HttpServletRequest request) {
        String uid = JwtUtils.getUIdByJwtToken(request);
        String picName = request.getHeader("picName");
        String upload = minioUtil.upload(file,uid,picName + ".png");
        return R.ok().data("url", upload);
    }

    /**
     * TODO
     *
     * @Description
     * @Author Paul  Email:8203193@qq.com
     * @Version 1.0
     * @Date 2023/6/13 15:19
     *
     */
    @ApiOperation("生成小程序二维码")
    @GetMapping("/generateQRcodeUrl")
    public R generateQRcodeUrl(HttpServletRequest request) {
        String uid = request.getParameter("uid");
        String qrUrl = minioUtil.getWXCode(uid);

        return R.ok().data("QRurl",qrUrl);
    }


}
