package com.slodon.b2b2c.controller.common;

import com.slodon.b2b2c.ueditor.ActionEnter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
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;

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

@Api(tags = "上传文件")
@RestController
@RequestMapping("v3/oss/ueditor")
public class UeditorController {
    @Resource
    private ActionEnter actionEnter;

    @ApiOperation("编辑器上传文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "upfile", value = "文件", paramType = "formData"),
            @ApiImplicitParam(name = "action", value = "操作类型：config-获取配置;uploadimage-上传图片;uploadvideo-上传视频;" +
                    "uploadfile-上传文件", paramType = "formData", required = true),
            @ApiImplicitParam(name = "callback", value = "回调", paramType = "formData"),
            @ApiImplicitParam(name = "start", value = "页数", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "大小", paramType = "query"),
            @ApiImplicitParam(name = "storeId", value = "店铺Id", paramType = "query"),
    })
    @RequestMapping(value = "upload")
    public void upload(HttpServletRequest request, HttpServletResponse response, String action, Integer start, Integer size,Long storeId, String callback, @RequestParam(value = "upfile", required = false) MultipartFile file) throws Exception {
        request.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Type", "text/html");
        response.addHeader("X-Frame-Options", "SAMEORIGIN");
        String result = actionEnter.exec(action, callback, file,start,size,storeId);
        response.getWriter().write(result);
    }
}
