feat(es):

This commit is contained in:
ovo 2024-12-10 17:00:35 +08:00
parent 609f6e7516
commit 742bcab6a7
3 changed files with 36 additions and 11 deletions

View File

@ -12,6 +12,7 @@ public class SecurityConstants {
* 这些路径可以直接访问不需要认证
*/
public static final List<String> WHITE_LIST = List.of(
"/common/**", //公共接口
"/demo/**", // 测试接口
"/api/products",
"/api/user/register", // 用户注册

View File

@ -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))));
}
}

View File

@ -31,7 +31,6 @@ public class MinioUtil {
* 创建存储桶
*/
public void createBucket(String bucketName) {
System.out.println("bucketName = " + bucketName);
try {
boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
if (!found) {
@ -48,8 +47,6 @@ public class MinioUtil {
*/
public String uploadFile(String bucketName, MultipartFile file) {
createBucket(bucketName);
try {
@ -189,12 +186,12 @@ public class MinioUtil {
// 初始化时创建视频桶
@PostConstruct
public void init() {
try {
createBucket("videos");
} catch (Exception e) {
log.error("创建视频存储桶失败", e);
}
}
// @PostConstruct
// public void init() {
// try {
// createBucket("videos");
// } catch (Exception e) {
// log.error("创建视频存储桶失败", e);
// }
// }
}