package com.ruoyi.platform.controller.minio;

import com.ruoyi.platform.service.MinioService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * minio 控制层
 * 提供通用的minio 存储上传下载接口
 * @author makejava
 * @since 2023-11-07 15:08:22
 *
 * */
@RestController
@RequestMapping("minioStorage")
@Api("minio存储管理")
public class MinioStorageController {
    @Resource
    private MinioService minioService;


    @GetMapping("/downloadFile")
    @ApiOperation("下载单个文件")
    public ResponseEntity<InputStreamResource> downloadFile(@RequestParam("path") String path) throws Exception {
        String bucketName = path.substring(0, path.indexOf("/"));
        String prefix = path.substring(path.indexOf("/")+1,path.length());
        return minioService.downloadFile(bucketName, prefix);
    }

    @GetMapping("/download")
    @ApiOperation(value = "minio存储下载", notes = "minio存储下载文件为zip包")
    public ResponseEntity<InputStreamResource> downloadDataset(@RequestParam("path") String path) {
        String bucketName = path.substring(0, path.indexOf("/"));
        String prefix = path.substring(path.indexOf("/")+1,path.length());
        return minioService.downloadZipFile(bucketName,prefix);
    }

}
