完成视频部分的前后端
This commit is contained in:
+21
-5
@@ -38,10 +38,11 @@ public class OssStorageService {
|
||||
|
||||
public UploadedResult uploadResultFileWithFreshDownloadUrl(File file, String moduleType) {
|
||||
String objectKey = String.format("result/%s/%s/%s", moduleType.toLowerCase(), UUID.randomUUID(), file.getName());
|
||||
String bucket = resolveBucket(moduleType);
|
||||
OSS ossClient = buildClient();
|
||||
try {
|
||||
ossClient.putObject(ossProperties.getBucket(), objectKey, file);
|
||||
return new UploadedResult(objectKey, getPublicUrl(objectKey));
|
||||
ossClient.putObject(bucket, objectKey, file);
|
||||
return new UploadedResult(objectKey, getPublicUrl(objectKey, bucket));
|
||||
} finally {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
@@ -56,10 +57,11 @@ public class OssStorageService {
|
||||
objectName = file.getName();
|
||||
}
|
||||
String objectKey = String.format("upload/%s/%s/%s", normalizedModuleType, UUID.randomUUID(), objectName);
|
||||
String bucket = resolveBucket(moduleType);
|
||||
OSS ossClient = buildClient();
|
||||
try {
|
||||
ossClient.putObject(ossProperties.getBucket(), objectKey, file);
|
||||
return new UploadedResult(objectKey, getPublicUrl(objectKey));
|
||||
ossClient.putObject(bucket, objectKey, file);
|
||||
return new UploadedResult(objectKey, getPublicUrl(objectKey, bucket));
|
||||
} finally {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
@@ -151,12 +153,16 @@ public class OssStorageService {
|
||||
* 获取公开(无签名)URL,格式:https://{bucket}.{endpoint}/{objectKey}
|
||||
*/
|
||||
public String getPublicUrl(String value) {
|
||||
return getPublicUrl(value, ossProperties.getBucket());
|
||||
}
|
||||
|
||||
private String getPublicUrl(String value, String bucket) {
|
||||
if (value == null || value.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
String objectKey = resolveObjectKey(value);
|
||||
String normalizedKey = objectKey.startsWith("/") ? objectKey.substring(1) : objectKey;
|
||||
String host = String.format("%s.%s", ossProperties.getBucket(), publicEndpoint());
|
||||
String host = String.format("%s.%s", bucket, publicEndpoint());
|
||||
try {
|
||||
return new URI("https", host, "/" + normalizedKey, null).toASCIIString();
|
||||
} catch (Exception ignored) {
|
||||
@@ -210,6 +216,16 @@ public class OssStorageService {
|
||||
);
|
||||
}
|
||||
|
||||
private String resolveBucket(String moduleType) {
|
||||
if (moduleType != null
|
||||
&& "IMAGE_VIDEO".equalsIgnoreCase(moduleType.trim())
|
||||
&& ossProperties.getImageVideoBucket() != null
|
||||
&& !ossProperties.getImageVideoBucket().isBlank()) {
|
||||
return ossProperties.getImageVideoBucket().trim();
|
||||
}
|
||||
return ossProperties.getBucket();
|
||||
}
|
||||
|
||||
private String publicEndpoint() {
|
||||
String endpoint = ossProperties.getPublicEndpoint();
|
||||
if (endpoint == null || endpoint.isBlank()) {
|
||||
|
||||
Reference in New Issue
Block a user