修复小程序后台路由误判
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.file.controller.front;
|
||||
|
||||
import com.xiaowang.jayucloud.salon.core.annotation.OperationGuard;
|
||||
import com.xiaowang.jayucloud.salon.core.common.Result;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.service.ObjectStorageDirectUploadService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.vo.ObjectStorageFileVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/object-storage-file")
|
||||
@RequiredArgsConstructor
|
||||
public class MiniProgramObjectStorageUploadController {
|
||||
|
||||
private final ObjectStorageDirectUploadService objectStorageDirectUploadService;
|
||||
|
||||
@PostMapping("/upload")
|
||||
@OperationGuard(action = "mini-program-upload-direct", ttlSeconds = 30, message = "上传处理中,请勿重复操作")
|
||||
public Result<ObjectStorageFileVO> uploadFile(HttpServletRequest request,
|
||||
@RequestParam("file") MultipartFile file) {
|
||||
Object userTypeValue = request.getAttribute("userType");
|
||||
if (!(userTypeValue instanceof Integer)
|
||||
|| (!Integer.valueOf(2).equals(userTypeValue) && !Integer.valueOf(3).equals(userTypeValue))) {
|
||||
return Result.error(403, "当前账号无权上传门店业务文件");
|
||||
}
|
||||
try {
|
||||
return Result.success(objectStorageDirectUploadService.upload(file));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("文件上传失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-29
@@ -10,6 +10,7 @@ import com.xiaowang.jayucloud.salon.core.modules.file.dto.ObjectStorageUploadOut
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.service.ChunkUploadService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.service.ObjectStorageFileService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.service.ObjectStorageOrchestrationService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.service.ObjectStorageDirectUploadService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.support.ObjectStorageUrlSupport;
|
||||
import com.xiaowang.jayucloud.salon.core.support.id.TimeOrderedSnowflakeIdGenerator;
|
||||
import com.xiaowang.jayucloud.salon.core.support.security.OperationGuardStrategy;
|
||||
@@ -46,6 +47,7 @@ public class ObjectStorageFileController {
|
||||
* Variable `objectStorageFileService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final ObjectStorageFileService objectStorageFileService;
|
||||
private final ObjectStorageDirectUploadService objectStorageDirectUploadService;
|
||||
/**
|
||||
* Variable `objectStorageOrchestrationService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
@@ -156,35 +158,7 @@ public class ObjectStorageFileController {
|
||||
@OperationGuard(action = "admin-upload-direct", ttlSeconds = 30, message = "上传处理中,请勿重复操作")
|
||||
public Result<ObjectStorageFileVO> uploadFile(@RequestParam("file") MultipartFile file) {
|
||||
try {
|
||||
uploadSecurityValidator.validate(file);
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
String objectName = snowflakeIdGenerator.nextIdString() + fileExtension;
|
||||
|
||||
ObjectStorageUploadOutcome uploadOutcome = objectStorageOrchestrationService.uploadPrimary(
|
||||
file.getInputStream(),
|
||||
file.getSize(),
|
||||
file.getContentType(),
|
||||
objectName
|
||||
);
|
||||
|
||||
ObjectStorageFileDTO dto = new ObjectStorageFileDTO();
|
||||
dto.setFileName(originalFilename);
|
||||
dto.setFileUrl(uploadOutcome.getPrimaryUrl());
|
||||
dto.setObjectName(objectName);
|
||||
dto.setPrimaryProvider(uploadOutcome.getPrimaryProvider());
|
||||
dto.setPrimaryUrl(uploadOutcome.getPrimaryUrl());
|
||||
dto.setBackupProvider(String.join(",", objectStorageProperties.getReplicaRequiredProviders()));
|
||||
dto.setContentType(file.getContentType());
|
||||
dto.setFileSize(file.getSize());
|
||||
dto.setPrimaryUploadStatus(1);
|
||||
dto.setBackupUploadStatus(0);
|
||||
dto.setBackupRetryCount(0);
|
||||
dto.setUploadAttempts(uploadOutcome.getAttempts());
|
||||
dto.setStatus(1);
|
||||
|
||||
Long fileId = objectStorageFileService.createObjectStorageFile(dto);
|
||||
return Result.success(objectStorageFileService.getObjectStorageFileById(fileId));
|
||||
return Result.success(objectStorageDirectUploadService.upload(file));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("文件上传失败: " + e.getMessage());
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.file.service;
|
||||
|
||||
import com.xiaowang.jayucloud.salon.core.config.ObjectStorageProperties;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.dto.ObjectStorageFileDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.dto.ObjectStorageUploadOutcome;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.vo.ObjectStorageFileVO;
|
||||
import com.xiaowang.jayucloud.salon.core.support.id.TimeOrderedSnowflakeIdGenerator;
|
||||
import com.xiaowang.jayucloud.salon.core.support.security.UploadSecurityValidator;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ObjectStorageDirectUploadService {
|
||||
|
||||
private final ObjectStorageFileService objectStorageFileService;
|
||||
private final ObjectStorageOrchestrationService objectStorageOrchestrationService;
|
||||
private final TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator;
|
||||
private final UploadSecurityValidator uploadSecurityValidator;
|
||||
private final ObjectStorageProperties objectStorageProperties;
|
||||
|
||||
public ObjectStorageFileVO upload(MultipartFile file) throws Exception {
|
||||
uploadSecurityValidator.validate(file);
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
String objectName = snowflakeIdGenerator.nextIdString() + fileExtension;
|
||||
|
||||
ObjectStorageUploadOutcome uploadOutcome = objectStorageOrchestrationService.uploadPrimary(
|
||||
file.getInputStream(),
|
||||
file.getSize(),
|
||||
file.getContentType(),
|
||||
objectName
|
||||
);
|
||||
|
||||
ObjectStorageFileDTO dto = new ObjectStorageFileDTO();
|
||||
dto.setFileName(originalFilename);
|
||||
dto.setFileUrl(uploadOutcome.getPrimaryUrl());
|
||||
dto.setObjectName(objectName);
|
||||
dto.setPrimaryProvider(uploadOutcome.getPrimaryProvider());
|
||||
dto.setPrimaryUrl(uploadOutcome.getPrimaryUrl());
|
||||
dto.setBackupProvider(String.join(",", objectStorageProperties.getReplicaRequiredProviders()));
|
||||
dto.setContentType(file.getContentType());
|
||||
dto.setFileSize(file.getSize());
|
||||
dto.setPrimaryUploadStatus(1);
|
||||
dto.setBackupUploadStatus(0);
|
||||
dto.setBackupRetryCount(0);
|
||||
dto.setUploadAttempts(uploadOutcome.getAttempts());
|
||||
dto.setStatus(1);
|
||||
|
||||
Long fileId = objectStorageFileService.createObjectStorageFile(dto);
|
||||
return objectStorageFileService.getObjectStorageFileById(fileId);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -50,7 +50,7 @@ import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/manager")
|
||||
@RequestMapping({"/admin/manager", "/manager"})
|
||||
@RequiredArgsConstructor
|
||||
public class AdminManagerController {
|
||||
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/user/workbench/registration")
|
||||
@RequestMapping({"/admin/user/workbench/registration", "/user/workbench/registration"})
|
||||
public class AdminWorkbenchRegistrationController {
|
||||
private final WorkbenchRegistrationService registrationService;
|
||||
private final UserMapper userMapper;
|
||||
|
||||
Reference in New Issue
Block a user