新增oss内网上传后转换返回外网地址的功能

This commit is contained in:
smallchill 2024-05-28 18:31:48 +08:00
parent 22e3e046d4
commit 7cc4f67b51
5 changed files with 56 additions and 9 deletions

View File

@ -54,7 +54,7 @@ import $!{superControllerClassPackage};
@RestController
@AllArgsConstructor
@RequestMapping("#if($!{hasServiceName})/$!{serviceName}#end/$!{entityKey}")
@Tag(name = "$!{table.comment}", tags = "$!{table.comment}接口")
@Tag(name = "$!{table.comment}", description = "$!{table.comment}接口")
#if($!{superControllerClass})
public class $!{table.controllerName} extends $!{superControllerClass} {
#else

View File

@ -29,6 +29,7 @@ import org.springblade.core.oss.props.OssProperties;
import org.springblade.core.oss.rule.OssRule;
import org.springblade.core.tool.jackson.JsonUtil;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
@ -281,8 +282,8 @@ public class AliossTemplate implements OssTemplate {
* @return String
*/
public String getOssHost(String bucketName) {
String prefix = ossProperties.getEndpoint().contains("https://") ? "https://" : "http://";
return prefix + getBucketName(bucketName) + StringPool.DOT + ossProperties.getEndpoint().replaceFirst(prefix, StringPool.EMPTY);
String prefix = getEndpoint().contains("https://") ? "https://" : "http://";
return prefix + getBucketName(bucketName) + StringPool.DOT + getEndpoint().replaceFirst(prefix, StringPool.EMPTY);
}
/**
@ -294,4 +295,17 @@ public class AliossTemplate implements OssTemplate {
return getOssHost(ossProperties.getBucketName());
}
/**
* 获取服务地址
*
* @return String
*/
public String getEndpoint() {
if (StringUtil.isBlank(ossProperties.getTransformEndpoint())) {
return ossProperties.getEndpoint();
}
return ossProperties.getTransformEndpoint();
}
}

View File

@ -29,6 +29,7 @@ import org.springblade.core.oss.rule.OssRule;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
@ -162,13 +163,13 @@ public class MinioTemplate implements OssTemplate {
@Override
@SneakyThrows
public String fileLink(String fileName) {
return ossProperties.getEndpoint().concat(StringPool.SLASH).concat(getBucketName()).concat(StringPool.SLASH).concat(fileName);
return getEndpoint().concat(StringPool.SLASH).concat(getBucketName()).concat(StringPool.SLASH).concat(fileName);
}
@Override
@SneakyThrows
public String fileLink(String bucketName, String fileName) {
return ossProperties.getEndpoint().concat(StringPool.SLASH).concat(getBucketName(bucketName)).concat(StringPool.SLASH).concat(fileName);
return getEndpoint().concat(StringPool.SLASH).concat(getBucketName(bucketName)).concat(StringPool.SLASH).concat(fileName);
}
@Override
@ -402,7 +403,7 @@ public class MinioTemplate implements OssTemplate {
* @return String
*/
public String getOssHost(String bucketName) {
return ossProperties.getEndpoint() + StringPool.SLASH + getBucketName(bucketName);
return getEndpoint() + StringPool.SLASH + getBucketName(bucketName);
}
/**
@ -414,4 +415,17 @@ public class MinioTemplate implements OssTemplate {
return getOssHost(ossProperties.getBucketName());
}
/**
* 获取服务地址
*
* @return String
*/
public String getEndpoint() {
if (StringUtil.isBlank(ossProperties.getTransformEndpoint())) {
return ossProperties.getEndpoint();
}
return ossProperties.getTransformEndpoint();
}
}

View File

@ -30,6 +30,7 @@ import org.springblade.core.oss.rule.OssRule;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
@ -116,13 +117,13 @@ public class QiniuTemplate implements OssTemplate {
@Override
@SneakyThrows
public String fileLink(String fileName) {
return ossProperties.getEndpoint().concat(StringPool.SLASH).concat(fileName);
return getEndpoint().concat(StringPool.SLASH).concat(fileName);
}
@Override
@SneakyThrows
public String fileLink(String bucketName, String fileName) {
return ossProperties.getEndpoint().concat(StringPool.SLASH).concat(fileName);
return getEndpoint().concat(StringPool.SLASH).concat(fileName);
}
@Override
@ -260,7 +261,20 @@ public class QiniuTemplate implements OssTemplate {
* @return String
*/
public String getOssHost() {
return ossProperties.getEndpoint();
return getEndpoint();
}
/**
* 获取服务地址
*
* @return String
*/
public String getEndpoint() {
if (StringUtil.isBlank(ossProperties.getTransformEndpoint())) {
return ossProperties.getEndpoint();
}
return ossProperties.getTransformEndpoint();
}
}

View File

@ -48,6 +48,11 @@ public class OssProperties {
*/
private String endpoint;
/**
* 转换外网地址的URL
*/
private String transformEndpoint;
/**
* Access key就像用户ID可以唯一标识你的账户
*/