Address code review feedback: protect types.js endpoint and improve code readability

Co-authored-by: qaiu <29825328+qaiu@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-07 05:27:07 +00:00
parent 41fc935c09
commit c79702eba8
2 changed files with 15 additions and 2 deletions

View File

@@ -21,7 +21,7 @@
<span style="margin-left: 10px;">正在检查访问权限...</span> <span style="margin-left: 10px;">正在检查访问权限...</span>
</div> </div>
<div v-if="!loading && !authChecking && !authed" class="playground-auth-overlay"> <div v-if="shouldShowAuthUI" class="playground-auth-overlay">
<div class="playground-auth-card"> <div class="playground-auth-card">
<div class="auth-icon"> <div class="auth-icon">
<el-icon :size="50"><Lock /></el-icon> <el-icon :size="50"><Lock /></el-icon>
@@ -788,6 +788,11 @@ async function parseById(
return isDarkMode.value ? 'vs-dark' : 'vs'; return isDarkMode.value ? 'vs-dark' : 'vs';
}); });
// 计算属性:是否需要显示密码输入界面
const shouldShowAuthUI = computed(() => {
return !loading.value && !authChecking.value && !authed.value;
});
// 编辑器配置 // 编辑器配置
const editorOptions = { const editorOptions = {
minimap: { enabled: true }, minimap: { enabled: true },
@@ -1613,6 +1618,7 @@ curl "${baseUrl}/json/parser?url=${encodeURIComponent(exampleUrl)}"</pre>
testing, testing,
isDarkMode, isDarkMode,
editorTheme, editorTheme,
shouldShowAuthUI,
editorOptions, editorOptions,
// 加载和认证 // 加载和认证
loading, loading,

View File

@@ -311,10 +311,17 @@ public class PlaygroundApi {
/** /**
* 获取types.js文件内容 * 获取types.js文件内容
* *
* @param ctx 路由上下文
* @param response HTTP响应 * @param response HTTP响应
*/ */
@RouteMapping(value = "/types.js", method = RouteMethod.GET) @RouteMapping(value = "/types.js", method = RouteMethod.GET)
public void getTypesJs(HttpServerResponse response) { public void getTypesJs(RoutingContext ctx, HttpServerResponse response) {
// 权限检查
if (!checkAuth(ctx)) {
ResponseUtil.fireJsonResultResponse(response, JsonResult.error("未授权访问"));
return;
}
try (InputStream inputStream = getClass().getClassLoader() try (InputStream inputStream = getClass().getClassLoader()
.getResourceAsStream("custom-parsers/types.js")) { .getResourceAsStream("custom-parsers/types.js")) {