mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 12:52:07 +08:00
组件文件获取接口支持域名可配
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
package com.cf.imes.module.infra.framework.file.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 外部文件访问地址配置。
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "chenfeng.file")
|
||||
public class ExternalFileProperties {
|
||||
|
||||
/**
|
||||
* 拼接数据库外部文件路径的 CDN 域名。
|
||||
*/
|
||||
private String externalDomain = "https://cdn.fzcfkj.com/";
|
||||
}
|
||||
+23
-1
@@ -8,6 +8,7 @@ import com.cf.imes.framework.common.util.Assert.AssertUtils;
|
||||
import com.cf.imes.framework.common.util.io.FileUtils;
|
||||
import com.cf.imes.module.infra.framework.file.core.client.FileClient;
|
||||
import com.cf.imes.module.infra.framework.file.core.utils.FileTypeUtils;
|
||||
import com.cf.imes.module.infra.framework.file.config.ExternalFileProperties;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.module.infra.controller.admin.file.vo.file.FilePageReqVO;
|
||||
import com.cf.imes.module.infra.dal.dataobject.file.FileDO;
|
||||
@@ -40,6 +41,9 @@ public class FileServiceImpl implements FileService {
|
||||
@Resource
|
||||
private FileMapper fileMapper;
|
||||
|
||||
@Resource
|
||||
private ExternalFileProperties externalFileProperties;
|
||||
|
||||
private static final String CLIENT_ERR_NOTIFICATION = "客户端({}) 不能为空";
|
||||
|
||||
@Override
|
||||
@@ -200,7 +204,25 @@ public class FileServiceImpl implements FileService {
|
||||
*/
|
||||
@Override
|
||||
public String getExternalFileUrl(Long id) {
|
||||
return validateFileExists(id).getUrl();
|
||||
String storedUrl = validateFileExists(id).getUrl();
|
||||
return joinUrl(externalFileProperties.getExternalDomain(), storedUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接配置域名和数据库文件路径,并消除连接处的重复斜杠。
|
||||
*/
|
||||
private String joinUrl(String domain, String path) {
|
||||
AssertUtils.notEmpty(domain, FILE_IS_EMPTY);
|
||||
AssertUtils.notEmpty(path, FILE_IS_EMPTY);
|
||||
int domainEnd = domain.length();
|
||||
while (domainEnd > 0 && domain.charAt(domainEnd - 1) == '/') {
|
||||
domainEnd--;
|
||||
}
|
||||
int pathStart = 0;
|
||||
while (pathStart < path.length() && path.charAt(pathStart) == '/') {
|
||||
pathStart++;
|
||||
}
|
||||
return domain.substring(0, domainEnd) + "/" + path.substring(pathStart);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -126,6 +126,8 @@ spring:
|
||||
|
||||
# 晨丰配置项,设置当前项目所有自定义的配置
|
||||
chenfeng:
|
||||
file:
|
||||
external-domain: https://cdn.fzcfkj.com/
|
||||
info:
|
||||
version: 1.0.0
|
||||
base-package: com.cf.imes.module.infra
|
||||
@@ -186,4 +188,4 @@ chenfeng:
|
||||
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
|
||||
log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
|
||||
|
||||
@@ -144,6 +144,8 @@ logging:
|
||||
|
||||
# 晨丰配置项,设置当前项目所有自定义的配置
|
||||
chenfeng:
|
||||
file:
|
||||
external-domain: https://cdn.fzcfkj.com/
|
||||
info:
|
||||
version: 1.0.0
|
||||
base-package: com.cf.imes.module.infra
|
||||
@@ -207,4 +209,4 @@ chenfeng:
|
||||
enable: false
|
||||
encrypt:
|
||||
enable: false
|
||||
publicKey: cfimes
|
||||
publicKey: cfimes
|
||||
|
||||
Reference in New Issue
Block a user