package com.ruoyi.web.controller.back;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.MusicInfo;
import com.ruoyi.system.config.AliConfig;
import org.springframework.web.bind.annotation.PostMapping;
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 java.io.IOException;

@RestController
@RequestMapping("/back/upload")
public class UploadOSSController extends BaseController {


    @PostMapping("/music/file")
    public AjaxResult addFile(
            @RequestParam("file") MultipartFile file
    ) throws IOException {
        // 1. 处理文件上传
        if (file != null && !file.isEmpty()) {
            // 保存文件逻辑
            return AjaxResult.success("请求成功",AliConfig.ossUp("musicFile/", file.getOriginalFilename(), file.getInputStream()));
        }

        return AjaxResult.error("文件不能为空");
    }


    @PostMapping("/musicImg/file")
    public AjaxResult addMusicImgFile(
            @RequestParam("file") MultipartFile file
    ) throws IOException {
        // 1. 处理文件上传
        if (file != null && !file.isEmpty()) {
            return AjaxResult.success("请求成功",AliConfig.ossUp("musicImg/", file.getOriginalFilename(), file.getInputStream()));
        }
        // 保存文件逻辑
        return AjaxResult.error("文件不能为空");
    }

    @PostMapping("/config/file")
    public AjaxResult addConfigFile(
            @RequestParam("file") MultipartFile file
    ) throws IOException {
        // 1. 处理文件上传
        if (file != null && !file.isEmpty()) {
            // 保存文件逻辑
            return AjaxResult.success("请求成功",AliConfig.ossUp("config/", file.getOriginalFilename(), file.getInputStream()));
        }
        return AjaxResult.error("文件不能为空");
    }

}
