package com.zanxiang.game.module.manage.controller;

import com.zanxiang.erp.security.annotation.PreAuthorize;
import com.zanxiang.game.module.manage.enums.FileTypeEnum;
import com.zanxiang.module.oss.service.IOssService;
import com.zanxiang.module.util.exception.BaseException;
import com.zanxiang.module.util.pojo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author : lingfeng
 * @time : 2022-07-12
 * @description : oss相关接口
 */
@RestController
@RequestMapping("/oss")
@Slf4j
public class OssController {

    @Autowired
    private IOssService ossService;

    @GetMapping(value = "/form/upload")
    @PreAuthorize(permissionKey = "manage:oss:formUpload")
    public ResultVO<Map<String, String>> formUpload(@RequestParam String fileType, @RequestParam String type) {
        FileTypeEnum fileTypeEnum = FileTypeEnum.getByFileType(fileType);
        if (fileTypeEnum == null) {
            throw new BaseException("错误的文件类型");
        }
        return ResultVO.ok(ossService.formUpload(fileTypeEnum.getFilePath(), type));
    }
}
