feat: 优化
This commit is contained in:
@@ -52,4 +52,11 @@ public interface FileApi {
|
||||
String presignGetUrl(@NotEmpty(message = "URL 不能为空") String url,
|
||||
Integer expirationSeconds);
|
||||
|
||||
/**
|
||||
* 获取主文件配置的自定义域名(CDN域名)
|
||||
*
|
||||
* @return 自定义域名,如 https://oss.muyetools.cn
|
||||
*/
|
||||
String getMasterFileDomain();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package cn.iocoder.yudao.module.infra.api.file;
|
||||
|
||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClient;
|
||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.s3.S3FileClient;
|
||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.s3.S3FileClientConfig;
|
||||
import cn.iocoder.yudao.module.infra.service.file.FileConfigService;
|
||||
import cn.iocoder.yudao.module.infra.service.file.FileService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -17,6 +21,9 @@ public class FileApiImpl implements FileApi {
|
||||
@Resource
|
||||
private FileService fileService;
|
||||
|
||||
@Resource
|
||||
private FileConfigService fileConfigService;
|
||||
|
||||
@Override
|
||||
public String createFile(byte[] content, String name, String directory, String type) {
|
||||
return fileService.createFile(content, name, directory, type);
|
||||
@@ -27,4 +34,14 @@ public class FileApiImpl implements FileApi {
|
||||
return fileService.presignGetUrl(url, expirationSeconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMasterFileDomain() {
|
||||
FileClient client = fileConfigService.getMasterFileClient();
|
||||
if (client instanceof S3FileClient) {
|
||||
S3FileClient s3Client = (S3FileClient) client;
|
||||
return s3Client.getConfig().getDomain();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,6 +54,11 @@ public abstract class AbstractFileClient<Config extends FileClientConfig> implem
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Config getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化文件的 URL 访问地址
|
||||
* 使用场景:local、ftp、db,通过 FileController 的 getFile 来获取文件内容
|
||||
|
||||
@@ -74,4 +74,11 @@ public interface FileClient {
|
||||
throw new UnsupportedOperationException("不支持的操作");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件配置
|
||||
*
|
||||
* @return 文件配置
|
||||
*/
|
||||
FileClientConfig getConfig();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user