refactor: 统一文件存储与上传流程,解耦 OSS 客户端、存储类型与前端上传模式

This commit is contained in:
2026-08-25 00:00:19 +08:00
parent 78dbc865fd
commit 81358e6d7c
57 changed files with 776 additions and 672 deletions
@@ -1,9 +1,9 @@
package top.xyquan.ecomdmbbackend.utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import top.xyquan.ecomdmbbackend.modules.sys.file.config.OssConfig;
import top.xyquan.ecomdmbbackend.modules.sys.file.config.SysFileProperties;
import jakarta.annotation.PostConstruct;
@@ -19,13 +19,13 @@ public class SysFileUtils {
@Autowired
private OssConfig ossConfig;
@Value("${file.access-domain:}")
private String fileAccessDomain;
@Autowired
private SysFileProperties sysFileProperties;
@PostConstruct
public void init() {
staticOssConfig = ossConfig;
staticFileAccessDomain = fileAccessDomain;
staticFileAccessDomain = sysFileProperties.getAccessDomain();
}
/**
@@ -46,26 +46,22 @@ public class SysFileUtils {
return null;
}
String domain = staticOssConfig.getDomain();
// 确保域名不以/结尾,路径不以/开头
domain = domain.endsWith("/") ? domain.substring(0, domain.length() - 1) : domain;
String path = storagePath.startsWith("/") ? storagePath : "/" + storagePath;
return domain + path;
} else {
// 本地存储:拼接文件访问域名和存储路径
// 本地存储:拼接 sys.file.access-domain 与路径
if (staticFileAccessDomain == null || staticFileAccessDomain.isEmpty()) {
return null;
}
// 确保域名不以/结尾
String domain = staticFileAccessDomain.endsWith("/")
? staticFileAccessDomain.substring(0, staticFileAccessDomain.length() - 1)
String domain = staticFileAccessDomain.endsWith("/")
? staticFileAccessDomain.substring(0, staticFileAccessDomain.length() - 1)
: staticFileAccessDomain;
// 本地存储路径去掉 ./ 前缀
String path = storagePath.startsWith("./")
? storagePath.substring(2)
String path = storagePath.startsWith("./")
? storagePath.substring(2)
: storagePath;
path = path.startsWith("/") ? path : "/" + path;
return domain + path;
}
}
}