fix: 配置提交500 — 修正静态文件路径 + 启动时创建目录
- par.static.path 默认 ./static(不再重复 configs/) - @PostConstruct 确保 static/configs 目录存在 - submitConfig 异常时详细日志
This commit is contained in:
@@ -45,7 +45,7 @@ mybatis-plus:
|
|||||||
|
|
||||||
par:
|
par:
|
||||||
static:
|
static:
|
||||||
path: ${PAR_STATIC_PATH:./static/configs/}
|
path: ${PAR_STATIC_PATH:./static}
|
||||||
mediabot:
|
mediabot:
|
||||||
psk: ${PAR_MEDIABOT_PSK:}
|
psk: ${PAR_MEDIABOT_PSK:}
|
||||||
admin:
|
admin:
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.par.core.entity.SiteConfig;
|
|||||||
import com.par.core.enums.ConfigStatus;
|
import com.par.core.enums.ConfigStatus;
|
||||||
import com.par.core.mapper.SiteConfigMapper;
|
import com.par.core.mapper.SiteConfigMapper;
|
||||||
import com.par.core.service.ConfigService;
|
import com.par.core.service.ConfigService;
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@@ -32,6 +33,16 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
@Value("${par.static.path:./static}")
|
@Value("${par.static.path:./static}")
|
||||||
private String staticPath;
|
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
|
@Override
|
||||||
public SiteConfig getLatestConfig(String siteId) {
|
public SiteConfig getLatestConfig(String siteId) {
|
||||||
return siteConfigMapper.selectLatestBySiteId(siteId);
|
return siteConfigMapper.selectLatestBySiteId(siteId);
|
||||||
@@ -71,7 +82,13 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
String configHash = HmacUtil.sha256(configJson);
|
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();
|
SiteConfig config = new SiteConfig();
|
||||||
config.setSiteId(siteId);
|
config.setSiteId(siteId);
|
||||||
|
|||||||
Reference in New Issue
Block a user