feat(es):
This commit is contained in:
parent
609f6e7516
commit
742bcab6a7
|
@ -12,6 +12,7 @@ public class SecurityConstants {
|
||||||
* 这些路径可以直接访问,不需要认证
|
* 这些路径可以直接访问,不需要认证
|
||||||
*/
|
*/
|
||||||
public static final List<String> WHITE_LIST = List.of(
|
public static final List<String> WHITE_LIST = List.of(
|
||||||
|
"/common/**", //公共接口
|
||||||
"/demo/**", // 测试接口
|
"/demo/**", // 测试接口
|
||||||
"/api/products",
|
"/api/products",
|
||||||
"/api/user/register", // 用户注册
|
"/api/user/register", // 用户注册
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.guwan.backend.controller;
|
||||||
|
|
||||||
|
import com.guwan.backend.common.Result;
|
||||||
|
import com.guwan.backend.util.MinioUtil;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/common")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class CommonController {
|
||||||
|
|
||||||
|
|
||||||
|
private final MinioUtil minioUtil;
|
||||||
|
|
||||||
|
@PostMapping("/uploadFile")
|
||||||
|
public Result<String> uploadFile(String bucketName, MultipartFile file){
|
||||||
|
return Result.success(minioUtil.getUrl(minioUtil.getFileUrl
|
||||||
|
(bucketName, minioUtil.uploadFile(bucketName, file))));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -31,7 +31,6 @@ public class MinioUtil {
|
||||||
* 创建存储桶
|
* 创建存储桶
|
||||||
*/
|
*/
|
||||||
public void createBucket(String bucketName) {
|
public void createBucket(String bucketName) {
|
||||||
System.out.println("bucketName = " + bucketName);
|
|
||||||
try {
|
try {
|
||||||
boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
|
boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
|
||||||
if (!found) {
|
if (!found) {
|
||||||
|
@ -48,8 +47,6 @@ public class MinioUtil {
|
||||||
*/
|
*/
|
||||||
public String uploadFile(String bucketName, MultipartFile file) {
|
public String uploadFile(String bucketName, MultipartFile file) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
createBucket(bucketName);
|
createBucket(bucketName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -189,12 +186,12 @@ public class MinioUtil {
|
||||||
|
|
||||||
|
|
||||||
// 初始化时创建视频桶
|
// 初始化时创建视频桶
|
||||||
@PostConstruct
|
// @PostConstruct
|
||||||
public void init() {
|
// public void init() {
|
||||||
try {
|
// try {
|
||||||
createBucket("videos");
|
// createBucket("videos");
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
log.error("创建视频存储桶失败", e);
|
// log.error("创建视频存储桶失败", e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
Loading…
Reference in New Issue