fix: 配置提交500 — 修正静态文件路径 + 启动时创建目录
- par.static.path 默认 ./static(不再重复 configs/) - @PostConstruct 确保 static/configs 目录存在 - submitConfig 异常时详细日志
This commit is contained in:
@@ -6,6 +6,7 @@ import com.par.core.entity.SiteConfig;
|
||||
import com.par.core.enums.ConfigStatus;
|
||||
import com.par.core.mapper.SiteConfigMapper;
|
||||
import com.par.core.service.ConfigService;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -32,6 +33,16 @@ public class ConfigServiceImpl implements ConfigService {
|
||||
@Value("${par.static.path:./static}")
|
||||
private String staticPath;
|
||||
|
||||
@PostConstruct
|
||||
void init() {
|
||||
try {
|
||||
Files.createDirectories(Paths.get(staticPath, "configs"));
|
||||
log.info("Config static dir ready: {}", Paths.get(staticPath, "configs").toAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to create config static dir: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SiteConfig getLatestConfig(String siteId) {
|
||||
return siteConfigMapper.selectLatestBySiteId(siteId);
|
||||
@@ -71,7 +82,13 @@ public class ConfigServiceImpl implements ConfigService {
|
||||
String configHash = HmacUtil.sha256(configJson);
|
||||
|
||||
// 存储静态文件
|
||||
String storagePath = storeConfigFile(siteId, version, configJson);
|
||||
String storagePath;
|
||||
try {
|
||||
storagePath = storeConfigFile(siteId, version, configJson);
|
||||
} catch (Exception e) {
|
||||
log.error("存储配置文件失败 siteId={} version={}: {}", siteId, version, e.getMessage());
|
||||
throw new RuntimeException("存储配置文件失败: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
SiteConfig config = new SiteConfig();
|
||||
config.setSiteId(siteId);
|
||||
|
||||
Reference in New Issue
Block a user