菜单修改优化
This commit is contained in:
+99
@@ -27,6 +27,7 @@ public class OssStorageService {
|
||||
|
||||
private static final String IMAGE_VIDEO_MODULE = "IMAGE_VIDEO";
|
||||
private static final String DIGITAL_HUMAN_PREFIX = "digital-human/versions/";
|
||||
private static final String LEGACY_MINIO_ENDPOINT = "http://47.110.241.161:9000";
|
||||
|
||||
private final OssProperties ossProperties;
|
||||
private final MinioClient minioClient;
|
||||
@@ -164,6 +165,52 @@ public class OssStorageService {
|
||||
return location == null ? null : getPublicUrl(location.objectKey(), location.bucket());
|
||||
}
|
||||
|
||||
/** Rewrites managed MinIO URLs to the current public endpoint without touching external URLs. */
|
||||
public String normalizeManagedPublicUrl(String value) {
|
||||
if (value == null || value.isBlank()) {
|
||||
return value;
|
||||
}
|
||||
|
||||
URI source;
|
||||
try {
|
||||
source = new URI(value.trim());
|
||||
} catch (Exception ignored) {
|
||||
return value;
|
||||
}
|
||||
if (!isHttpUrl(source) || source.getHost() == null || source.getUserInfo() != null) {
|
||||
return value;
|
||||
}
|
||||
|
||||
String objectPath;
|
||||
try {
|
||||
objectPath = trimLeadingSlash(decodePath(source.getRawPath()));
|
||||
} catch (Exception ignored) {
|
||||
return value;
|
||||
}
|
||||
if (objectPath.isBlank() || hasDotPathSegment(objectPath)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
List<URI> endpoints = managedEndpoints();
|
||||
for (URI endpoint : endpoints) {
|
||||
for (String bucket : configuredBuckets()) {
|
||||
if (matchesVirtualHostEndpoint(source, endpoint, bucket)) {
|
||||
return getPublicUrl(objectPath, bucket);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (endpoints.stream().noneMatch(endpoint -> matchesEndpoint(source, endpoint))) {
|
||||
return value;
|
||||
}
|
||||
|
||||
String bucket = bucketPrefix(objectPath);
|
||||
if (bucket == null) {
|
||||
return value;
|
||||
}
|
||||
String objectKey = trimLeadingSlash(objectPath.substring(bucket.length()));
|
||||
return objectKey.isBlank() ? value : getPublicUrl(objectKey, bucket);
|
||||
}
|
||||
|
||||
public String resolveObjectKey(String value) {
|
||||
StorageLocation location = resolveStorageLocation(value);
|
||||
return location == null ? value : location.objectKey();
|
||||
@@ -271,6 +318,58 @@ public class OssStorageService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
private List<URI> managedEndpoints() {
|
||||
return Stream.of(ossProperties.getEndpoint(), ossProperties.getPublicEndpoint(), LEGACY_MINIO_ENDPOINT)
|
||||
.filter(Objects::nonNull)
|
||||
.map(String::trim)
|
||||
.filter(endpoint -> !endpoint.isBlank())
|
||||
.map(this::parseEndpoint)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.toList();
|
||||
}
|
||||
|
||||
private URI parseEndpoint(String value) {
|
||||
try {
|
||||
URI endpoint = new URI(withScheme(value));
|
||||
return endpoint.getHost() == null ? null : endpoint;
|
||||
} catch (Exception ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean matchesEndpoint(URI source, URI endpoint) {
|
||||
return sameSchemeAndPort(source, endpoint)
|
||||
&& source.getHost().equalsIgnoreCase(endpoint.getHost());
|
||||
}
|
||||
|
||||
private boolean matchesVirtualHostEndpoint(URI source, URI endpoint, String bucket) {
|
||||
String expectedHost = bucket + "." + endpoint.getHost();
|
||||
return sameSchemeAndPort(source, endpoint)
|
||||
&& source.getHost().equalsIgnoreCase(expectedHost);
|
||||
}
|
||||
|
||||
private boolean sameSchemeAndPort(URI left, URI right) {
|
||||
return left.getScheme().equalsIgnoreCase(right.getScheme())
|
||||
&& effectivePort(left) == effectivePort(right);
|
||||
}
|
||||
|
||||
private int effectivePort(URI uri) {
|
||||
if (uri.getPort() >= 0) {
|
||||
return uri.getPort();
|
||||
}
|
||||
return "https".equalsIgnoreCase(uri.getScheme()) ? 443 : 80;
|
||||
}
|
||||
|
||||
private boolean isHttpUrl(URI uri) {
|
||||
return "http".equalsIgnoreCase(uri.getScheme()) || "https".equalsIgnoreCase(uri.getScheme());
|
||||
}
|
||||
|
||||
private boolean hasDotPathSegment(String path) {
|
||||
return Stream.of(path.split("/", -1))
|
||||
.anyMatch(segment -> ".".equals(segment) || "..".equals(segment));
|
||||
}
|
||||
|
||||
private MinioClient buildClient() {
|
||||
return minioClient;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user