feat: 默认脚本分保存本地和上传七牛云两个按钮
This commit is contained in:
@@ -53,7 +53,24 @@ public class GroovyScriptEngine {
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存站点类型默认脚本到七牛云+本地缓存
|
||||
* 保存默认脚本到本地文件(不上传七牛云)
|
||||
*/
|
||||
public static void saveDefaultLocal(String siteType, String script) {
|
||||
if (siteType == null || script == null) return;
|
||||
String key = siteType.toLowerCase();
|
||||
DEFAULT_SCRIPTS_CACHE.put(key, script);
|
||||
try {
|
||||
var path = java.nio.file.Paths.get(
|
||||
GroovyScriptEngine.class.getClassLoader().getResource("scripts/default-" + key + ".groovy").toURI());
|
||||
java.nio.file.Files.writeString(path, script, java.nio.charset.StandardCharsets.UTF_8);
|
||||
log.info("Default script saved locally: default-{}.groovy", key);
|
||||
} catch (Exception e) {
|
||||
log.warn("Local save failed: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传默认脚本到七牛云+本地缓存
|
||||
*/
|
||||
public static void saveDefaultScript(String siteType, String script) {
|
||||
if (siteType == null || script == null) return;
|
||||
@@ -61,17 +78,8 @@ public class GroovyScriptEngine {
|
||||
DEFAULT_SCRIPTS_CACHE.put(key, script);
|
||||
if (storageService != null) {
|
||||
storageService.store(DEFAULT_SCRIPTS_PATH + key + ".groovy", script);
|
||||
} else {
|
||||
// 回退到 classpath 写入(开发环境)
|
||||
try {
|
||||
var path = java.nio.file.Paths.get(
|
||||
GroovyScriptEngine.class.getClassLoader().getResource("scripts/default-" + key + ".groovy").toURI());
|
||||
java.nio.file.Files.writeString(path, script, java.nio.charset.StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
log.warn("Fallback save failed: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
log.info("Default script saved: default-{}.groovy", key);
|
||||
log.info("Default script uploaded: default-{}.groovy", key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user