Skip to content

Commit c79702e

Browse files
Copilotqaiu
andcommitted
Address code review feedback: protect types.js endpoint and improve code readability
Co-authored-by: qaiu <29825328+qaiu@users.noreply.github.com>
1 parent 41fc935 commit c79702e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

web-front/src/views/Playground.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<span style="margin-left: 10px;">正在检查访问权限...</span>
2222
</div>
2323

24-
<div v-if="!loading && !authChecking && !authed" class="playground-auth-overlay">
24+
<div v-if="shouldShowAuthUI" class="playground-auth-overlay">
2525
<div class="playground-auth-card">
2626
<div class="auth-icon">
2727
<el-icon :size="50"><Lock /></el-icon>
@@ -787,6 +787,11 @@ async function parseById(
787787
const editorTheme = computed(() => {
788788
return isDarkMode.value ? 'vs-dark' : 'vs';
789789
});
790+
791+
// 计算属性:是否需要显示密码输入界面
792+
const shouldShowAuthUI = computed(() => {
793+
return !loading.value && !authChecking.value && !authed.value;
794+
});
790795
791796
// 编辑器配置
792797
const editorOptions = {
@@ -1613,6 +1618,7 @@ curl "${baseUrl}/json/parser?url=${encodeURIComponent(exampleUrl)}"</pre>
16131618
testing,
16141619
isDarkMode,
16151620
editorTheme,
1621+
shouldShowAuthUI,
16161622
editorOptions,
16171623
// 加载和认证
16181624
loading,

web-service/src/main/java/cn/qaiu/lz/web/controller/PlaygroundApi.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,17 @@ public Future<JsonObject> test(RoutingContext ctx) {
311311
/**
312312
* 获取types.js文件内容
313313
*
314+
* @param ctx 路由上下文
314315
* @param response HTTP响应
315316
*/
316317
@RouteMapping(value = "/types.js", method = RouteMethod.GET)
317-
public void getTypesJs(HttpServerResponse response) {
318+
public void getTypesJs(RoutingContext ctx, HttpServerResponse response) {
319+
// 权限检查
320+
if (!checkAuth(ctx)) {
321+
ResponseUtil.fireJsonResultResponse(response, JsonResult.error("未授权访问"));
322+
return;
323+
}
324+
318325
try (InputStream inputStream = getClass().getClassLoader()
319326
.getResourceAsStream("custom-parsers/types.js")) {
320327

0 commit comments

Comments
 (0)