package org.springblade.modules.obs.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springblade.core.tool.api.R;
import org.springblade.modules.obs.service.ObsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@Api(tags = "对象存储接口")
@RestController
public class ObsController {

    @Autowired
	ObsService obsService;



    @ApiOperation("上传对象")
    @PostMapping("/putObject")
    public R urlUploadObject(@RequestParam MultipartFile file){
        try {
            return R.data(obsService.postObject(file));
        } catch (IOException e) {
            e.printStackTrace();
            return R.fail("上传文件错误："+e.getMessage());
        }
    }

    @PostMapping("/generateCode")
    @ApiOperation("生成小程序分享二维码")
    public R generateCode(@RequestBody Map<String,String> params) throws IOException {
        return R.data(obsService.getCode(params));
    }

    @PostMapping("/getUnlimitCode")
    @ApiOperation("生成小程序分享二维码(无限制)")
    public R UnlimitCode(@RequestBody Map<String,String> params) throws IOException {
        return R.data(obsService.getUnlimitCode(params));
    }
}
