This commit is contained in:
2026-09-10 17:52:15 +08:00
parent 4861608c4e
commit 16c47210b7
2 changed files with 92 additions and 9 deletions
+12 -9
View File
@@ -5,14 +5,9 @@
</component>
<component name="ChangeListManager">
<list default="true" id="1719acca-367b-404a-afec-6277f106f2d4" name="Changes" comment="1">
<change afterPath="$PROJECT_DIR$/.idea/git_toolbox_prj.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/kotlinc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/io/v/nutz/web/commons/ext/beetl/BeetlCustomResourceLoader.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/io/v/nutz/web/commons/proc/NutShiroProcessor.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/io/v/nutz/web/commons/proc/NutShiroProcessor.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/application.properties" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/application.properties" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/views/platform/data/user/SourceUser.html" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/views/platform/data/user/SourceUser.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/views/platform/data/user/UpdateUser.html" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/views/platform/data/user/UpdateUser.html" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -94,11 +89,11 @@
<recent name="G:\projects\UNION_HUTB\src\main\resources\chain" />
</key>
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="io.v.nutz.web.commons.ext.beetl" />
<recent name="io.v.nutz.question.controller" />
<recent name="io.v.nutz.web.modules.controllers.platform.sys" />
<recent name="io.v.nutz.web.commons.validate" />
<recent name="io.v.nutz.base.result" />
<recent name="io.v.nutz.web.commons" />
</key>
</component>
<component name="RunAnythingCache">
@@ -171,7 +166,7 @@
<workItem from="1788829714943" duration="16873000" />
<workItem from="1788870526241" duration="597000" />
<workItem from="1788915405430" duration="16496000" />
<workItem from="1789005416130" duration="6147000" />
<workItem from="1789005416130" duration="11214000" />
</task>
<task id="LOCAL-00001">
<created>1695868954392</created>
@@ -224,7 +219,15 @@
<option name="project" value="LOCAL" />
<updated>1788925494296</updated>
</task>
<option name="localTasksCounter" value="8" />
<task id="LOCAL-00008" summary="1">
<option name="closed" value="true" />
<created>1789027539831</created>
<option name="number" value="00008" />
<option name="presentableId" value="LOCAL-00008" />
<option name="project" value="LOCAL" />
<updated>1789027539831</updated>
</task>
<option name="localTasksCounter" value="9" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@@ -0,0 +1,80 @@
package io.v.nutz.web.commons.ext.beetl;
import org.beetl.core.Resource;
import org.beetl.core.misc.BeetlUtil;
import org.beetl.core.resource.ClasspathResource;
import org.beetl.core.resource.ClasspathResourceLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class BeetlCustomResourceLoader extends ClasspathResourceLoader {
@Override
public Resource getResource(String key) {
Resource resource = new ClasspathResource(key, this.getChildPath(super.getRoot(), key), this);
return resource;
}
@Override
public String getResourceId(Resource resource, String id) {
// return resource == null ? id : BeetlUtil.getRelPath(resource.getId(), id);
return getRelPath(resource.getId(), id);
}
/**
* 增加判断相对路径
* 光见鬼
*/
private String getRelPath(String siblings, String resourceId) {
// 参数校验
if (resourceId == null || resourceId.isEmpty()) {
throw new RuntimeException("资源ID为空,参数错");
}
// 如果是绝对路径,直接返回(以 / 或 \ 开头)
if (resourceId.charAt(0) == '\\' || resourceId.charAt(0) == '/') {
if (BeetlUtil.isOutsideOfRoot(resourceId)) {
throw new RuntimeException("不能访问外部文件或者模板");
}
return resourceId;
}
// 处理相对路径
String baseDir = siblings;
// 如果siblings是文件路径,获取其所在目录
int lastSeparatorIndex = Math.max(siblings.lastIndexOf('/'), siblings.lastIndexOf('\\'));
if (lastSeparatorIndex > 0) {
baseDir = siblings.substring(0, lastSeparatorIndex + 1);
}
// 分割路径
String[] parts = resourceId.replace('\\', '/').split("/");
List<String> baseParts = new ArrayList<>(
Arrays.asList(baseDir.replace('\\', '/').split("/"))
);
baseParts.removeIf(String::isEmpty);
// 处理 ../ 和 ./
for (String part : parts) {
if ("..".equals(part)) {
if (!baseParts.isEmpty()) {
baseParts.remove(baseParts.size() - 1);
}
} else if (!".".equals(part) && !part.isEmpty()) {
baseParts.add(part);
}
}
// 组合最终路径
String result = "/" + String.join("/", baseParts);
// 检查是否访问外部文件
if (BeetlUtil.isOutsideOfRoot(result)) {
throw new RuntimeException("不能访问外部文件或者模板");
}
return result;
}
}