package org.springblade.modules.app.web;

import com.wn.common.controller.BaseController;
import com.wn.common.datamodel.ResultDTO;
import org.springblade.common.auth.permission.DisableLoginVerify;
import org.springblade.core.tool.api.R;
import org.springblade.modules.app.dto.PostPolicyDTO;
import org.springblade.modules.app.manager.OssManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = "app/aliyunoss")
public class AppOssController extends BaseController {

    @Autowired
    private OssManager ossManager;

    /**
     * 前端js阿里云上传文件，获取签名等信息
     *
     * @param key
     * @return
     */
    @ResponseBody
    @GetMapping("/sign")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<PostPolicyDTO>> getOssPostPolicy(String key) {
        return success(ossManager.getPostPolicy(key));
    }

    /**
     * 添加活动
     *
     * @param request 请求对象
     * @return
     */
    @PostMapping("/upload")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<String>> uploadImg(HttpServletRequest request, String path) {
        return success(ossManager.upLoadImage(request, path));
    }

}

