From dcba64096e288968d368ad3916736f26bf5399c4 Mon Sep 17 00:00:00 2001 From: mediabot-pt <295750538+mediabot-pt@users.noreply.github.com> Date: Wed, 1 Jul 2026 10:47:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20config=20=E5=AD=97=E6=AE=B5=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=8F=AF=E9=80=89=EF=BC=8C=E5=8F=AA=E4=BC=A0=20script?= =?UTF-8?q?=20=E5=8D=B3=E5=8F=AF=E6=8F=90=E4=BA=A4=E7=BA=AFGroovy=E9=80=82?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../par/api/controller/ConfigController.java | 7 +++-- .../core/service/impl/ConfigServiceImpl.java | 27 +++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/par-api/src/main/java/com/par/api/controller/ConfigController.java b/par-api/src/main/java/com/par/api/controller/ConfigController.java index 21b4073..cebc39d 100644 --- a/par-api/src/main/java/com/par/api/controller/ConfigController.java +++ b/par-api/src/main/java/com/par/api/controller/ConfigController.java @@ -154,8 +154,11 @@ public class ConfigController { String schemaVersion = (String) payload.get("schemaVersion"); String groovyScript = (String) payload.get("script"); - if (version == null || configJson == null) { - return ApiResponse.error(400, "version and config are required"); + if (version == null) { + return ApiResponse.error(400, "version is required"); + } + if ((configJson == null || configJson.isBlank()) && (groovyScript == null || groovyScript.isBlank())) { + return ApiResponse.error(400, "config 或 script 至少需要一个"); } Long submitterId = (Long) request.getAttribute("accountId"); diff --git a/par-core/src/main/java/com/par/core/service/impl/ConfigServiceImpl.java b/par-core/src/main/java/com/par/core/service/impl/ConfigServiceImpl.java index d9a349a..aa3e9be 100644 --- a/par-core/src/main/java/com/par/core/service/impl/ConfigServiceImpl.java +++ b/par-core/src/main/java/com/par/core/service/impl/ConfigServiceImpl.java @@ -56,8 +56,10 @@ public class ConfigServiceImpl implements ConfigService { @Override public SiteConfig submitConfig(String siteId, String version, String configJson, String schemaVersion, String groovyScript, Long submitterId) { - String configHash = HmacUtil.sha256(configJson); - String storagePath = String.format("configs/%s/pending/%s.json", siteId, configHash.substring(0, 8)); + boolean hasConfig = configJson != null && !configJson.isBlank(); + boolean hasScript = groovyScript != null && !groovyScript.isBlank(); + String configHash = hasConfig ? HmacUtil.sha256(configJson) : HmacUtil.sha256(groovyScript); + String idPrefix = hasConfig ? configHash.substring(0, 8) : Long.toHexString(System.currentTimeMillis()); // 相同 hash 的提交 → 真正重复,跳过 SiteConfig sameHash = siteConfigMapper.selectOne( @@ -70,18 +72,21 @@ public class ConfigServiceImpl implements ConfigService { return sameHash; } - // 存储配置 - try { - storageService.store(storagePath, configJson); - } catch (Exception e) { - log.error("存储配置文件失败 siteId={} version={}: {}", siteId, version, e.getMessage()); - throw new RuntimeException("存储配置文件失败: " + e.getMessage(), e); + // 存储 JSON 配置(可选) + String storagePath = null; + if (hasConfig) { + storagePath = String.format("configs/%s/pending/%s.json", siteId, idPrefix); + try { storageService.store(storagePath, configJson); } + catch (Exception e) { + log.error("存储配置文件失败 siteId={} version={}: {}", siteId, version, e.getMessage()); + throw new RuntimeException("存储配置文件失败: " + e.getMessage(), e); + } } - // 存储 Groovy 脚本(可选) + // 存储 Groovy 脚本 String scriptPath = null; - if (groovyScript != null && !groovyScript.isBlank()) { - scriptPath = String.format("configs/%s/pending/%s.groovy", siteId, configHash.substring(0, 8)); + if (hasScript) { + scriptPath = String.format("configs/%s/pending/%s.groovy", siteId, idPrefix); storageService.store(scriptPath, groovyScript); }