提交开发分支未提交代码并修正配置
This commit is contained in:
+4
-4
@@ -193,11 +193,11 @@
|
||||
<artifactId>httpclient</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MinIO -->
|
||||
<!-- Qiniu Kodo primary object storage -->
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
<version>8.5.7</version>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
<version>[7.19.0, 7.19.99]</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Aliyun OSS backup storage -->
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "yuminail.cache")
|
||||
@ConfigurationProperties(prefix = "fingertip-designer.cache")
|
||||
public class AppCacheProperties {
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "yuminail.http-client")
|
||||
@ConfigurationProperties(prefix = "fingertip-designer.http-client")
|
||||
/**
|
||||
* Purpose: HttpClientProperties supports HttpClientProperties.java by holding or executing the http client properties business role.
|
||||
* Usage: reference this class from the owning layer and pass validated inputs before reading or updating related state.
|
||||
|
||||
@@ -9,18 +9,18 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "yuminail.security.jwt")
|
||||
@ConfigurationProperties(prefix = "fingertip-designer.security.jwt")
|
||||
public class JwtProperties {
|
||||
|
||||
/**
|
||||
* HS512 密钥,生产环境请通过 Nacos 覆盖。
|
||||
*/
|
||||
private String secret = "yuminail-secret-key-for-jwt-token-generation-2026-must-be-at-least-512-bits-long-for-hs512-algorithm-security-requirements";
|
||||
private String secret = "fingertip-designer-secret-key-for-jwt-token-generation-2026-must-be-at-least-512-bits-long-for-hs512-algorithm-security-requirements";
|
||||
|
||||
/**
|
||||
* Token 发行者。
|
||||
*/
|
||||
private String issuer = "yuminail";
|
||||
private String issuer = "fingertip-designer";
|
||||
|
||||
/**
|
||||
* AccessToken 有效期,单位秒。
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "yuminail.security.login-lock")
|
||||
@ConfigurationProperties(prefix = "fingertip-designer.security.login-lock")
|
||||
/**
|
||||
* Purpose: LoginLockProperties supports LoginLockProperties.java by holding or executing the login lock properties business role.
|
||||
* Usage: reference this class from the owning layer and pass validated inputs before reading or updating related state.
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.xiaowang.yuminailcore.config;
|
||||
|
||||
import io.minio.MinioClient;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "minio")
|
||||
/**
|
||||
* Purpose: MinioConfig supports MinioConfig.java by holding or executing the minio config business role.
|
||||
* Usage: reference this class from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
public class MinioConfig {
|
||||
|
||||
/**
|
||||
* Purpose: endpoint supports MinioConfig.java by holding or executing the endpoint business role.
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private String endpoint;
|
||||
/**
|
||||
* Purpose: accessKey supports MinioConfig.java by holding or executing the access key business role.
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private String accessKey;
|
||||
/**
|
||||
* Purpose: secretKey supports MinioConfig.java by holding or executing the secret key business role.
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private String secretKey;
|
||||
/**
|
||||
* Purpose: bucketName supports MinioConfig.java by holding or executing the bucket name business role.
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private String bucketName;
|
||||
|
||||
@Bean
|
||||
/**
|
||||
* Purpose: minioClient supports MinioConfig.java by holding or executing the minio client business role.
|
||||
* Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
public MinioClient minioClient() {
|
||||
return MinioClient.builder()
|
||||
.endpoint(endpoint)
|
||||
.credentials(accessKey, secretKey)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.xiaowang.yuminailcore.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
@Component
|
||||
@Validated
|
||||
@ConfigurationProperties(prefix = "object-storage")
|
||||
public class ObjectStorageProperties {
|
||||
|
||||
@NotBlank
|
||||
private String primaryProvider;
|
||||
|
||||
@NotBlank
|
||||
private String backupProvider;
|
||||
|
||||
@NotNull
|
||||
@Min(1)
|
||||
private Integer signedUrlExpireMinutes;
|
||||
|
||||
@NotBlank
|
||||
private String backupQueueName;
|
||||
|
||||
@NotBlank
|
||||
private String backupExchangeName;
|
||||
|
||||
@NotBlank
|
||||
private String backupRoutingKey;
|
||||
|
||||
@NotNull
|
||||
@Min(1)
|
||||
private Integer backupRetryBatchLimit;
|
||||
|
||||
@NotBlank
|
||||
private String backupRetryCron;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.xiaowang.yuminailcore.config;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.BindingBuilder;
|
||||
import org.springframework.amqp.core.DirectExchange;
|
||||
@@ -10,15 +11,14 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class RabbitMQConfig {
|
||||
|
||||
public static final String EXAMPLE_QUEUE = "yuminail.example.queue";
|
||||
public static final String EXAMPLE_EXCHANGE = "yuminail.example.exchange";
|
||||
public static final String EXAMPLE_ROUTING_KEY = "yuminail.example.routing.key";
|
||||
public static final String EXAMPLE_QUEUE = "fingertip-designer.example.queue";
|
||||
public static final String EXAMPLE_EXCHANGE = "fingertip-designer.example.exchange";
|
||||
public static final String EXAMPLE_ROUTING_KEY = "fingertip-designer.example.routing.key";
|
||||
|
||||
public static final String FILE_OSS_BACKUP_EXCHANGE = "yuminail.file.oss.backup.exchange";
|
||||
public static final String FILE_OSS_BACKUP_QUEUE = "yuminail.file.oss.backup.queue";
|
||||
public static final String FILE_OSS_BACKUP_ROUTING_KEY = "yuminail.file.oss.backup";
|
||||
private final ObjectStorageProperties objectStorageProperties;
|
||||
|
||||
@Bean
|
||||
public MessageConverter jsonMessageConverter() {
|
||||
@@ -41,19 +41,19 @@ public class RabbitMQConfig {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue fileOssBackupQueue() {
|
||||
return new Queue(FILE_OSS_BACKUP_QUEUE, true);
|
||||
public Queue objectStorageBackupQueue() {
|
||||
return new Queue(objectStorageProperties.getBackupQueueName(), true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DirectExchange fileOssBackupExchange() {
|
||||
return new DirectExchange(FILE_OSS_BACKUP_EXCHANGE, true, false);
|
||||
public DirectExchange objectStorageBackupExchange() {
|
||||
return new DirectExchange(objectStorageProperties.getBackupExchangeName(), true, false);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding fileOssBackupBinding() {
|
||||
return BindingBuilder.bind(fileOssBackupQueue())
|
||||
.to(fileOssBackupExchange())
|
||||
.with(FILE_OSS_BACKUP_ROUTING_KEY);
|
||||
public Binding objectStorageBackupBinding() {
|
||||
return BindingBuilder.bind(objectStorageBackupQueue())
|
||||
.to(objectStorageBackupExchange())
|
||||
.with(objectStorageProperties.getBackupRoutingKey());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "yuminail.security.rate-limit")
|
||||
@ConfigurationProperties(prefix = "fingertip-designer.security.rate-limit")
|
||||
public class RateLimitProperties {
|
||||
|
||||
private LimitRule login = new LimitRule(10, 60);
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "yuminail.security.signature")
|
||||
@ConfigurationProperties(prefix = "fingertip-designer.security.signature")
|
||||
public class RequestSignatureProperties {
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "yuminail.slow-request")
|
||||
@ConfigurationProperties(prefix = "fingertip-designer.slow-request")
|
||||
/**
|
||||
* Purpose: SlowRequestLogProperties supports SlowRequestLogProperties.java by holding or executing the slow request log properties business role.
|
||||
* Usage: reference this class from the owning layer and pass validated inputs before reading or updating related state.
|
||||
|
||||
+3
-1
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "yuminail.security.upload")
|
||||
@ConfigurationProperties(prefix = "fingertip-designer.security.upload")
|
||||
/**
|
||||
* Purpose: UploadSecurityProperties supports UploadSecurityProperties.java by holding or executing the upload security properties business role.
|
||||
* Usage: reference this class from the owning layer and pass validated inputs before reading or updating related state.
|
||||
@@ -22,6 +22,8 @@ public class UploadSecurityProperties {
|
||||
*/
|
||||
private long maxSize = 10 * 1024 * 1024;
|
||||
|
||||
private long maxTotalSize = 500L * 1024 * 1024;
|
||||
|
||||
private List<String> allowedMimeTypes = new ArrayList<>(List.of(
|
||||
"image/jpeg",
|
||||
"image/png",
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "yuminail.wechat.mini")
|
||||
@ConfigurationProperties(prefix = "fingertip-designer.wechat.mini")
|
||||
public class WechatMiniProperties {
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -267,7 +267,7 @@ public class NailArtistInfoServiceImpl extends ServiceImpl<NailArtistInfoMapper,
|
||||
profile.setWorkStartTime(artistInfo.getWorkStartTime());
|
||||
profile.setWorkEndTime(artistInfo.getWorkEndTime());
|
||||
profile.setStyleTags(parseTextTokens(artistInfo.getSkills()));
|
||||
profile.setWorks(buildWorks(artistInfo.getPortfolio(), servedItems, 6));
|
||||
profile.setWorks(buildWorks(artistInfo.getPortfolio(), servedItems, 24));
|
||||
profile.setReviews(reviews.stream().limit(3).collect(Collectors.toList()));
|
||||
profile.setAvailability(getAvailability(artistId).stream().limit(8).collect(Collectors.toList()));
|
||||
return profile;
|
||||
|
||||
+119
-94
@@ -2,48 +2,49 @@ package com.xiaowang.yuminailcore.modules.content.controller.front;
|
||||
|
||||
import com.xiaowang.yuminailcore.annotation.OperationGuard;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.config.ObjectStorageProperties;
|
||||
import com.xiaowang.yuminailcore.modules.content.dto.CommentDTO;
|
||||
import com.xiaowang.yuminailcore.modules.file.dto.ObjectStorageFileDTO;
|
||||
import com.xiaowang.yuminailcore.modules.content.service.CommentService;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.MinioService;
|
||||
import com.xiaowang.yuminailcore.modules.content.vo.CommentVO;
|
||||
import com.xiaowang.yuminailcore.modules.file.dto.ChunkUploadCompleteRequestDTO;
|
||||
import com.xiaowang.yuminailcore.modules.file.dto.ChunkUploadInitRequestDTO;
|
||||
import com.xiaowang.yuminailcore.modules.file.dto.ObjectStorageFileDTO;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.ChunkUploadService;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.ObjectStorageFileService;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.PrimaryObjectStorageService;
|
||||
import com.xiaowang.yuminailcore.modules.file.vo.ObjectStorageFileVO;
|
||||
import com.xiaowang.yuminailcore.support.id.TimeOrderedSnowflakeIdGenerator;
|
||||
import com.xiaowang.yuminailcore.support.security.UploadSecurityValidator;
|
||||
import com.xiaowang.yuminailcore.modules.content.vo.CommentVO;
|
||||
import com.xiaowang.yuminailcore.modules.file.vo.ObjectStorageFileVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
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 javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户评论信息表 Controller
|
||||
* 对应数据库表 t_comment
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping({"/comment", "/api/comment"})
|
||||
@RequiredArgsConstructor
|
||||
public class CommentController {
|
||||
/**
|
||||
* Variable `commentService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
|
||||
private final CommentService commentService;
|
||||
private final ObjectStorageFileService objectStorageFileService;
|
||||
private final MinioService minioService;
|
||||
private final PrimaryObjectStorageService primaryObjectStorageService;
|
||||
private final ChunkUploadService chunkUploadService;
|
||||
private final TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator;
|
||||
private final UploadSecurityValidator uploadSecurityValidator;
|
||||
private final ObjectStorageProperties objectStorageProperties;
|
||||
|
||||
/**
|
||||
* 创建评论
|
||||
*
|
||||
* @param commentDTO 评论DTO
|
||||
* @return 评论ID
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
public Result<Long> createComment(HttpServletRequest request, @RequestBody CommentDTO commentDTO) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
@@ -60,43 +61,76 @@ public class CommentController {
|
||||
}
|
||||
try {
|
||||
uploadSecurityValidator.validate(file);
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
if (originalFilename == null || originalFilename.isEmpty()) {
|
||||
originalFilename = "comment-image";
|
||||
}
|
||||
String fileExtension = originalFilename == null || !originalFilename.contains(".")
|
||||
? ""
|
||||
: originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
String objectName = snowflakeIdGenerator.nextIdString() + fileExtension;
|
||||
String fileUrl = minioService.uploadFile(file, objectName);
|
||||
|
||||
ObjectStorageFileDTO dto = new ObjectStorageFileDTO();
|
||||
dto.setFileName(originalFilename);
|
||||
dto.setFileUrl(fileUrl);
|
||||
dto.setObjectName(objectName);
|
||||
dto.setMinioUrl(fileUrl);
|
||||
dto.setContentType(file.getContentType());
|
||||
dto.setFileSize(file.getSize());
|
||||
dto.setMinioUploadStatus(1);
|
||||
dto.setOssUploadStatus(0);
|
||||
dto.setOssRetryCount(0);
|
||||
dto.setStatus(1);
|
||||
|
||||
Long fileId = objectStorageFileService.createObjectStorageFile(dto);
|
||||
return Result.success(objectStorageFileService.getObjectStorageFileById(fileId));
|
||||
String originalFilename = normalizeOriginalFilename(file.getOriginalFilename());
|
||||
String objectName = snowflakeIdGenerator.nextIdString() + resolveFileExtension(originalFilename);
|
||||
String fileUrl = primaryObjectStorageService.uploadFile(file, objectName);
|
||||
return Result.success(createCommentImageRecord(originalFilename, fileUrl, objectName, file.getContentType(), file.getSize()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("评价图片上传失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新评论
|
||||
*
|
||||
* @param id 评论ID
|
||||
* @param commentDTO 评论DTO
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
@PostMapping("/upload-image/init")
|
||||
@OperationGuard(action = "comment-image-upload-init", ttlSeconds = 10, message = "图片正在上传中,请勿重复操作")
|
||||
public Result<?> initCommentImageUpload(HttpServletRequest request, @Valid @RequestBody ChunkUploadInitRequestDTO requestDTO) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
if (userId == null) {
|
||||
return Result.error("请先登录后再上传评价图片");
|
||||
}
|
||||
uploadSecurityValidator.validateMetadata(requestDTO.getFileName(), requestDTO.getContentType(), requestDTO.getFileSize());
|
||||
return Result.success(chunkUploadService.initCommentImageUpload(userId, requestDTO));
|
||||
}
|
||||
|
||||
@PostMapping("/upload-image/chunk")
|
||||
@OperationGuard(action = "comment-image-upload-chunk", ttlSeconds = 20)
|
||||
public Result<Boolean> uploadCommentImageChunk(HttpServletRequest request,
|
||||
@RequestParam("uploadId") String uploadId,
|
||||
@RequestParam("chunkIndex") Integer chunkIndex,
|
||||
@RequestParam("totalChunks") Integer totalChunks,
|
||||
@RequestParam("chunk") MultipartFile chunkFile) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
if (userId == null) {
|
||||
return Result.error("请先登录后再上传评价图片");
|
||||
}
|
||||
uploadSecurityValidator.validateChunk(chunkFile);
|
||||
chunkUploadService.uploadCommentImageChunk(userId, uploadId, chunkIndex, totalChunks, chunkFile);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/upload-image/complete")
|
||||
@OperationGuard(action = "comment-image-upload-complete", ttlSeconds = 30, message = "图片正在上传中,请勿重复操作")
|
||||
public Result<ObjectStorageFileVO> completeCommentImageUpload(HttpServletRequest request, @Valid @RequestBody ChunkUploadCompleteRequestDTO requestDTO) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
if (userId == null) {
|
||||
return Result.error("请先登录后再上传评价图片");
|
||||
}
|
||||
try (ChunkUploadService.PreparedUploadFile preparedUploadFile =
|
||||
chunkUploadService.prepareCommentImageFile(userId, requestDTO.getUploadId());
|
||||
FileInputStream inputStream = new FileInputStream(preparedUploadFile.getFile())) {
|
||||
String originalFilename = normalizeOriginalFilename(preparedUploadFile.getFileName());
|
||||
String objectName = snowflakeIdGenerator.nextIdString() + resolveFileExtension(originalFilename);
|
||||
String fileUrl = primaryObjectStorageService.uploadStream(inputStream, preparedUploadFile.getFileSize(), preparedUploadFile.getContentType(), objectName);
|
||||
ObjectStorageFileVO fileVO = createCommentImageRecord(originalFilename, fileUrl, objectName, preparedUploadFile.getContentType(), preparedUploadFile.getFileSize());
|
||||
chunkUploadService.clearCommentImageUpload(userId, requestDTO.getUploadId());
|
||||
return Result.success(fileVO);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("评价图片上传失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/upload-image/{uploadId}")
|
||||
@OperationGuard(action = "comment-image-upload-cancel", ttlSeconds = 30, message = "图片正在上传中,请勿重复操作")
|
||||
public Result<Boolean> cancelCommentImageUpload(HttpServletRequest request, @PathVariable String uploadId) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
if (userId == null) {
|
||||
return Result.error("请先登录后再取消上传");
|
||||
}
|
||||
chunkUploadService.clearCommentImageUpload(userId, uploadId);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
public Result<Boolean> updateComment(HttpServletRequest request, @PathVariable Long id, @RequestBody CommentDTO commentDTO) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
@@ -104,12 +138,6 @@ public class CommentController {
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除评论
|
||||
*
|
||||
* @param id 评论ID
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result<Boolean> deleteComment(HttpServletRequest request, @PathVariable Long id) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
@@ -117,74 +145,71 @@ public class CommentController {
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询评论
|
||||
*
|
||||
* @param id 评论ID
|
||||
* @return 评论VO
|
||||
*/
|
||||
@GetMapping("/get/{id}")
|
||||
public Result<CommentVO> getCommentById(@PathVariable Long id) {
|
||||
CommentVO commentVO = commentService.getCommentById(id);
|
||||
return Result.success(commentVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有评论
|
||||
*
|
||||
* @return 评论VO列表
|
||||
*/
|
||||
@GetMapping("/list/all")
|
||||
public Result<List<CommentVO>> listAllComments() {
|
||||
List<CommentVO> commentVOs = commentService.listAllComments();
|
||||
return Result.success(commentVOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询评论
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 评论VO列表
|
||||
*/
|
||||
@GetMapping("/list/user/{userId}")
|
||||
public Result<List<CommentVO>> listCommentsByUserId(@PathVariable Long userId) {
|
||||
List<CommentVO> commentVOs = commentService.listCommentsByUserId(userId);
|
||||
return Result.success(commentVOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据店铺ID查询评论
|
||||
*
|
||||
* @param shopId 店铺ID
|
||||
* @return 评论VO列表
|
||||
*/
|
||||
@GetMapping("/list/shop/{shopId}")
|
||||
public Result<List<CommentVO>> listCommentsByShopId(@PathVariable Long shopId) {
|
||||
List<CommentVO> commentVOs = commentService.listCommentsByShopId(shopId);
|
||||
return Result.success(commentVOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商品ID查询评论
|
||||
*
|
||||
* @param productId 商品ID
|
||||
* @return 评论VO列表
|
||||
*/
|
||||
@GetMapping("/list/product/{productId}")
|
||||
public Result<List<CommentVO>> listCommentsByProductId(@PathVariable Long productId) {
|
||||
List<CommentVO> commentVOs = commentService.listCommentsByProductId(productId);
|
||||
return Result.success(commentVOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父级评论ID查询回复
|
||||
*
|
||||
* @param parentCommentId 父级评论ID
|
||||
* @return 评论VO列表
|
||||
*/
|
||||
@GetMapping("/list/parent/{parentCommentId}")
|
||||
public Result<List<CommentVO>> listCommentsByParentCommentId(@PathVariable Long parentCommentId) {
|
||||
List<CommentVO> commentVOs = commentService.listCommentsByParentCommentId(parentCommentId);
|
||||
return Result.success(commentVOs);
|
||||
}
|
||||
|
||||
private ObjectStorageFileVO createCommentImageRecord(String originalFilename, String fileUrl, String objectName, String contentType, Long fileSize) {
|
||||
ObjectStorageFileDTO dto = new ObjectStorageFileDTO();
|
||||
dto.setFileName(originalFilename);
|
||||
dto.setFileUrl(fileUrl);
|
||||
dto.setObjectName(objectName);
|
||||
dto.setPrimaryProvider(objectStorageProperties.getPrimaryProvider());
|
||||
dto.setPrimaryUrl(fileUrl);
|
||||
dto.setBackupProvider(objectStorageProperties.getBackupProvider());
|
||||
dto.setContentType(contentType);
|
||||
dto.setFileSize(fileSize);
|
||||
dto.setPrimaryUploadStatus(1);
|
||||
dto.setBackupUploadStatus(0);
|
||||
dto.setBackupRetryCount(0);
|
||||
dto.setStatus(1);
|
||||
Long fileId = objectStorageFileService.createObjectStorageFile(dto);
|
||||
return objectStorageFileService.getObjectStorageFileById(fileId);
|
||||
}
|
||||
|
||||
private String normalizeOriginalFilename(String originalFilename) {
|
||||
if (originalFilename == null || originalFilename.isBlank()) {
|
||||
return "comment-image";
|
||||
}
|
||||
return originalFilename;
|
||||
}
|
||||
|
||||
private String resolveFileExtension(String originalFilename) {
|
||||
if (originalFilename == null || !originalFilename.contains(".")) {
|
||||
return "";
|
||||
}
|
||||
return originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
}
|
||||
}
|
||||
|
||||
+17
-3
@@ -8,19 +8,33 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@Validated
|
||||
@ConfigurationProperties(prefix = "aliyun.oss")
|
||||
public class AliyunOssConfig {
|
||||
|
||||
private boolean enabled = false;
|
||||
@NotNull
|
||||
private Boolean enabled;
|
||||
@NotBlank
|
||||
private String endpoint;
|
||||
@NotBlank
|
||||
private String region;
|
||||
private String bucketName = "fingertipdesigner";
|
||||
@NotBlank
|
||||
private String bucketName;
|
||||
@NotBlank
|
||||
private String accessKeyId;
|
||||
@NotBlank
|
||||
private String accessKeySecret;
|
||||
private int signedUrlExpireMinutes = 30;
|
||||
@NotNull
|
||||
@Min(1)
|
||||
private Integer signedUrlExpireMinutes;
|
||||
|
||||
@Bean(destroyMethod = "shutdown")
|
||||
@ConditionalOnProperty(prefix = "aliyun.oss", name = "enabled", havingValue = "true")
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package com.xiaowang.yuminailcore.modules.file.config;
|
||||
|
||||
import com.qiniu.common.Zone;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
import com.qiniu.util.Auth;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@Validated
|
||||
@ConfigurationProperties(prefix = "qiniu.kodo")
|
||||
public class QiniuKodoConfig {
|
||||
|
||||
@NotBlank
|
||||
private String accessKey;
|
||||
|
||||
@NotBlank
|
||||
private String secretKey;
|
||||
|
||||
@NotBlank
|
||||
private String bucketName;
|
||||
|
||||
@NotBlank
|
||||
private String domain;
|
||||
|
||||
@NotBlank
|
||||
private String zone;
|
||||
|
||||
@NotNull
|
||||
private Boolean privateBucket;
|
||||
|
||||
@NotNull
|
||||
@Min(1)
|
||||
private Integer signedUrlExpireMinutes;
|
||||
|
||||
@Bean
|
||||
public Auth qiniuAuth() {
|
||||
return Auth.create(accessKey, secretKey);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public com.qiniu.storage.Configuration qiniuConfiguration() {
|
||||
return new com.qiniu.storage.Configuration(resolveZone());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UploadManager qiniuUploadManager(com.qiniu.storage.Configuration qiniuConfiguration) {
|
||||
return new UploadManager(qiniuConfiguration);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public BucketManager qiniuBucketManager(com.qiniu.storage.Configuration qiniuConfiguration, Auth qiniuAuth) {
|
||||
return new BucketManager(qiniuAuth, qiniuConfiguration);
|
||||
}
|
||||
|
||||
private Zone resolveZone() {
|
||||
String normalizedZone = zone.trim().toLowerCase();
|
||||
switch (normalizedZone) {
|
||||
case "z0":
|
||||
return Zone.zone0();
|
||||
case "z1":
|
||||
return Zone.zone1();
|
||||
case "z2":
|
||||
return Zone.zone2();
|
||||
case "na0":
|
||||
return Zone.zoneNa0();
|
||||
case "as0":
|
||||
return Zone.zoneAs0();
|
||||
default:
|
||||
throw new IllegalStateException("Unsupported Qiniu zone: " + zone);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -57,7 +57,7 @@ public class FrontendFileController {
|
||||
|
||||
private boolean hasObjectStorageReference(ObjectStorageFileVO fileVO) {
|
||||
return StringUtils.hasText(fileVO.getObjectName())
|
||||
|| StringUtils.hasText(objectStorageUrlSupport.extractObjectName(fileVO.getMinioUrl()))
|
||||
|| StringUtils.hasText(objectStorageUrlSupport.extractObjectName(fileVO.getPrimaryUrl()))
|
||||
|| StringUtils.hasText(objectStorageUrlSupport.extractObjectName(fileVO.getFileUrl()));
|
||||
}
|
||||
|
||||
|
||||
+19
-13
@@ -1,13 +1,14 @@
|
||||
package com.xiaowang.yuminailcore.modules.file.controller.front;
|
||||
|
||||
import com.xiaowang.yuminailcore.annotation.OperationGuard;
|
||||
import com.xiaowang.yuminailcore.config.ObjectStorageProperties;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.modules.file.dto.ChunkUploadCompleteRequestDTO;
|
||||
import com.xiaowang.yuminailcore.modules.file.dto.ChunkUploadInitRequestDTO;
|
||||
import com.xiaowang.yuminailcore.modules.file.dto.ObjectStorageFileDTO;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.ChunkUploadService;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.MinioService;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.ObjectStorageFileService;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.PrimaryObjectStorageService;
|
||||
import com.xiaowang.yuminailcore.modules.file.support.ObjectStorageUrlSupport;
|
||||
import com.xiaowang.yuminailcore.support.id.TimeOrderedSnowflakeIdGenerator;
|
||||
import com.xiaowang.yuminailcore.support.security.OperationGuardStrategy;
|
||||
@@ -45,9 +46,9 @@ public class ObjectStorageFileController {
|
||||
*/
|
||||
private final ObjectStorageFileService objectStorageFileService;
|
||||
/**
|
||||
* Variable `minioService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
* Variable `primaryObjectStorageService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final MinioService minioService;
|
||||
private final PrimaryObjectStorageService primaryObjectStorageService;
|
||||
/**
|
||||
* Variable `chunkUploadService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
@@ -65,6 +66,7 @@ public class ObjectStorageFileController {
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private final UploadSecurityValidator uploadSecurityValidator;
|
||||
private final ObjectStorageProperties objectStorageProperties;
|
||||
|
||||
@PostMapping("/upload/init")
|
||||
@OperationGuard(action = "admin-upload-init", ttlSeconds = 10, message = "上传处理中,请勿重复操作")
|
||||
@@ -100,7 +102,7 @@ public class ObjectStorageFileController {
|
||||
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
String objectName = snowflakeIdGenerator.nextIdString() + fileExtension;
|
||||
|
||||
String fileUrl = minioService.uploadStream(
|
||||
String fileUrl = primaryObjectStorageService.uploadStream(
|
||||
inputStream,
|
||||
preparedUploadFile.getFileSize(),
|
||||
preparedUploadFile.getContentType(),
|
||||
@@ -111,12 +113,14 @@ public class ObjectStorageFileController {
|
||||
dto.setFileName(originalFilename);
|
||||
dto.setFileUrl(fileUrl);
|
||||
dto.setObjectName(objectName);
|
||||
dto.setMinioUrl(fileUrl);
|
||||
dto.setPrimaryProvider(objectStorageProperties.getPrimaryProvider());
|
||||
dto.setPrimaryUrl(fileUrl);
|
||||
dto.setBackupProvider(objectStorageProperties.getBackupProvider());
|
||||
dto.setContentType(preparedUploadFile.getContentType());
|
||||
dto.setFileSize(preparedUploadFile.getFileSize());
|
||||
dto.setMinioUploadStatus(1);
|
||||
dto.setOssUploadStatus(0);
|
||||
dto.setOssRetryCount(0);
|
||||
dto.setPrimaryUploadStatus(1);
|
||||
dto.setBackupUploadStatus(0);
|
||||
dto.setBackupRetryCount(0);
|
||||
dto.setStatus(1);
|
||||
|
||||
Long fileId = objectStorageFileService.createObjectStorageFile(dto);
|
||||
@@ -155,18 +159,20 @@ public class ObjectStorageFileController {
|
||||
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
String objectName = snowflakeIdGenerator.nextIdString() + fileExtension;
|
||||
|
||||
String fileUrl = minioService.uploadFile(file, objectName);
|
||||
String fileUrl = primaryObjectStorageService.uploadFile(file, objectName);
|
||||
|
||||
ObjectStorageFileDTO dto = new ObjectStorageFileDTO();
|
||||
dto.setFileName(originalFilename);
|
||||
dto.setFileUrl(fileUrl);
|
||||
dto.setObjectName(objectName);
|
||||
dto.setMinioUrl(fileUrl);
|
||||
dto.setPrimaryProvider(objectStorageProperties.getPrimaryProvider());
|
||||
dto.setPrimaryUrl(fileUrl);
|
||||
dto.setBackupProvider(objectStorageProperties.getBackupProvider());
|
||||
dto.setContentType(file.getContentType());
|
||||
dto.setFileSize(file.getSize());
|
||||
dto.setMinioUploadStatus(1);
|
||||
dto.setOssUploadStatus(0);
|
||||
dto.setOssRetryCount(0);
|
||||
dto.setPrimaryUploadStatus(1);
|
||||
dto.setBackupUploadStatus(0);
|
||||
dto.setBackupRetryCount(0);
|
||||
dto.setStatus(1);
|
||||
|
||||
Long fileId = objectStorageFileService.createObjectStorageFile(dto);
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import lombok.NoArgsConstructor;
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class OssBackupUploadMessage {
|
||||
public class ObjectStorageBackupMessage {
|
||||
|
||||
private Long fileId;
|
||||
}
|
||||
+12
-8
@@ -26,25 +26,29 @@ public class ObjectStorageFileDTO {
|
||||
|
||||
private String objectName;
|
||||
|
||||
private String minioUrl;
|
||||
private String primaryProvider;
|
||||
|
||||
private String ossUrl;
|
||||
private String primaryUrl;
|
||||
|
||||
private String backupProvider;
|
||||
|
||||
private String backupUrl;
|
||||
|
||||
private String contentType;
|
||||
|
||||
private Long fileSize;
|
||||
|
||||
private Integer minioUploadStatus;
|
||||
private Integer primaryUploadStatus;
|
||||
|
||||
private Integer ossUploadStatus;
|
||||
private Integer backupUploadStatus;
|
||||
|
||||
private Integer ossRetryCount;
|
||||
private Integer backupRetryCount;
|
||||
|
||||
private String ossLastError;
|
||||
private String backupLastError;
|
||||
|
||||
private LocalDateTime ossUploadedAt;
|
||||
private LocalDateTime backupUploadedAt;
|
||||
|
||||
private LocalDateTime ossLastRetryTime;
|
||||
private LocalDateTime backupLastRetryTime;
|
||||
|
||||
/**
|
||||
* 文件状态:1-可用,0-不可用,2-回收站
|
||||
|
||||
+22
-16
@@ -35,11 +35,17 @@ public class ObjectStorageFileDO extends BaseEntity {
|
||||
@TableField("object_name")
|
||||
private String objectName;
|
||||
|
||||
@TableField("minio_url")
|
||||
private String minioUrl;
|
||||
@TableField("primary_provider")
|
||||
private String primaryProvider;
|
||||
|
||||
@TableField("oss_url")
|
||||
private String ossUrl;
|
||||
@TableField("primary_url")
|
||||
private String primaryUrl;
|
||||
|
||||
@TableField("backup_provider")
|
||||
private String backupProvider;
|
||||
|
||||
@TableField("backup_url")
|
||||
private String backupUrl;
|
||||
|
||||
@TableField("content_type")
|
||||
private String contentType;
|
||||
@@ -47,23 +53,23 @@ public class ObjectStorageFileDO extends BaseEntity {
|
||||
@TableField("file_size")
|
||||
private Long fileSize;
|
||||
|
||||
@TableField("minio_upload_status")
|
||||
private Integer minioUploadStatus;
|
||||
@TableField("primary_upload_status")
|
||||
private Integer primaryUploadStatus;
|
||||
|
||||
@TableField("oss_upload_status")
|
||||
private Integer ossUploadStatus;
|
||||
@TableField("backup_upload_status")
|
||||
private Integer backupUploadStatus;
|
||||
|
||||
@TableField("oss_retry_count")
|
||||
private Integer ossRetryCount;
|
||||
@TableField("backup_retry_count")
|
||||
private Integer backupRetryCount;
|
||||
|
||||
@TableField("oss_last_error")
|
||||
private String ossLastError;
|
||||
@TableField("backup_last_error")
|
||||
private String backupLastError;
|
||||
|
||||
@TableField("oss_uploaded_at")
|
||||
private LocalDateTime ossUploadedAt;
|
||||
@TableField("backup_uploaded_at")
|
||||
private LocalDateTime backupUploadedAt;
|
||||
|
||||
@TableField("oss_last_retry_time")
|
||||
private LocalDateTime ossLastRetryTime;
|
||||
@TableField("backup_last_retry_time")
|
||||
private LocalDateTime backupLastRetryTime;
|
||||
|
||||
/**
|
||||
* 文件状态:1-可用,0-不可用,2-回收站
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.xiaowang.yuminailcore.modules.file.mq;
|
||||
|
||||
import com.xiaowang.yuminailcore.modules.file.dto.ObjectStorageBackupMessage;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.ObjectStorageBackupService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ObjectStorageBackupMessageListener {
|
||||
|
||||
private final ObjectStorageBackupService objectStorageBackupService;
|
||||
|
||||
@RabbitListener(queues = "#{objectStorageProperties.backupQueueName}")
|
||||
public void handle(ObjectStorageBackupMessage message) {
|
||||
if (message == null || message.getFileId() == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
objectStorageBackupService.backupFile(message.getFileId());
|
||||
} catch (Exception e) {
|
||||
log.warn("Handle object storage backup message failed, fileId={}", message.getFileId(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-7
@@ -1,7 +1,7 @@
|
||||
package com.xiaowang.yuminailcore.modules.file.mq;
|
||||
|
||||
import com.xiaowang.yuminailcore.config.RabbitMQConfig;
|
||||
import com.xiaowang.yuminailcore.modules.file.dto.OssBackupUploadMessage;
|
||||
import com.xiaowang.yuminailcore.config.ObjectStorageProperties;
|
||||
import com.xiaowang.yuminailcore.modules.file.dto.ObjectStorageBackupMessage;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
@@ -10,9 +10,10 @@ import org.springframework.stereotype.Component;
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class OssBackupMessagePublisher {
|
||||
public class ObjectStorageBackupMessagePublisher {
|
||||
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
private final ObjectStorageProperties objectStorageProperties;
|
||||
|
||||
public void publish(Long fileId) {
|
||||
if (fileId == null || fileId <= 0) {
|
||||
@@ -20,12 +21,12 @@ public class OssBackupMessagePublisher {
|
||||
}
|
||||
try {
|
||||
rabbitTemplate.convertAndSend(
|
||||
RabbitMQConfig.FILE_OSS_BACKUP_EXCHANGE,
|
||||
RabbitMQConfig.FILE_OSS_BACKUP_ROUTING_KEY,
|
||||
new OssBackupUploadMessage(fileId)
|
||||
objectStorageProperties.getBackupExchangeName(),
|
||||
objectStorageProperties.getBackupRoutingKey(),
|
||||
new ObjectStorageBackupMessage(fileId)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
log.warn("Publish OSS backup message failed, fileId={}", fileId, e);
|
||||
log.warn("Publish object storage backup message failed, fileId={}", fileId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
package com.xiaowang.yuminailcore.modules.file.mq;
|
||||
|
||||
import com.xiaowang.yuminailcore.config.RabbitMQConfig;
|
||||
import com.xiaowang.yuminailcore.modules.file.dto.OssBackupUploadMessage;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.OssBackupService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class OssBackupMessageListener {
|
||||
|
||||
private final OssBackupService ossBackupService;
|
||||
|
||||
@RabbitListener(queues = RabbitMQConfig.FILE_OSS_BACKUP_QUEUE)
|
||||
public void handle(OssBackupUploadMessage message) {
|
||||
if (message == null || message.getFileId() == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ossBackupService.backupFileToOss(message.getFileId());
|
||||
} catch (Exception e) {
|
||||
log.warn("Handle OSS backup message failed, fileId={}", message.getFileId(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.xiaowang.yuminailcore.modules.file.scheduler;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.xiaowang.yuminailcore.config.ObjectStorageProperties;
|
||||
import com.xiaowang.yuminailcore.modules.file.entity.ObjectStorageFileDO;
|
||||
import com.xiaowang.yuminailcore.modules.file.mapper.ObjectStorageFileMapper;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.ObjectStorageBackupService;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.impl.ObjectStorageBackupServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ObjectStorageBackupRetryScheduler {
|
||||
|
||||
private final ObjectStorageFileMapper objectStorageFileMapper;
|
||||
private final ObjectStorageBackupService objectStorageBackupService;
|
||||
private final ObjectStorageProperties objectStorageProperties;
|
||||
|
||||
@Scheduled(cron = "${object-storage.backup-retry-cron}", zone = "Asia/Shanghai")
|
||||
public void retryPendingOrFailedBackups() {
|
||||
List<ObjectStorageFileDO> files = objectStorageFileMapper.selectList(
|
||||
Wrappers.lambdaQuery(ObjectStorageFileDO.class)
|
||||
.eq(ObjectStorageFileDO::getStatus, 1)
|
||||
.eq(ObjectStorageFileDO::getPrimaryProvider, objectStorageProperties.getPrimaryProvider())
|
||||
.eq(ObjectStorageFileDO::getBackupProvider, objectStorageProperties.getBackupProvider())
|
||||
.eq(ObjectStorageFileDO::getPrimaryUploadStatus, ObjectStorageBackupServiceImpl.UPLOAD_STATUS_SUCCEEDED)
|
||||
.in(ObjectStorageFileDO::getBackupUploadStatus,
|
||||
ObjectStorageBackupServiceImpl.UPLOAD_STATUS_PENDING,
|
||||
ObjectStorageBackupServiceImpl.UPLOAD_STATUS_FAILED)
|
||||
.last("LIMIT " + objectStorageProperties.getBackupRetryBatchLimit())
|
||||
);
|
||||
for (ObjectStorageFileDO file : files) {
|
||||
try {
|
||||
objectStorageBackupService.backupFile(file.getId());
|
||||
} catch (Exception e) {
|
||||
log.warn("Retry object storage backup failed, fileId={}", file.getId(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
package com.xiaowang.yuminailcore.modules.file.scheduler;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.xiaowang.yuminailcore.modules.file.entity.ObjectStorageFileDO;
|
||||
import com.xiaowang.yuminailcore.modules.file.mapper.ObjectStorageFileMapper;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.OssBackupService;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.impl.OssBackupServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class OssBackupRetryScheduler {
|
||||
|
||||
private static final int BATCH_LIMIT = 500;
|
||||
|
||||
private final ObjectStorageFileMapper objectStorageFileMapper;
|
||||
private final OssBackupService ossBackupService;
|
||||
|
||||
@Scheduled(cron = "0 0 2 * * ?", zone = "Asia/Shanghai")
|
||||
public void retryPendingOrFailedBackups() {
|
||||
List<ObjectStorageFileDO> files = objectStorageFileMapper.selectList(
|
||||
Wrappers.lambdaQuery(ObjectStorageFileDO.class)
|
||||
.eq(ObjectStorageFileDO::getStatus, 1)
|
||||
.eq(ObjectStorageFileDO::getMinioUploadStatus, OssBackupServiceImpl.UPLOAD_STATUS_SUCCEEDED)
|
||||
.in(ObjectStorageFileDO::getOssUploadStatus,
|
||||
OssBackupServiceImpl.UPLOAD_STATUS_PENDING,
|
||||
OssBackupServiceImpl.UPLOAD_STATUS_FAILED)
|
||||
.last("LIMIT " + BATCH_LIMIT)
|
||||
);
|
||||
for (ObjectStorageFileDO file : files) {
|
||||
try {
|
||||
ossBackupService.backupFileToOss(file.getId());
|
||||
} catch (Exception e) {
|
||||
log.warn("Retry OSS backup failed, fileId={}", file.getId(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -30,6 +30,10 @@ public interface ChunkUploadService {
|
||||
*/
|
||||
ChunkUploadSessionVO initUserAvatarUpload(Long ownerId, ChunkUploadInitRequestDTO requestDTO);
|
||||
|
||||
ChunkUploadSessionVO initUserProfileImageUpload(Long ownerId, ChunkUploadInitRequestDTO requestDTO);
|
||||
|
||||
ChunkUploadSessionVO initCommentImageUpload(Long ownerId, ChunkUploadInitRequestDTO requestDTO);
|
||||
|
||||
/**
|
||||
* Run business method `uploadAdminObjectStorageChunk`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
@@ -52,6 +56,10 @@ public interface ChunkUploadService {
|
||||
*/
|
||||
void uploadUserAvatarChunk(Long ownerId, String uploadId, Integer chunkIndex, Integer totalChunks, MultipartFile chunkFile);
|
||||
|
||||
void uploadUserProfileImageChunk(Long ownerId, String uploadId, Integer chunkIndex, Integer totalChunks, MultipartFile chunkFile);
|
||||
|
||||
void uploadCommentImageChunk(Long ownerId, String uploadId, Integer chunkIndex, Integer totalChunks, MultipartFile chunkFile);
|
||||
|
||||
/**
|
||||
* Run business method `prepareAdminObjectStorageFile`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
@@ -70,6 +78,10 @@ public interface ChunkUploadService {
|
||||
*/
|
||||
PreparedUploadFile prepareUserAvatarFile(Long ownerId, String uploadId);
|
||||
|
||||
PreparedUploadFile prepareUserProfileImageFile(Long ownerId, String uploadId);
|
||||
|
||||
PreparedUploadFile prepareCommentImageFile(Long ownerId, String uploadId);
|
||||
|
||||
/**
|
||||
* Run business method `clearAdminObjectStorageUpload`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
@@ -85,6 +97,10 @@ public interface ChunkUploadService {
|
||||
* @param uploadId parameter `uploadId` supplied by the caller
|
||||
*/
|
||||
void clearUserAvatarUpload(Long ownerId, String uploadId);
|
||||
|
||||
void clearUserProfileImageUpload(Long ownerId, String uploadId);
|
||||
|
||||
void clearCommentImageUpload(Long ownerId, String uploadId);
|
||||
/**
|
||||
* PreparedUploadFile declares the business contract used by controllers. Implementations live in the matching ServiceImpl class.
|
||||
* Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
|
||||
|
||||
-78
@@ -1,78 +0,0 @@
|
||||
package com.xiaowang.yuminailcore.modules.file.service;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.InputStream;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
/**
|
||||
* MinioService declares the business contract used by controllers. Implementations live in the matching ServiceImpl class.
|
||||
* Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
|
||||
*/
|
||||
public interface MinioService {
|
||||
|
||||
/**
|
||||
* Run business method `uploadFile`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param file parameter `file` supplied by the caller
|
||||
* @param objectName parameter `objectName` supplied by the caller
|
||||
* @return String result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
String uploadFile(MultipartFile file, String objectName) throws Exception;
|
||||
|
||||
/**
|
||||
* Run business method `uploadStream`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param inputStream parameter `inputStream` supplied by the caller
|
||||
* @param fileSize parameter `fileSize` supplied by the caller
|
||||
* @param contentType parameter `contentType` supplied by the caller
|
||||
* @param objectName parameter `objectName` supplied by the caller
|
||||
* @return String result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
String uploadStream(InputStream inputStream, long fileSize, String contentType, String objectName) throws Exception;
|
||||
|
||||
/**
|
||||
* Run business method `downloadFile`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param objectName parameter `objectName` supplied by the caller
|
||||
* @return InputStream result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
InputStream downloadFile(String objectName) throws Exception;
|
||||
|
||||
/**
|
||||
* Delete, revoke, or logically remove a record.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param objectName parameter `objectName` supplied by the caller
|
||||
*/
|
||||
void deleteFile(String objectName) throws Exception;
|
||||
|
||||
/**
|
||||
* Load data by the supplied parameter.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param objectName parameter `objectName` supplied by the caller
|
||||
* @return String result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
String getFileUrl(String objectName);
|
||||
|
||||
/**
|
||||
* Load data by the supplied parameter.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param objectName parameter `objectName` supplied by the caller
|
||||
* @param expiryTimeInMinutes parameter `expiryTimeInMinutes` supplied by the caller
|
||||
* @return String result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
String getPresignedUrl(String objectName, int expiryTimeInMinutes) throws Exception;
|
||||
|
||||
/**
|
||||
* Run business method `bucketExists`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param bucketName parameter `bucketName` supplied by the caller
|
||||
* @return boolean result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
boolean bucketExists(String bucketName) throws Exception;
|
||||
|
||||
/**
|
||||
* Run business method `makeBucket`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param bucketName parameter `bucketName` supplied by the caller
|
||||
*/
|
||||
void makeBucket(String bucketName) throws Exception;
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package com.xiaowang.yuminailcore.modules.file.service;
|
||||
|
||||
public interface ObjectStorageBackupService {
|
||||
|
||||
void backupFile(Long fileId);
|
||||
}
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
package com.xiaowang.yuminailcore.modules.file.service;
|
||||
|
||||
public interface OssBackupService {
|
||||
|
||||
void backupFileToOss(Long fileId);
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.xiaowang.yuminailcore.modules.file.service;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public interface PrimaryObjectStorageService {
|
||||
|
||||
String uploadFile(MultipartFile file, String objectName) throws Exception;
|
||||
|
||||
String uploadStream(InputStream inputStream, long fileSize, String contentType, String objectName) throws Exception;
|
||||
|
||||
InputStream downloadFile(String objectName) throws Exception;
|
||||
|
||||
void deleteFile(String objectName) throws Exception;
|
||||
|
||||
String getFileUrl(String objectName);
|
||||
|
||||
String getPresignedUrl(String objectName, Integer expiryTimeInMinutes) throws Exception;
|
||||
}
|
||||
+43
-1
@@ -105,6 +105,16 @@ public class ChunkUploadServiceImpl implements ChunkUploadService {
|
||||
return initUpload(UploadTargetType.USER_AVATAR, ownerId, requestDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkUploadSessionVO initUserProfileImageUpload(Long ownerId, ChunkUploadInitRequestDTO requestDTO) {
|
||||
return initUpload(UploadTargetType.USER_PROFILE_IMAGE, ownerId, requestDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkUploadSessionVO initCommentImageUpload(Long ownerId, ChunkUploadInitRequestDTO requestDTO) {
|
||||
return initUpload(UploadTargetType.COMMENT_IMAGE, ownerId, requestDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Run business method `uploadAdminObjectStorageChunk`.
|
||||
@@ -155,6 +165,16 @@ public class ChunkUploadServiceImpl implements ChunkUploadService {
|
||||
uploadChunk(UploadTargetType.USER_AVATAR, ownerId, uploadId, chunkIndex, totalChunks, chunkFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadUserProfileImageChunk(Long ownerId, String uploadId, Integer chunkIndex, Integer totalChunks, MultipartFile chunkFile) {
|
||||
uploadChunk(UploadTargetType.USER_PROFILE_IMAGE, ownerId, uploadId, chunkIndex, totalChunks, chunkFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadCommentImageChunk(Long ownerId, String uploadId, Integer chunkIndex, Integer totalChunks, MultipartFile chunkFile) {
|
||||
uploadChunk(UploadTargetType.COMMENT_IMAGE, ownerId, uploadId, chunkIndex, totalChunks, chunkFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Run business method `prepareAdminObjectStorageFile`.
|
||||
@@ -195,6 +215,16 @@ public class ChunkUploadServiceImpl implements ChunkUploadService {
|
||||
return prepareMergedFile(UploadTargetType.USER_AVATAR, ownerId, uploadId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedUploadFile prepareUserProfileImageFile(Long ownerId, String uploadId) {
|
||||
return prepareMergedFile(UploadTargetType.USER_PROFILE_IMAGE, ownerId, uploadId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedUploadFile prepareCommentImageFile(Long ownerId, String uploadId) {
|
||||
return prepareMergedFile(UploadTargetType.COMMENT_IMAGE, ownerId, uploadId);
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Run business method `clearAdminObjectStorageUpload`.
|
||||
@@ -233,6 +263,16 @@ public class ChunkUploadServiceImpl implements ChunkUploadService {
|
||||
clearUpload(UploadTargetType.USER_AVATAR, ownerId, uploadId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearUserProfileImageUpload(Long ownerId, String uploadId) {
|
||||
clearUpload(UploadTargetType.USER_PROFILE_IMAGE, ownerId, uploadId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCommentImageUpload(Long ownerId, String uploadId) {
|
||||
clearUpload(UploadTargetType.COMMENT_IMAGE, ownerId, uploadId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run business method `initUpload`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
@@ -791,7 +831,9 @@ public class ChunkUploadServiceImpl implements ChunkUploadService {
|
||||
*/
|
||||
private enum UploadTargetType {
|
||||
ADMIN_OBJECT_STORAGE,
|
||||
USER_AVATAR
|
||||
USER_AVATAR,
|
||||
USER_PROFILE_IMAGE,
|
||||
COMMENT_IMAGE
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
-174
@@ -1,174 +0,0 @@
|
||||
package com.xiaowang.yuminailcore.modules.file.service.impl;
|
||||
|
||||
import com.xiaowang.yuminailcore.config.MinioConfig;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.MinioService;
|
||||
import io.minio.*;
|
||||
import io.minio.http.Method;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
/**
|
||||
* MinioServiceImpl contains the concrete business logic. It validates input, calls mappers/support services, and builds return objects.
|
||||
* Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
|
||||
*/
|
||||
public class MinioServiceImpl implements MinioService {
|
||||
/**
|
||||
* Variable `minioClient`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final MinioClient minioClient;
|
||||
/**
|
||||
* Variable `minioConfig`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final MinioConfig minioConfig;
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Run business method `uploadFile`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param file parameter `file` supplied by the caller
|
||||
* @param objectName parameter `objectName` supplied by the caller
|
||||
* @return String result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
public String uploadFile(MultipartFile file, String objectName) throws Exception {
|
||||
try {
|
||||
try (InputStream inputStream = file.getInputStream()) {
|
||||
return uploadStream(inputStream, file.getSize(), file.getContentType(), objectName);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("文件上传失败: {}", objectName, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Run business method `uploadStream`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param inputStream parameter `inputStream` supplied by the caller
|
||||
* @param fileSize parameter `fileSize` supplied by the caller
|
||||
* @param contentType parameter `contentType` supplied by the caller
|
||||
* @param objectName parameter `objectName` supplied by the caller
|
||||
* @return String result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
public String uploadStream(InputStream inputStream, long fileSize, String contentType, String objectName) throws Exception {
|
||||
try {
|
||||
minioClient.putObject(
|
||||
PutObjectArgs.builder()
|
||||
.bucket(minioConfig.getBucketName())
|
||||
.object(objectName)
|
||||
.stream(inputStream, fileSize, -1)
|
||||
.contentType(contentType)
|
||||
.build()
|
||||
);
|
||||
|
||||
log.info("文件上传成功: {}", objectName);
|
||||
/**
|
||||
* Load data by the supplied parameter.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param objectName parameter `objectName` supplied by the caller
|
||||
* @return return result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
return getFileUrl(objectName);
|
||||
} catch (Exception e) {
|
||||
log.error("文件上传失败: {}", objectName, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Run business method `downloadFile`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param objectName parameter `objectName` supplied by the caller
|
||||
* @return InputStream result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
public InputStream downloadFile(String objectName) throws Exception {
|
||||
return minioClient.getObject(
|
||||
GetObjectArgs.builder()
|
||||
.bucket(minioConfig.getBucketName())
|
||||
.object(objectName)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Delete, revoke, or logically remove a record.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param objectName parameter `objectName` supplied by the caller
|
||||
*/
|
||||
public void deleteFile(String objectName) throws Exception {
|
||||
minioClient.removeObject(
|
||||
RemoveObjectArgs.builder()
|
||||
.bucket(minioConfig.getBucketName())
|
||||
.object(objectName)
|
||||
.build()
|
||||
);
|
||||
log.info("文件删除成功: {}", objectName);
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Load data by the supplied parameter.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param objectName parameter `objectName` supplied by the caller
|
||||
* @return String result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
public String getFileUrl(String objectName) {
|
||||
return minioConfig.getEndpoint() + "/" + minioConfig.getBucketName() + "/" + objectName;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Load data by the supplied parameter.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param objectName parameter `objectName` supplied by the caller
|
||||
* @param expiryTimeInMinutes parameter `expiryTimeInMinutes` supplied by the caller
|
||||
* @return String result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
public String getPresignedUrl(String objectName, int expiryTimeInMinutes) throws Exception {
|
||||
String url = minioClient.getPresignedObjectUrl(
|
||||
GetPresignedObjectUrlArgs.builder()
|
||||
.method(Method.GET)
|
||||
.bucket(minioConfig.getBucketName())
|
||||
.object(objectName)
|
||||
.expiry(expiryTimeInMinutes, TimeUnit.MINUTES)
|
||||
.build()
|
||||
);
|
||||
log.info("生成带签名的临时访问链接: {}, 有效期: {}分钟", objectName, expiryTimeInMinutes);
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Run business method `bucketExists`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param bucketName parameter `bucketName` supplied by the caller
|
||||
* @return boolean result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
public boolean bucketExists(String bucketName) throws Exception {
|
||||
return minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Run business method `makeBucket`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param bucketName parameter `bucketName` supplied by the caller
|
||||
*/
|
||||
public void makeBucket(String bucketName) throws Exception {
|
||||
if (!bucketExists(bucketName)) {
|
||||
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
|
||||
log.info("Bucket 创建成功: {}", bucketName);
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
-20
@@ -1,11 +1,12 @@
|
||||
package com.xiaowang.yuminailcore.modules.file.service.impl;
|
||||
|
||||
import com.xiaowang.yuminailcore.config.ObjectStorageProperties;
|
||||
import com.xiaowang.yuminailcore.modules.file.entity.ObjectStorageFileDO;
|
||||
import com.xiaowang.yuminailcore.modules.file.mapper.ObjectStorageFileMapper;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.AliyunOssService;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.MinioService;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.ObjectStorageBackupService;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.ObjectStorageFileService;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.OssBackupService;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.PrimaryObjectStorageService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -17,7 +18,7 @@ import java.time.LocalDateTime;
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class OssBackupServiceImpl implements OssBackupService {
|
||||
public class ObjectStorageBackupServiceImpl implements ObjectStorageBackupService {
|
||||
|
||||
public static final int UPLOAD_STATUS_PENDING = 0;
|
||||
public static final int UPLOAD_STATUS_SUCCEEDED = 1;
|
||||
@@ -27,12 +28,13 @@ public class OssBackupServiceImpl implements OssBackupService {
|
||||
private static final int MAX_ERROR_LENGTH = 500;
|
||||
|
||||
private final ObjectStorageFileMapper objectStorageFileMapper;
|
||||
private final MinioService minioService;
|
||||
private final PrimaryObjectStorageService primaryObjectStorageService;
|
||||
private final AliyunOssService aliyunOssService;
|
||||
private final ObjectStorageFileService objectStorageFileService;
|
||||
private final ObjectStorageProperties objectStorageProperties;
|
||||
|
||||
@Override
|
||||
public void backupFileToOss(Long fileId) {
|
||||
public void backupFile(Long fileId) {
|
||||
if (fileId == null || fileId <= 0) {
|
||||
return;
|
||||
}
|
||||
@@ -41,16 +43,16 @@ public class OssBackupServiceImpl implements OssBackupService {
|
||||
return;
|
||||
}
|
||||
|
||||
try (InputStream inputStream = minioService.downloadFile(file.getObjectName())) {
|
||||
String ossUrl = aliyunOssService.uploadStream(
|
||||
try (InputStream inputStream = primaryObjectStorageService.downloadFile(file.getObjectName())) {
|
||||
String backupUrl = aliyunOssService.uploadStream(
|
||||
file.getObjectName(),
|
||||
inputStream,
|
||||
file.getFileSize() == null ? -1L : file.getFileSize(),
|
||||
file.getContentType()
|
||||
);
|
||||
markSucceeded(file, ossUrl);
|
||||
markSucceeded(file, backupUrl);
|
||||
} catch (Exception e) {
|
||||
log.warn("Backup file to Aliyun OSS failed, fileId={}", fileId, e);
|
||||
log.warn("Backup file to object storage failed, fileId={}", fileId, e);
|
||||
markFailed(file, e);
|
||||
}
|
||||
}
|
||||
@@ -58,25 +60,27 @@ public class OssBackupServiceImpl implements OssBackupService {
|
||||
private boolean shouldBackup(ObjectStorageFileDO file) {
|
||||
return file != null
|
||||
&& Integer.valueOf(ACTIVE_STATUS).equals(file.getStatus())
|
||||
&& Integer.valueOf(UPLOAD_STATUS_SUCCEEDED).equals(file.getMinioUploadStatus())
|
||||
&& !Integer.valueOf(UPLOAD_STATUS_SUCCEEDED).equals(file.getOssUploadStatus())
|
||||
&& objectStorageProperties.getPrimaryProvider().equals(file.getPrimaryProvider())
|
||||
&& objectStorageProperties.getBackupProvider().equals(file.getBackupProvider())
|
||||
&& Integer.valueOf(UPLOAD_STATUS_SUCCEEDED).equals(file.getPrimaryUploadStatus())
|
||||
&& !Integer.valueOf(UPLOAD_STATUS_SUCCEEDED).equals(file.getBackupUploadStatus())
|
||||
&& StringUtils.hasText(file.getObjectName());
|
||||
}
|
||||
|
||||
private void markSucceeded(ObjectStorageFileDO file, String ossUrl) {
|
||||
file.setOssUrl(ossUrl);
|
||||
file.setOssUploadStatus(UPLOAD_STATUS_SUCCEEDED);
|
||||
file.setOssUploadedAt(LocalDateTime.now());
|
||||
file.setOssLastError(null);
|
||||
private void markSucceeded(ObjectStorageFileDO file, String backupUrl) {
|
||||
file.setBackupUrl(backupUrl);
|
||||
file.setBackupUploadStatus(UPLOAD_STATUS_SUCCEEDED);
|
||||
file.setBackupUploadedAt(LocalDateTime.now());
|
||||
file.setBackupLastError(null);
|
||||
objectStorageFileMapper.updateById(file);
|
||||
objectStorageFileService.evictObjectStorageFileCache(file.getId());
|
||||
}
|
||||
|
||||
private void markFailed(ObjectStorageFileDO file, Exception e) {
|
||||
file.setOssUploadStatus(UPLOAD_STATUS_FAILED);
|
||||
file.setOssRetryCount((file.getOssRetryCount() == null ? 0 : file.getOssRetryCount()) + 1);
|
||||
file.setOssLastError(truncateError(e));
|
||||
file.setOssLastRetryTime(LocalDateTime.now());
|
||||
file.setBackupUploadStatus(UPLOAD_STATUS_FAILED);
|
||||
file.setBackupRetryCount((file.getBackupRetryCount() == null ? 0 : file.getBackupRetryCount()) + 1);
|
||||
file.setBackupLastError(truncateError(e));
|
||||
file.setBackupLastRetryTime(LocalDateTime.now());
|
||||
objectStorageFileMapper.updateById(file);
|
||||
objectStorageFileService.evictObjectStorageFileCache(file.getId());
|
||||
}
|
||||
+30
-23
@@ -3,11 +3,12 @@ package com.xiaowang.yuminailcore.modules.file.service.impl;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.xiaowang.yuminailcore.config.AppCacheProperties;
|
||||
import com.xiaowang.yuminailcore.config.ObjectStorageProperties;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.modules.file.dto.ObjectStorageFileDTO;
|
||||
import com.xiaowang.yuminailcore.modules.file.entity.ObjectStorageFileDO;
|
||||
import com.xiaowang.yuminailcore.modules.file.mapper.ObjectStorageFileMapper;
|
||||
import com.xiaowang.yuminailcore.modules.file.mq.OssBackupMessagePublisher;
|
||||
import com.xiaowang.yuminailcore.modules.file.mq.ObjectStorageBackupMessagePublisher;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.ObjectStorageFileService;
|
||||
import com.xiaowang.yuminailcore.support.cache.MultiLevelCacheService;
|
||||
import com.xiaowang.yuminailcore.modules.file.vo.ObjectStorageFileVO;
|
||||
@@ -55,7 +56,8 @@ public class ObjectStorageFileServiceImpl extends ServiceImpl<ObjectStorageFileM
|
||||
* Variable `appCacheProperties`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final AppCacheProperties appCacheProperties;
|
||||
private final OssBackupMessagePublisher ossBackupMessagePublisher;
|
||||
private final ObjectStorageBackupMessagePublisher objectStorageBackupMessagePublisher;
|
||||
private final ObjectStorageProperties objectStorageProperties;
|
||||
|
||||
@Override
|
||||
/**
|
||||
@@ -69,7 +71,7 @@ public class ObjectStorageFileServiceImpl extends ServiceImpl<ObjectStorageFileM
|
||||
applyDTO(objectStorageFileDO, objectStorageFileDTO);
|
||||
objectStorageFileMapper.insert(objectStorageFileDO);
|
||||
evictFileCache(objectStorageFileDO.getId());
|
||||
publishOssBackupIfNeeded(objectStorageFileDO);
|
||||
publishBackupIfNeeded(objectStorageFileDO);
|
||||
return objectStorageFileDO.getId();
|
||||
}
|
||||
|
||||
@@ -226,16 +228,18 @@ public class ObjectStorageFileServiceImpl extends ServiceImpl<ObjectStorageFileM
|
||||
objectStorageFileVO.setFileName(objectStorageFileDO.getFileName());
|
||||
objectStorageFileVO.setFileUrl(objectStorageFileDO.getFileUrl());
|
||||
objectStorageFileVO.setObjectName(objectStorageFileDO.getObjectName());
|
||||
objectStorageFileVO.setMinioUrl(objectStorageFileDO.getMinioUrl());
|
||||
objectStorageFileVO.setOssUrl(objectStorageFileDO.getOssUrl());
|
||||
objectStorageFileVO.setPrimaryProvider(objectStorageFileDO.getPrimaryProvider());
|
||||
objectStorageFileVO.setPrimaryUrl(objectStorageFileDO.getPrimaryUrl());
|
||||
objectStorageFileVO.setBackupProvider(objectStorageFileDO.getBackupProvider());
|
||||
objectStorageFileVO.setBackupUrl(objectStorageFileDO.getBackupUrl());
|
||||
objectStorageFileVO.setContentType(objectStorageFileDO.getContentType());
|
||||
objectStorageFileVO.setFileSize(objectStorageFileDO.getFileSize());
|
||||
objectStorageFileVO.setMinioUploadStatus(objectStorageFileDO.getMinioUploadStatus());
|
||||
objectStorageFileVO.setOssUploadStatus(objectStorageFileDO.getOssUploadStatus());
|
||||
objectStorageFileVO.setOssRetryCount(objectStorageFileDO.getOssRetryCount());
|
||||
objectStorageFileVO.setOssLastError(objectStorageFileDO.getOssLastError());
|
||||
objectStorageFileVO.setOssUploadedAt(objectStorageFileDO.getOssUploadedAt());
|
||||
objectStorageFileVO.setOssLastRetryTime(objectStorageFileDO.getOssLastRetryTime());
|
||||
objectStorageFileVO.setPrimaryUploadStatus(objectStorageFileDO.getPrimaryUploadStatus());
|
||||
objectStorageFileVO.setBackupUploadStatus(objectStorageFileDO.getBackupUploadStatus());
|
||||
objectStorageFileVO.setBackupRetryCount(objectStorageFileDO.getBackupRetryCount());
|
||||
objectStorageFileVO.setBackupLastError(objectStorageFileDO.getBackupLastError());
|
||||
objectStorageFileVO.setBackupUploadedAt(objectStorageFileDO.getBackupUploadedAt());
|
||||
objectStorageFileVO.setBackupLastRetryTime(objectStorageFileDO.getBackupLastRetryTime());
|
||||
objectStorageFileVO.setCreateTime(objectStorageFileDO.getCreateTime());
|
||||
objectStorageFileVO.setStatus(objectStorageFileDO.getStatus());
|
||||
objectStorageFileVO.setDeleteTime(objectStorageFileDO.getDeleteTime());
|
||||
@@ -247,26 +251,29 @@ public class ObjectStorageFileServiceImpl extends ServiceImpl<ObjectStorageFileM
|
||||
objectStorageFileDO.setFileName(objectStorageFileDTO.getFileName());
|
||||
objectStorageFileDO.setFileUrl(objectStorageFileDTO.getFileUrl());
|
||||
objectStorageFileDO.setObjectName(objectStorageFileDTO.getObjectName());
|
||||
objectStorageFileDO.setMinioUrl(objectStorageFileDTO.getMinioUrl());
|
||||
objectStorageFileDO.setOssUrl(objectStorageFileDTO.getOssUrl());
|
||||
objectStorageFileDO.setPrimaryProvider(objectStorageFileDTO.getPrimaryProvider());
|
||||
objectStorageFileDO.setPrimaryUrl(objectStorageFileDTO.getPrimaryUrl());
|
||||
objectStorageFileDO.setBackupProvider(objectStorageFileDTO.getBackupProvider());
|
||||
objectStorageFileDO.setBackupUrl(objectStorageFileDTO.getBackupUrl());
|
||||
objectStorageFileDO.setContentType(objectStorageFileDTO.getContentType());
|
||||
objectStorageFileDO.setFileSize(objectStorageFileDTO.getFileSize());
|
||||
objectStorageFileDO.setMinioUploadStatus(objectStorageFileDTO.getMinioUploadStatus());
|
||||
objectStorageFileDO.setOssUploadStatus(objectStorageFileDTO.getOssUploadStatus());
|
||||
objectStorageFileDO.setOssRetryCount(objectStorageFileDTO.getOssRetryCount());
|
||||
objectStorageFileDO.setOssLastError(objectStorageFileDTO.getOssLastError());
|
||||
objectStorageFileDO.setOssUploadedAt(objectStorageFileDTO.getOssUploadedAt());
|
||||
objectStorageFileDO.setOssLastRetryTime(objectStorageFileDTO.getOssLastRetryTime());
|
||||
objectStorageFileDO.setPrimaryUploadStatus(objectStorageFileDTO.getPrimaryUploadStatus());
|
||||
objectStorageFileDO.setBackupUploadStatus(objectStorageFileDTO.getBackupUploadStatus());
|
||||
objectStorageFileDO.setBackupRetryCount(objectStorageFileDTO.getBackupRetryCount());
|
||||
objectStorageFileDO.setBackupLastError(objectStorageFileDTO.getBackupLastError());
|
||||
objectStorageFileDO.setBackupUploadedAt(objectStorageFileDTO.getBackupUploadedAt());
|
||||
objectStorageFileDO.setBackupLastRetryTime(objectStorageFileDTO.getBackupLastRetryTime());
|
||||
objectStorageFileDO.setStatus(objectStorageFileDTO.getStatus());
|
||||
objectStorageFileDO.setDeleteTime(objectStorageFileDTO.getDeleteTime());
|
||||
objectStorageFileDO.setRecycleTime(objectStorageFileDTO.getRecycleTime());
|
||||
}
|
||||
|
||||
private void publishOssBackupIfNeeded(ObjectStorageFileDO objectStorageFileDO) {
|
||||
private void publishBackupIfNeeded(ObjectStorageFileDO objectStorageFileDO) {
|
||||
if (StringUtils.hasText(objectStorageFileDO.getObjectName())
|
||||
&& Integer.valueOf(1).equals(objectStorageFileDO.getMinioUploadStatus())
|
||||
&& Integer.valueOf(0).equals(objectStorageFileDO.getOssUploadStatus())) {
|
||||
ossBackupMessagePublisher.publish(objectStorageFileDO.getId());
|
||||
&& objectStorageProperties.getPrimaryProvider().equals(objectStorageFileDO.getPrimaryProvider())
|
||||
&& Integer.valueOf(1).equals(objectStorageFileDO.getPrimaryUploadStatus())
|
||||
&& Integer.valueOf(0).equals(objectStorageFileDO.getBackupUploadStatus())) {
|
||||
objectStorageBackupMessagePublisher.publish(objectStorageFileDO.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
package com.xiaowang.yuminailcore.modules.file.service.impl;
|
||||
|
||||
import com.qiniu.http.Response;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
import com.qiniu.storage.model.DefaultPutRet;
|
||||
import com.qiniu.util.Auth;
|
||||
import com.qiniu.util.StringMap;
|
||||
import com.xiaowang.yuminailcore.config.ObjectStorageProperties;
|
||||
import com.xiaowang.yuminailcore.modules.file.config.QiniuKodoConfig;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.PrimaryObjectStorageService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class QiniuObjectStorageServiceImpl implements PrimaryObjectStorageService {
|
||||
|
||||
private final QiniuKodoConfig qiniuKodoConfig;
|
||||
private final ObjectStorageProperties objectStorageProperties;
|
||||
private final Auth qiniuAuth;
|
||||
private final UploadManager qiniuUploadManager;
|
||||
private final BucketManager qiniuBucketManager;
|
||||
|
||||
@Override
|
||||
public String uploadFile(MultipartFile file, String objectName) throws Exception {
|
||||
try (InputStream inputStream = file.getInputStream()) {
|
||||
return uploadStream(inputStream, file.getSize(), file.getContentType(), objectName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadStream(InputStream inputStream, long fileSize, String contentType, String objectName) throws Exception {
|
||||
byte[] bytes = toBytes(inputStream);
|
||||
String uploadToken = qiniuAuth.uploadToken(
|
||||
qiniuKodoConfig.getBucketName(),
|
||||
objectName,
|
||||
buildUploadPolicyExpirySeconds(),
|
||||
new StringMap()
|
||||
);
|
||||
Response response = qiniuUploadManager.put(
|
||||
bytes,
|
||||
objectName,
|
||||
uploadToken,
|
||||
null,
|
||||
contentType,
|
||||
false
|
||||
);
|
||||
DefaultPutRet putRet = response.jsonToObject(DefaultPutRet.class);
|
||||
log.info("七牛云文件上传成功, key={}", putRet.key);
|
||||
return getFileUrl(objectName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream downloadFile(String objectName) throws Exception {
|
||||
URL url = new URL(getPresignedUrl(objectName, objectStorageProperties.getSignedUrlExpireMinutes()));
|
||||
return url.openStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFile(String objectName) throws Exception {
|
||||
qiniuBucketManager.delete(qiniuKodoConfig.getBucketName(), objectName);
|
||||
log.info("七牛云文件删除成功, key={}", objectName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileUrl(String objectName) {
|
||||
return normalizeDomain(qiniuKodoConfig.getDomain()) + "/" + objectName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPresignedUrl(String objectName, Integer expiryTimeInMinutes) throws Exception {
|
||||
if (!Boolean.TRUE.equals(qiniuKodoConfig.getPrivateBucket())) {
|
||||
return getFileUrl(objectName);
|
||||
}
|
||||
int expireMinutes = expiryTimeInMinutes == null || expiryTimeInMinutes <= 0
|
||||
? qiniuKodoConfig.getSignedUrlExpireMinutes()
|
||||
: expiryTimeInMinutes;
|
||||
return qiniuAuth.privateDownloadUrl(
|
||||
getFileUrl(objectName),
|
||||
TimeUnit.MINUTES.toSeconds(expireMinutes)
|
||||
);
|
||||
}
|
||||
|
||||
private long buildUploadPolicyExpirySeconds() {
|
||||
return TimeUnit.MINUTES.toSeconds(qiniuKodoConfig.getSignedUrlExpireMinutes());
|
||||
}
|
||||
|
||||
private byte[] toBytes(InputStream inputStream) throws Exception {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||
byte[] buffer = new byte[8192];
|
||||
int read;
|
||||
while ((read = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, read);
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
private String normalizeDomain(String domain) {
|
||||
String normalized = domain.trim();
|
||||
while (normalized.endsWith("/")) {
|
||||
normalized = normalized.substring(0, normalized.length() - 1);
|
||||
}
|
||||
if (!StringUtils.hasText(normalized)) {
|
||||
throw new IllegalStateException("Qiniu domain is blank");
|
||||
}
|
||||
if (!normalized.startsWith("http://") && !normalized.startsWith("https://")) {
|
||||
return "http://" + normalized;
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
}
|
||||
+38
-122
@@ -1,8 +1,9 @@
|
||||
package com.xiaowang.yuminailcore.modules.file.support;
|
||||
|
||||
import com.xiaowang.yuminailcore.config.MinioConfig;
|
||||
import com.xiaowang.yuminailcore.config.ObjectStorageProperties;
|
||||
import com.xiaowang.yuminailcore.modules.file.config.QiniuKodoConfig;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.AliyunOssService;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.MinioService;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.PrimaryObjectStorageService;
|
||||
import com.xiaowang.yuminailcore.modules.file.vo.ObjectStorageFileVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -16,16 +17,12 @@ import java.net.URI;
|
||||
@RequiredArgsConstructor
|
||||
public class ObjectStorageUrlSupport {
|
||||
|
||||
private static final int DEFAULT_SIGNED_URL_EXPIRE_MINUTES = 60;
|
||||
private static final long MINIO_HEALTH_CACHE_MILLIS = 60_000L;
|
||||
private static final int UPLOAD_STATUS_SUCCEEDED = 1;
|
||||
|
||||
private final MinioService minioService;
|
||||
private final MinioConfig minioConfig;
|
||||
private final PrimaryObjectStorageService primaryObjectStorageService;
|
||||
private final QiniuKodoConfig qiniuKodoConfig;
|
||||
private final AliyunOssService aliyunOssService;
|
||||
|
||||
private volatile boolean minioHealthy = true;
|
||||
private volatile long minioHealthCheckedAt = 0L;
|
||||
private final ObjectStorageProperties objectStorageProperties;
|
||||
|
||||
public String toAccessibleUrl(String fileUrl) {
|
||||
if (!StringUtils.hasText(fileUrl)) {
|
||||
@@ -36,15 +33,18 @@ public class ObjectStorageUrlSupport {
|
||||
return fileUrl;
|
||||
}
|
||||
try {
|
||||
return signWithMinio(objectName, DEFAULT_SIGNED_URL_EXPIRE_MINUTES);
|
||||
return primaryObjectStorageService.getPresignedUrl(
|
||||
objectName,
|
||||
objectStorageProperties.getSignedUrlExpireMinutes()
|
||||
);
|
||||
} catch (Exception e) {
|
||||
log.warn("Generate MinIO signed URL failed, fallback to safe display URL: {}", fileUrl, e);
|
||||
log.warn("生成主对象存储访问链接失败, fileUrl={}", fileUrl, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String toAccessibleUrl(ObjectStorageFileVO file) {
|
||||
return toAccessibleUrl(file, DEFAULT_SIGNED_URL_EXPIRE_MINUTES);
|
||||
return toAccessibleUrl(file, objectStorageProperties.getSignedUrlExpireMinutes());
|
||||
}
|
||||
|
||||
public String toAccessibleUrl(ObjectStorageFileVO file, Integer expiryTimeInMinutes) {
|
||||
@@ -54,8 +54,8 @@ public class ObjectStorageUrlSupport {
|
||||
try {
|
||||
return getSignedUrlOrThrow(file, expiryTimeInMinutes);
|
||||
} catch (Exception e) {
|
||||
String fallback = hasObjectStorageReference(file) ? null : firstText(file.getFileUrl(), file.getMinioUrl());
|
||||
log.warn("Generate object storage signed URL failed, fallback to safe display URL, fileId={}", file.getId(), e);
|
||||
String fallback = hasObjectStorageReference(file) ? null : firstText(file.getFileUrl(), file.getPrimaryUrl());
|
||||
log.warn("生成对象存储访问链接失败, fileId={}", file.getId(), e);
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
@@ -69,21 +69,15 @@ public class ObjectStorageUrlSupport {
|
||||
throw new IllegalStateException("No available object storage signed URL: objectName is empty");
|
||||
}
|
||||
|
||||
Exception minioFailure = null;
|
||||
int minioExpiry = expiryTimeInMinutes == null || expiryTimeInMinutes <= 0
|
||||
? DEFAULT_SIGNED_URL_EXPIRE_MINUTES
|
||||
: expiryTimeInMinutes;
|
||||
if (shouldTryMinio()) {
|
||||
try {
|
||||
return signWithMinio(objectName, minioExpiry);
|
||||
} catch (Exception e) {
|
||||
minioFailure = e;
|
||||
markMinioHealth(false);
|
||||
log.warn("Generate MinIO signed URL failed, fileId={}, objectName={}", file.getId(), objectName, e);
|
||||
}
|
||||
Exception primaryFailure = null;
|
||||
try {
|
||||
return primaryObjectStorageService.getPresignedUrl(objectName, expiryTimeInMinutes);
|
||||
} catch (Exception e) {
|
||||
primaryFailure = e;
|
||||
log.warn("生成主对象存储访问链接失败, fileId={}, objectName={}", file.getId(), objectName, e);
|
||||
}
|
||||
|
||||
if (Integer.valueOf(UPLOAD_STATUS_SUCCEEDED).equals(file.getOssUploadStatus())) {
|
||||
if (Integer.valueOf(UPLOAD_STATUS_SUCCEEDED).equals(file.getBackupUploadStatus())) {
|
||||
try {
|
||||
return aliyunOssService.getPresignedUrl(objectName);
|
||||
} catch (Exception e) {
|
||||
@@ -91,9 +85,7 @@ public class ObjectStorageUrlSupport {
|
||||
"No available object storage signed URL for fileId=" + file.getId(),
|
||||
e
|
||||
);
|
||||
if (minioFailure != null) {
|
||||
failure.addSuppressed(minioFailure);
|
||||
}
|
||||
failure.addSuppressed(primaryFailure);
|
||||
throw failure;
|
||||
}
|
||||
}
|
||||
@@ -101,9 +93,7 @@ public class ObjectStorageUrlSupport {
|
||||
IllegalStateException failure = new IllegalStateException(
|
||||
"No available object storage signed URL for fileId=" + file.getId()
|
||||
);
|
||||
if (minioFailure != null) {
|
||||
failure.addSuppressed(minioFailure);
|
||||
}
|
||||
failure.addSuppressed(primaryFailure);
|
||||
throw failure;
|
||||
}
|
||||
|
||||
@@ -115,7 +105,7 @@ public class ObjectStorageUrlSupport {
|
||||
if (!StringUtils.hasText(objectName)) {
|
||||
return fileUrl;
|
||||
}
|
||||
return minioService.getFileUrl(objectName);
|
||||
return primaryObjectStorageService.getFileUrl(objectName);
|
||||
}
|
||||
|
||||
public String extractObjectName(String fileUrl) {
|
||||
@@ -125,18 +115,18 @@ public class ObjectStorageUrlSupport {
|
||||
|
||||
String normalizedUrl = fileUrl.trim();
|
||||
if (!normalizedUrl.startsWith("http://") && !normalizedUrl.startsWith("https://")) {
|
||||
return trimBucketPrefix(stripQuery(normalizedUrl));
|
||||
return stripQuery(stripLeadingSlash(normalizedUrl));
|
||||
}
|
||||
|
||||
try {
|
||||
URI fileUri = URI.create(normalizedUrl);
|
||||
String path = fileUri.getPath();
|
||||
if (!StringUtils.hasText(path)) {
|
||||
URI domainUri = URI.create(normalizeDomain(qiniuKodoConfig.getDomain()));
|
||||
if (!sameAuthority(fileUri, domainUri)) {
|
||||
return "";
|
||||
}
|
||||
return extractObjectNameFromUri(fileUri);
|
||||
return stripQuery(stripLeadingSlash(fileUri.getPath()));
|
||||
} catch (Exception e) {
|
||||
log.warn("Parse object storage URL failed: {}", fileUrl, e);
|
||||
log.warn("解析对象存储链接失败, fileUrl={}", fileUrl, e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -145,7 +135,7 @@ public class ObjectStorageUrlSupport {
|
||||
if (StringUtils.hasText(file.getObjectName())) {
|
||||
return file.getObjectName();
|
||||
}
|
||||
String objectName = extractObjectName(file.getMinioUrl());
|
||||
String objectName = extractObjectName(file.getPrimaryUrl());
|
||||
if (StringUtils.hasText(objectName)) {
|
||||
return objectName;
|
||||
}
|
||||
@@ -154,28 +144,10 @@ public class ObjectStorageUrlSupport {
|
||||
|
||||
private boolean hasObjectStorageReference(ObjectStorageFileVO file) {
|
||||
return StringUtils.hasText(file.getObjectName())
|
||||
|| StringUtils.hasText(extractObjectName(file.getMinioUrl()))
|
||||
|| StringUtils.hasText(extractObjectName(file.getPrimaryUrl()))
|
||||
|| StringUtils.hasText(extractObjectName(file.getFileUrl()));
|
||||
}
|
||||
|
||||
private String signWithMinio(String objectName, int expiryTimeInMinutes) throws Exception {
|
||||
String signedUrl = minioService.getPresignedUrl(objectName, expiryTimeInMinutes);
|
||||
markMinioHealth(true);
|
||||
return signedUrl;
|
||||
}
|
||||
|
||||
private boolean shouldTryMinio() {
|
||||
if (minioHealthy) {
|
||||
return true;
|
||||
}
|
||||
return System.currentTimeMillis() - minioHealthCheckedAt >= MINIO_HEALTH_CACHE_MILLIS;
|
||||
}
|
||||
|
||||
private void markMinioHealth(boolean healthy) {
|
||||
minioHealthy = healthy;
|
||||
minioHealthCheckedAt = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private String firstText(String... values) {
|
||||
if (values == null) {
|
||||
return null;
|
||||
@@ -188,53 +160,15 @@ public class ObjectStorageUrlSupport {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String extractObjectNameFromPath(String path) {
|
||||
String bucketPrefix = "/" + minioConfig.getBucketName() + "/";
|
||||
if (path.startsWith(bucketPrefix)) {
|
||||
return path.substring(bucketPrefix.length());
|
||||
private String normalizeDomain(String domain) {
|
||||
String normalized = domain.trim();
|
||||
while (normalized.endsWith("/")) {
|
||||
normalized = normalized.substring(0, normalized.length() - 1);
|
||||
}
|
||||
|
||||
String endpointPath = "";
|
||||
try {
|
||||
endpointPath = URI.create(minioConfig.getEndpoint()).getPath();
|
||||
} catch (Exception e) {
|
||||
log.warn("Parse MinIO endpoint failed: {}", minioConfig.getEndpoint(), e);
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(endpointPath) && !"/".equals(endpointPath)) {
|
||||
String normalizedEndpointPath = endpointPath.endsWith("/")
|
||||
? endpointPath.substring(0, endpointPath.length() - 1)
|
||||
: endpointPath;
|
||||
String prefixedBucketPath = normalizedEndpointPath + bucketPrefix;
|
||||
if (path.startsWith(prefixedBucketPath)) {
|
||||
return path.substring(prefixedBucketPath.length());
|
||||
}
|
||||
}
|
||||
|
||||
int bucketIndex = path.indexOf(bucketPrefix);
|
||||
if (bucketIndex >= 0) {
|
||||
return path.substring(bucketIndex + bucketPrefix.length());
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private String extractObjectNameFromUri(URI fileUri) {
|
||||
String objectName = extractObjectNameFromPath(fileUri.getPath());
|
||||
if (StringUtils.hasText(objectName)) {
|
||||
return objectName;
|
||||
}
|
||||
|
||||
try {
|
||||
URI endpointUri = URI.create(minioConfig.getEndpoint());
|
||||
if (!sameAuthority(fileUri, endpointUri)) {
|
||||
return "";
|
||||
}
|
||||
return stripFirstPathSegment(fileUri.getPath());
|
||||
} catch (Exception e) {
|
||||
log.warn("Parse MinIO endpoint failed: {}", minioConfig.getEndpoint(), e);
|
||||
return "";
|
||||
if (!normalized.startsWith("http://") && !normalized.startsWith("https://")) {
|
||||
return "http://" + normalized;
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
private boolean sameAuthority(URI left, URI right) {
|
||||
@@ -252,24 +186,6 @@ public class ObjectStorageUrlSupport {
|
||||
return "https".equalsIgnoreCase(uri.getScheme()) ? 443 : 80;
|
||||
}
|
||||
|
||||
private String stripFirstPathSegment(String path) {
|
||||
String normalizedPath = stripLeadingSlash(path);
|
||||
int slashIndex = normalizedPath.indexOf('/');
|
||||
if (slashIndex < 0 || slashIndex == normalizedPath.length() - 1) {
|
||||
return "";
|
||||
}
|
||||
return normalizedPath.substring(slashIndex + 1);
|
||||
}
|
||||
|
||||
private String trimBucketPrefix(String rawValue) {
|
||||
String normalized = stripLeadingSlash(rawValue);
|
||||
String bucketPrefix = minioConfig.getBucketName() + "/";
|
||||
if (normalized.startsWith(bucketPrefix)) {
|
||||
return normalized.substring(bucketPrefix.length());
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
private String stripLeadingSlash(String rawValue) {
|
||||
String normalized = rawValue;
|
||||
while (normalized.startsWith("/")) {
|
||||
|
||||
+12
-8
@@ -31,25 +31,29 @@ public class ObjectStorageFileVO {
|
||||
|
||||
private String objectName;
|
||||
|
||||
private String minioUrl;
|
||||
private String primaryProvider;
|
||||
|
||||
private String ossUrl;
|
||||
private String primaryUrl;
|
||||
|
||||
private String backupProvider;
|
||||
|
||||
private String backupUrl;
|
||||
|
||||
private String contentType;
|
||||
|
||||
private Long fileSize;
|
||||
|
||||
private Integer minioUploadStatus;
|
||||
private Integer primaryUploadStatus;
|
||||
|
||||
private Integer ossUploadStatus;
|
||||
private Integer backupUploadStatus;
|
||||
|
||||
private Integer ossRetryCount;
|
||||
private Integer backupRetryCount;
|
||||
|
||||
private String ossLastError;
|
||||
private String backupLastError;
|
||||
|
||||
private LocalDateTime ossUploadedAt;
|
||||
private LocalDateTime backupUploadedAt;
|
||||
|
||||
private LocalDateTime ossLastRetryTime;
|
||||
private LocalDateTime backupLastRetryTime;
|
||||
|
||||
/**
|
||||
* 文件上传时间
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.xiaowang.yuminailcore.modules.product.vo;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -20,11 +22,13 @@ public class ProductVO {
|
||||
/**
|
||||
* 商品唯一主键ID(雪花id)
|
||||
*/
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 所属店铺ID,关联店铺表主键
|
||||
*/
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
|
||||
+55
-6
@@ -33,7 +33,7 @@ import com.xiaowang.yuminailcore.modules.user.vo.UserRelationVO;
|
||||
import com.xiaowang.yuminailcore.modules.user.vo.UserVO;
|
||||
import com.xiaowang.yuminailcore.modules.user.vo.InviteCodeVO;
|
||||
import com.xiaowang.yuminailcore.modules.integration.vo.WechatMiniLoginResultVO;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.MinioService;
|
||||
import com.xiaowang.yuminailcore.modules.file.service.PrimaryObjectStorageService;
|
||||
import com.xiaowang.yuminailcore.modules.user.service.UserAssetService;
|
||||
import com.xiaowang.yuminailcore.modules.user.service.UserService;
|
||||
import com.xiaowang.yuminailcore.modules.security.service.ShopRoleService;
|
||||
@@ -95,9 +95,9 @@ public class UserController {
|
||||
*/
|
||||
private final UserAssetService userAssetService;
|
||||
/**
|
||||
* Variable `minioService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
* Variable `primaryObjectStorageService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final MinioService minioService;
|
||||
private final PrimaryObjectStorageService primaryObjectStorageService;
|
||||
/**
|
||||
* Variable `chunkUploadService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
@@ -764,7 +764,7 @@ public class UserController {
|
||||
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
String objectName = "avatar/" + userId + "/" + snowflakeIdGenerator.nextIdString() + fileExtension;
|
||||
|
||||
String avatarUrl = minioService.uploadStream(inputStream, preparedUploadFile.getFileSize(), preparedUploadFile.getContentType(), objectName);
|
||||
String avatarUrl = primaryObjectStorageService.uploadStream(inputStream, preparedUploadFile.getFileSize(), preparedUploadFile.getContentType(), objectName);
|
||||
userService.updateUserAvatar(userId, avatarUrl);
|
||||
chunkUploadService.clearUserAvatarUpload(userId, requestDTO.getUploadId());
|
||||
return Result.success(objectStorageUrlSupport.toAccessibleUrl(avatarUrl));
|
||||
@@ -802,7 +802,7 @@ public class UserController {
|
||||
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
String objectName = "avatar/" + userId + "/" + snowflakeIdGenerator.nextIdString() + fileExtension;
|
||||
|
||||
String avatarUrl = minioService.uploadFile(file, objectName);
|
||||
String avatarUrl = primaryObjectStorageService.uploadFile(file, objectName);
|
||||
userService.updateUserAvatar(userId, avatarUrl);
|
||||
|
||||
return Result.success(objectStorageUrlSupport.toAccessibleUrl(avatarUrl));
|
||||
@@ -821,6 +821,55 @@ public class UserController {
|
||||
/**
|
||||
* 上传个人资料图片,不直接修改头像或资料字段。
|
||||
*/
|
||||
@PostMapping("/upload-profile-image/init")
|
||||
@OperationGuard(action = "user-profile-image-upload-init", ttlSeconds = 10, message = "上传处理中,请勿重复操作")
|
||||
public Result<ChunkUploadSessionVO> initProfileImageUpload(HttpServletRequest request, @Valid @RequestBody ChunkUploadInitRequestDTO requestDTO) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
return Result.success(chunkUploadService.initUserProfileImageUpload(userId, requestDTO));
|
||||
}
|
||||
|
||||
@PostMapping("/upload-profile-image/chunk")
|
||||
@OperationGuard(action = "user-profile-image-upload-chunk", strategy = OperationGuardStrategy.NOOP_IF_DUPLICATE, ttlSeconds = 20)
|
||||
public Result<Boolean> uploadProfileImageChunk(HttpServletRequest request,
|
||||
@RequestParam("uploadId") String uploadId,
|
||||
@RequestParam("chunkIndex") Integer chunkIndex,
|
||||
@RequestParam("totalChunks") Integer totalChunks,
|
||||
@RequestParam("chunk") MultipartFile chunkFile) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
chunkUploadService.uploadUserProfileImageChunk(userId, uploadId, chunkIndex, totalChunks, chunkFile);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/upload-profile-image/complete")
|
||||
@OperationGuard(action = "user-profile-image-upload-complete", ttlSeconds = 30, message = "上传处理中,请勿重复操作")
|
||||
public Result<String> completeProfileImageUpload(HttpServletRequest request, @Valid @RequestBody ChunkUploadCompleteRequestDTO requestDTO) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
try (ChunkUploadService.PreparedUploadFile preparedUploadFile =
|
||||
chunkUploadService.prepareUserProfileImageFile(userId, requestDTO.getUploadId());
|
||||
FileInputStream inputStream = new FileInputStream(preparedUploadFile.getFile())) {
|
||||
String originalFilename = preparedUploadFile.getFileName();
|
||||
String fileExtension = "";
|
||||
if (originalFilename != null && originalFilename.lastIndexOf(".") >= 0) {
|
||||
fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
}
|
||||
String objectName = "profile/" + userId + "/" + snowflakeIdGenerator.nextIdString() + fileExtension;
|
||||
String imageUrl = primaryObjectStorageService.uploadStream(inputStream, preparedUploadFile.getFileSize(), preparedUploadFile.getContentType(), objectName);
|
||||
chunkUploadService.clearUserProfileImageUpload(userId, requestDTO.getUploadId());
|
||||
return Result.success(objectStorageUrlSupport.toAccessibleUrl(imageUrl));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("资料图片上传失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/upload-profile-image/{uploadId}")
|
||||
@OperationGuard(action = "user-profile-image-upload-cancel", ttlSeconds = 30, message = "上传处理中,请勿重复操作")
|
||||
public Result<Boolean> cancelProfileImageUpload(HttpServletRequest request, @PathVariable String uploadId) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
chunkUploadService.clearUserProfileImageUpload(userId, uploadId);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/upload-profile-image")
|
||||
@OperationGuard(action = "user-profile-image-upload", ttlSeconds = 30, message = "上传处理中,请勿重复操作")
|
||||
public Result<String> uploadProfileImage(HttpServletRequest request, @RequestParam("file") MultipartFile file) {
|
||||
@@ -835,7 +884,7 @@ public class UserController {
|
||||
fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
}
|
||||
String objectName = "profile/" + userId + "/" + snowflakeIdGenerator.nextIdString() + fileExtension;
|
||||
String imageUrl = minioService.uploadFile(file, objectName);
|
||||
String imageUrl = primaryObjectStorageService.uploadFile(file, objectName);
|
||||
return Result.success(objectStorageUrlSupport.toAccessibleUrl(imageUrl));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ public class UploadSecurityValidator {
|
||||
* Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
public void validateMetadata(String filename, String contentType, Long fileSize) {
|
||||
if (fileSize == null || fileSize <= 0 || fileSize > properties.getMaxSize()) {
|
||||
if (fileSize == null || fileSize <= 0 || fileSize > properties.getMaxTotalSize()) {
|
||||
throw new RuntimeException("上传文件大小不合法");
|
||||
}
|
||||
String extension = resolveExtension(filename);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/nailart?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
url: jdbc:mysql://localhost:3306/FingertipDesigner?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 5MB
|
||||
@@ -25,10 +25,10 @@ mybatis:
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
|
||||
yuminail:
|
||||
fingertip-designer:
|
||||
security:
|
||||
jwt:
|
||||
issuer: yuminail
|
||||
issuer: fingertip-designer
|
||||
access-token-expiration-seconds: 7200
|
||||
refresh-token-expiration-seconds: 604800
|
||||
clock-skew-seconds: 30
|
||||
@@ -85,3 +85,33 @@ yuminail:
|
||||
connection-request-timeout-ms: 1000
|
||||
max-total-connections: 200
|
||||
max-connections-per-route: 50
|
||||
|
||||
object-storage:
|
||||
primary-provider: QINIU_KODO
|
||||
backup-provider: ALIYUN_OSS
|
||||
signed-url-expire-minutes: 60
|
||||
backup-queue-name: fingertip-designer.file.object-storage.backup.queue
|
||||
backup-exchange-name: fingertip-designer.file.object-storage.backup.exchange
|
||||
backup-routing-key: fingertip-designer.file.object-storage.backup
|
||||
backup-retry-batch-limit: 500
|
||||
backup-retry-cron: "0 0 2 * * ?"
|
||||
|
||||
qiniu:
|
||||
kodo:
|
||||
access-key: ${QINIU_KODO_ACCESS_KEY:}
|
||||
secret-key: ${QINIU_KODO_SECRET_KEY:}
|
||||
bucket-name: ${QINIU_KODO_BUCKET_NAME:}
|
||||
domain: ${QINIU_KODO_DOMAIN:}
|
||||
zone: ${QINIU_KODO_ZONE:z2}
|
||||
private-bucket: ${QINIU_KODO_PRIVATE_BUCKET:true}
|
||||
signed-url-expire-minutes: ${QINIU_KODO_SIGNED_URL_EXPIRE_MINUTES:60}
|
||||
|
||||
aliyun:
|
||||
oss:
|
||||
enabled: ${ALIYUN_OSS_ENABLED:false}
|
||||
endpoint: ${ALIYUN_OSS_ENDPOINT:}
|
||||
region: ${ALIYUN_OSS_REGION:}
|
||||
bucket-name: ${ALIYUN_OSS_BUCKET_NAME:}
|
||||
access-key-id: ${ALIYUN_OSS_ACCESS_KEY_ID:}
|
||||
access-key-secret: ${ALIYUN_OSS_ACCESS_KEY_SECRET:}
|
||||
signed-url-expire-minutes: ${ALIYUN_OSS_SIGNED_URL_EXPIRE_MINUTES:60}
|
||||
|
||||
@@ -1,57 +1,51 @@
|
||||
spring:
|
||||
application:
|
||||
name: yumi-nail-core
|
||||
name: fingertip-designer-core
|
||||
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# Nacos集群地址
|
||||
server-addr: home-nacos01:8848,home-nacos02:8848,home-nacos03:8848
|
||||
# 命名空间ID
|
||||
namespace: YumiNail-Dev
|
||||
# 分组名称
|
||||
group: DEFAULT_GROUP
|
||||
# 服务名称
|
||||
# Nacos 集群地址,默认指向开发环境,生产环境通过环境变量覆盖。
|
||||
server-addr: ${NACOS_SERVER_ADDR:192.168.5.103:8848}
|
||||
# Nacos 命名空间,默认指向开发环境。
|
||||
namespace: ${NACOS_NAMESPACE:YumiNail-Dev}
|
||||
# 服务注册分组。
|
||||
group: ${NACOS_GROUP:DEFAULT_GROUP}
|
||||
# 注册到 Nacos 的服务名。
|
||||
service: ${spring.application.name}
|
||||
# 是否启用服务发现
|
||||
# 是否启用服务发现。
|
||||
enabled: true
|
||||
# 是否启用服务注册
|
||||
# 是否将当前服务注册到 Nacos。
|
||||
register-enabled: true
|
||||
# Nacos认证用户名
|
||||
username: xiaowang
|
||||
# Nacos认证密码
|
||||
password: 122503wcy....
|
||||
# Nacos 认证用户名。
|
||||
username: ${NACOS_USERNAME:xiaowang}
|
||||
# Nacos 认证密码。
|
||||
password: ${NACOS_PASSWORD:122503wcy....}
|
||||
config:
|
||||
# Nacos配置中心集群地址
|
||||
server-addr: home-nacos01:8848,home-nacos02:8848,home-nacos03:8848
|
||||
# 配置中心命名空间
|
||||
namespace: YumiNail-Dev
|
||||
# 配置分组
|
||||
group: DEFAULT_GROUP
|
||||
# 配置文件名称
|
||||
name: yuminail-core
|
||||
# 配置文件扩展名
|
||||
# Nacos 配置中心地址,与服务发现使用同一组集群节点,默认指向开发环境。
|
||||
server-addr: ${NACOS_SERVER_ADDR:192.168.5.103:8848}
|
||||
# Nacos 配置中心命名空间,默认指向开发环境。
|
||||
namespace: ${NACOS_NAMESPACE:YumiNail-Dev}
|
||||
# 配置分组。
|
||||
group: ${NACOS_GROUP:DEFAULT_GROUP}
|
||||
# Core 服务独有配置文件。
|
||||
name: core
|
||||
# 所有 Nacos 配置均使用 YAML。
|
||||
file-extension: yaml
|
||||
# 是否启用配置中心
|
||||
# 是否启用配置中心。
|
||||
enabled: true
|
||||
# Nacos认证用户名
|
||||
username: xiaowang
|
||||
# Nacos认证密码
|
||||
password: 122503wcy....
|
||||
# 共享配置文件列表
|
||||
# Nacos 认证用户名。
|
||||
username: ${NACOS_USERNAME:xiaowang}
|
||||
# Nacos 认证密码。
|
||||
password: ${NACOS_PASSWORD:122503wcy....}
|
||||
# Core 与 Gateway 共享的公共配置文件。
|
||||
shared-configs:
|
||||
- data-id: rabbit-mq.yaml
|
||||
group: DEFAULT_GROUP
|
||||
- data-id: infra.yaml
|
||||
group: ${NACOS_GROUP:DEFAULT_GROUP}
|
||||
refresh: true
|
||||
- data-id: datasource.yaml
|
||||
group: DEFAULT_GROUP
|
||||
refresh: true
|
||||
- data-id: mybatis-plus.yaml
|
||||
group: DEFAULT_GROUP
|
||||
- data-id: secret.yaml
|
||||
group: ${NACOS_GROUP:DEFAULT_GROUP}
|
||||
refresh: true
|
||||
- data-id: logging.yaml
|
||||
group: DEFAULT_GROUP
|
||||
refresh: true
|
||||
- data-id: redis.yaml
|
||||
group: DEFAULT_GROUP
|
||||
group: ${NACOS_GROUP:DEFAULT_GROUP}
|
||||
refresh: true
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user