修复Salon对象存储头像展示
This commit is contained in:
+1
-1
@@ -700,7 +700,7 @@ public class NailArtistInfoServiceImpl extends ServiceImpl<NailArtistInfoMapper,
|
||||
return null;
|
||||
}
|
||||
String accessibleUrl = objectStorageUrlSupport.toAccessibleUrl(avatar);
|
||||
return StringUtils.hasText(accessibleUrl) ? accessibleUrl : avatar;
|
||||
return StringUtils.hasText(accessibleUrl) ? accessibleUrl : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+65
-6
@@ -1,6 +1,8 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.file.support;
|
||||
|
||||
import com.xiaowang.jayucloud.salon.core.config.ObjectStorageProperties;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.config.AliyunOssConfig;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.config.MinioStorageConfig;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.config.QiniuKodoConfig;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.service.AliyunOssService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.service.ObjectStorageOrchestrationService;
|
||||
@@ -21,6 +23,8 @@ public class ObjectStorageUrlSupport {
|
||||
private static final int UPLOAD_STATUS_SUCCEEDED = 1;
|
||||
|
||||
private final PrimaryObjectStorageService primaryObjectStorageService;
|
||||
private final MinioStorageConfig minioStorageConfig;
|
||||
private final AliyunOssConfig aliyunOssConfig;
|
||||
private final QiniuKodoConfig qiniuKodoConfig;
|
||||
private final AliyunOssService aliyunOssService;
|
||||
private final ObjectStorageProperties objectStorageProperties;
|
||||
@@ -32,7 +36,7 @@ public class ObjectStorageUrlSupport {
|
||||
}
|
||||
String objectName = extractObjectName(fileUrl);
|
||||
if (!StringUtils.hasText(objectName)) {
|
||||
return fileUrl;
|
||||
return isKnownStorageUrl(fileUrl) ? null : fileUrl;
|
||||
}
|
||||
try {
|
||||
return objectStorageOrchestrationService.getPresignedUrl(
|
||||
@@ -116,6 +120,9 @@ public class ObjectStorageUrlSupport {
|
||||
}
|
||||
|
||||
String normalizedUrl = fileUrl.trim();
|
||||
if (normalizedUrl.startsWith("oss://")) {
|
||||
return extractBucketObjectName(normalizedUrl.substring("oss://".length()), aliyunOssConfig.getBucketName());
|
||||
}
|
||||
if (!normalizedUrl.startsWith("http://") && !normalizedUrl.startsWith("https://")) {
|
||||
return stripQuery(stripLeadingSlash(normalizedUrl));
|
||||
}
|
||||
@@ -123,10 +130,17 @@ public class ObjectStorageUrlSupport {
|
||||
try {
|
||||
URI fileUri = URI.create(normalizedUrl);
|
||||
URI domainUri = URI.create(normalizeDomain(qiniuKodoConfig.getDomain()));
|
||||
if (!sameAuthority(fileUri, domainUri)) {
|
||||
return "";
|
||||
if (sameAuthority(fileUri, domainUri)) {
|
||||
return stripQuery(stripLeadingSlash(fileUri.getPath()));
|
||||
}
|
||||
return stripQuery(stripLeadingSlash(fileUri.getPath()));
|
||||
if (sameConfiguredAuthority(fileUri, minioStorageConfig.getEndpoint())
|
||||
|| sameConfiguredAuthority(fileUri, minioStorageConfig.getPublicEndpoint())) {
|
||||
return extractBucketObjectName(fileUri.getPath(), minioStorageConfig.getBucketName());
|
||||
}
|
||||
if (sameConfiguredAuthority(fileUri, aliyunOssConfig.getEndpoint())) {
|
||||
return extractBucketObjectName(fileUri.getPath(), aliyunOssConfig.getBucketName());
|
||||
}
|
||||
return "";
|
||||
} catch (Exception e) {
|
||||
log.warn("解析对象存储链接失败, fileUrl={}", fileUrl, e);
|
||||
return "";
|
||||
@@ -163,6 +177,9 @@ public class ObjectStorageUrlSupport {
|
||||
}
|
||||
|
||||
private String normalizeDomain(String domain) {
|
||||
if (!StringUtils.hasText(domain)) {
|
||||
return "";
|
||||
}
|
||||
String normalized = domain.trim();
|
||||
while (normalized.endsWith("/")) {
|
||||
normalized = normalized.substring(0, normalized.length() - 1);
|
||||
@@ -174,13 +191,55 @@ public class ObjectStorageUrlSupport {
|
||||
}
|
||||
|
||||
private boolean sameAuthority(URI left, URI right) {
|
||||
return left.getScheme() != null
|
||||
&& left.getScheme().equalsIgnoreCase(right.getScheme())
|
||||
return right != null
|
||||
&& left.getHost() != null
|
||||
&& right.getHost() != null
|
||||
&& left.getHost().equalsIgnoreCase(right.getHost())
|
||||
&& normalizedPort(left) == normalizedPort(right);
|
||||
}
|
||||
|
||||
private boolean sameConfiguredAuthority(URI fileUri, String endpoint) {
|
||||
if (!StringUtils.hasText(endpoint)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return sameAuthority(fileUri, URI.create(normalizeDomain(endpoint)));
|
||||
} catch (Exception ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private String extractBucketObjectName(String rawPath, String bucketName) {
|
||||
String path = stripQuery(stripLeadingSlash(rawPath));
|
||||
if (!StringUtils.hasText(path) || !StringUtils.hasText(bucketName)) {
|
||||
return "";
|
||||
}
|
||||
String bucketPrefix = bucketName.trim() + "/";
|
||||
return path.startsWith(bucketPrefix) ? path.substring(bucketPrefix.length()) : path;
|
||||
}
|
||||
|
||||
private boolean isKnownStorageUrl(String fileUrl) {
|
||||
if (!StringUtils.hasText(fileUrl)) {
|
||||
return false;
|
||||
}
|
||||
String normalized = fileUrl.trim();
|
||||
if (normalized.startsWith("oss://")) {
|
||||
return true;
|
||||
}
|
||||
if (!normalized.startsWith("http://") && !normalized.startsWith("https://")) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
URI uri = URI.create(normalized);
|
||||
return sameConfiguredAuthority(uri, qiniuKodoConfig.getDomain())
|
||||
|| sameConfiguredAuthority(uri, minioStorageConfig.getEndpoint())
|
||||
|| sameConfiguredAuthority(uri, minioStorageConfig.getPublicEndpoint())
|
||||
|| sameConfiguredAuthority(uri, aliyunOssConfig.getEndpoint());
|
||||
} catch (Exception ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private int normalizedPort(URI uri) {
|
||||
if (uri.getPort() >= 0) {
|
||||
return uri.getPort();
|
||||
|
||||
+3
-1
@@ -30,6 +30,7 @@ import com.xiaowang.jayucloud.salon.core.modules.order.service.OrderService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.planning.service.PlanningService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.security.support.AdminScopeHelper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.support.OrderStatus;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.support.ObjectStorageUrlSupport;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.planning.support.PlanningCalendarSupport;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.planning.support.PlanningTodayOverviewSupport;
|
||||
import com.xiaowang.jayucloud.salon.core.support.id.TimeOrderedSnowflakeIdGenerator;
|
||||
@@ -96,6 +97,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
private final AppointmentCapacityService appointmentCapacityService;
|
||||
private final OrderService orderService;
|
||||
private final TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator;
|
||||
private final ObjectStorageUrlSupport objectStorageUrlSupport;
|
||||
|
||||
@Override
|
||||
public PlanningCalendarVO getCalendar(UserDO currentUser, LocalDate startDate, LocalDate endDate, Long artistId) {
|
||||
@@ -425,7 +427,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
vo.setName(firstNonBlank(user.getNickname(), user.getAccount(), "美甲师" + (i + 1)));
|
||||
vo.setShortName(PlanningCalendarSupport.shortName(vo.getName()));
|
||||
vo.setPhone(firstNonBlank(user.getContactPhone(), user.getPhone(), ""));
|
||||
vo.setAvatar(user.getAvatar());
|
||||
vo.setAvatar(objectStorageUrlSupport.toAccessibleUrl(user.getAvatar()));
|
||||
vo.setColor(info != null && StringUtils.hasText(info.getColor())
|
||||
? info.getColor() : colorForArtist(user.getId(), i));
|
||||
vo.setStatus(info == null || info.getStatus() == null ? user.getStatus() : info.getStatus());
|
||||
|
||||
+9
-3
@@ -31,6 +31,7 @@ import com.xiaowang.jayucloud.salon.core.modules.user.mapper.UserMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.service.UserService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.service.SystemParameterConfigService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.service.ObjectStorageFileService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.support.ObjectStorageUrlSupport;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.vo.ObjectStorageFileVO;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -64,6 +65,7 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
|
||||
private final TransactionTemplate transactionTemplate;
|
||||
private final WechatMiniBindingMapper wechatMiniBindingMapper;
|
||||
private final ObjectStorageFileService objectStorageFileService;
|
||||
private final ObjectStorageUrlSupport objectStorageUrlSupport;
|
||||
|
||||
public WorkbenchRegistrationServiceImpl(
|
||||
WorkbenchRegistrationApplicationMapper applicationMapper,
|
||||
@@ -79,7 +81,8 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
|
||||
ShopBusinessExpiryService shopBusinessExpiryService,
|
||||
PlatformTransactionManager transactionManager,
|
||||
WechatMiniBindingMapper wechatMiniBindingMapper,
|
||||
ObjectStorageFileService objectStorageFileService
|
||||
ObjectStorageFileService objectStorageFileService,
|
||||
ObjectStorageUrlSupport objectStorageUrlSupport
|
||||
) {
|
||||
this.applicationMapper = applicationMapper;
|
||||
this.userMapper = userMapper;
|
||||
@@ -95,6 +98,7 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
|
||||
this.transactionTemplate = new TransactionTemplate(transactionManager);
|
||||
this.wechatMiniBindingMapper = wechatMiniBindingMapper;
|
||||
this.objectStorageFileService = objectStorageFileService;
|
||||
this.objectStorageUrlSupport = objectStorageUrlSupport;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -324,7 +328,8 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
|
||||
if (request != null && Boolean.TRUE.equals(request.getUseApplicantAvatar()) && application.getApplicantAvatarFileId() != null) {
|
||||
requireApplicantProfileApproved(application);
|
||||
ObjectStorageFileVO file = contentModerationFile(application.getApplicantAvatarFileId());
|
||||
target.setAvatar(file.getFileUrl());
|
||||
target.setAvatar(objectStorageUrlSupport.toStoredUrl(StringUtils.hasText(file.getObjectName())
|
||||
? file.getObjectName() : file.getFileUrl()));
|
||||
}
|
||||
target.setStatus(1);
|
||||
userMapper.updateById(target);
|
||||
@@ -367,7 +372,8 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
|
||||
return users.stream()
|
||||
.filter(user -> !hasActiveWechatBinding(user.getId()))
|
||||
.filter(user -> !hasPendingAssociation(user.getId(), applicationId))
|
||||
.map(user -> new WorkbenchRegistrationArtistVO(user.getId(), user.getNickname(), user.getAvatar()))
|
||||
.map(user -> new WorkbenchRegistrationArtistVO(user.getId(), user.getNickname(),
|
||||
objectStorageUrlSupport.toAccessibleUrl(user.getAvatar())))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.file.support;
|
||||
|
||||
import com.xiaowang.jayucloud.salon.core.config.ObjectStorageProperties;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.config.AliyunOssConfig;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.config.MinioStorageConfig;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.config.QiniuKodoConfig;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.service.AliyunOssService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.service.ObjectStorageOrchestrationService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.service.PrimaryObjectStorageService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class ObjectStorageUrlSupportTest {
|
||||
|
||||
private ObjectStorageUrlSupport support;
|
||||
private ObjectStorageOrchestrationService orchestrationService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MinioStorageConfig minio = new MinioStorageConfig();
|
||||
minio.setEndpoint("http://192.168.10.14:9000");
|
||||
minio.setPublicEndpoint("https://sit.minio.yunail.art");
|
||||
minio.setBucketName("jayucloud-salon-sit");
|
||||
AliyunOssConfig aliyun = new AliyunOssConfig();
|
||||
aliyun.setEndpoint("https://oss-cn-hangzhou.aliyuncs.com");
|
||||
aliyun.setBucketName("salon");
|
||||
QiniuKodoConfig qiniu = new QiniuKodoConfig();
|
||||
qiniu.setDomain("https://sit.qiniu.yunail.art");
|
||||
ObjectStorageProperties properties = new ObjectStorageProperties();
|
||||
properties.setSignedUrlExpireMinutes(60);
|
||||
orchestrationService = mock(ObjectStorageOrchestrationService.class);
|
||||
support = new ObjectStorageUrlSupport(mock(PrimaryObjectStorageService.class), minio, aliyun,
|
||||
qiniu, mock(AliyunOssService.class), properties, orchestrationService);
|
||||
}
|
||||
|
||||
@Test
|
||||
void extractsObjectNameFromMinioInternalAndPublicUrls() {
|
||||
assertEquals("avatar/7/photo.jpg", support.extractObjectName(
|
||||
"http://192.168.10.14:9000/jayucloud-salon-sit/avatar/7/photo.jpg"));
|
||||
assertEquals("avatar/7/photo.jpg", support.extractObjectName(
|
||||
"https://sit.minio.yunail.art/jayucloud-salon-sit/avatar/7/photo.jpg?X-Amz-Signature=test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void keepsQiniuAndOssReferencesSupported() {
|
||||
assertEquals("avatar/7/photo.jpg", support.extractObjectName("https://sit.qiniu.yunail.art/avatar/7/photo.jpg"));
|
||||
assertEquals("avatar/7/photo.jpg", support.extractObjectName("oss://salon/avatar/7/photo.jpg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotReturnKnownPrivateUrlWhenSigningFails() {
|
||||
when(orchestrationService.getPresignedUrl("avatar/7/photo.jpg", 60))
|
||||
.thenThrow(new IllegalStateException("storage unavailable"));
|
||||
assertNull(support.toAccessibleUrl("https://sit.minio.yunail.art/jayucloud-salon-sit/avatar/7/photo.jpg"));
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -15,6 +15,7 @@ import com.xiaowang.jayucloud.salon.core.modules.planning.dto.PlanningAppointmen
|
||||
import com.xiaowang.jayucloud.salon.core.modules.planning.dto.PlanningBackfillOrderCreateDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.planning.mapper.AppointmentReservationMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.planning.service.AppointmentCapacityService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.support.ObjectStorageUrlSupport;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.product.mapper.ProductMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.product.entity.ProductDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.security.support.AdminScopeHelper;
|
||||
@@ -61,6 +62,7 @@ class PlanningServiceImplTest {
|
||||
@Mock private AppointmentCapacityService appointmentCapacityService;
|
||||
@Mock private OrderService orderService;
|
||||
@Mock private TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator;
|
||||
@Mock private ObjectStorageUrlSupport objectStorageUrlSupport;
|
||||
|
||||
private PlanningServiceImpl service;
|
||||
|
||||
@@ -68,7 +70,8 @@ class PlanningServiceImplTest {
|
||||
void setUp() {
|
||||
service = new PlanningServiceImpl(adminScopeHelper, userMapper, userService, nailArtistInfoMapper, artistScheduleMapper,
|
||||
artistScheduleExceptionMapper, appointmentReservationMapper, orderMapper, orderItemMapper,
|
||||
productMapper, shopMapper, shopBusinessExpiryService, appointmentCapacityService, orderService, snowflakeIdGenerator);
|
||||
productMapper, shopMapper, shopBusinessExpiryService, appointmentCapacityService, orderService, snowflakeIdGenerator,
|
||||
objectStorageUrlSupport);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+3
-1
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.integration.service.WechatMiniAuthService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.integration.mapper.WechatMiniBindingMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.service.ObjectStorageFileService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.support.ObjectStorageUrlSupport;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.privacy.moderation.LocalMockContentModerationProvider;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.privacy.moderation.ModerationOutcome;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.privacy.entity.ContentModerationRecordDO;
|
||||
@@ -57,6 +58,7 @@ class WorkbenchRegistrationServiceImplTest {
|
||||
@Mock private PlatformTransactionManager transactionManager;
|
||||
@Mock private WechatMiniBindingMapper wechatMiniBindingMapper;
|
||||
@Mock private ObjectStorageFileService objectStorageFileService;
|
||||
@Mock private ObjectStorageUrlSupport objectStorageUrlSupport;
|
||||
|
||||
private WorkbenchRegistrationServiceImpl service;
|
||||
|
||||
@@ -65,7 +67,7 @@ class WorkbenchRegistrationServiceImplTest {
|
||||
service = new WorkbenchRegistrationServiceImpl(applicationMapper, userMapper, shopMapper, userService,
|
||||
userShopBindingSupport, userShopBindingMapper, wechatMiniAuthService, systemParameterConfigService,
|
||||
contentModerationService, contentModerationRecordMapper, shopBusinessExpiryService, transactionManager,
|
||||
wechatMiniBindingMapper, objectStorageFileService);
|
||||
wechatMiniBindingMapper, objectStorageFileService, objectStorageUrlSupport);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user