修复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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user