mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2025-12-16 12:23:03 +00:00
Address code review feedback: improve error handling and add missing import
Co-authored-by: qaiu <29825328+qaiu@users.noreply.github.com>
This commit is contained in:
@@ -531,6 +531,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { ref, computed, onMounted, onUnmounted, nextTick, watch } from 'vue';
|
import { ref, computed, onMounted, onUnmounted, nextTick, watch } from 'vue';
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||||
|
import { Lock } from '@element-plus/icons-vue';
|
||||||
import { useMagicKeys, useFullscreen, useEventListener } from '@vueuse/core';
|
import { useMagicKeys, useFullscreen, useEventListener } from '@vueuse/core';
|
||||||
import { Splitpanes, Pane } from 'splitpanes';
|
import { Splitpanes, Pane } from 'splitpanes';
|
||||||
import 'splitpanes/dist/splitpanes.css';
|
import 'splitpanes/dist/splitpanes.css';
|
||||||
@@ -545,7 +546,8 @@ export default {
|
|||||||
MonacoEditor,
|
MonacoEditor,
|
||||||
JsonViewer,
|
JsonViewer,
|
||||||
Splitpanes,
|
Splitpanes,
|
||||||
Pane
|
Pane,
|
||||||
|
Lock
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
const editorRef = ref(null);
|
const editorRef = ref(null);
|
||||||
|
|||||||
@@ -150,18 +150,43 @@ public class PlaygroundApi {
|
|||||||
*/
|
*/
|
||||||
private String getClientId(HttpServerRequest request) {
|
private String getClientId(HttpServerRequest request) {
|
||||||
// 优先使用Cookie中的session id,否则使用IP
|
// 优先使用Cookie中的session id,否则使用IP
|
||||||
String cookie = request.getHeader("Cookie");
|
String sessionId = extractSessionIdFromCookie(request);
|
||||||
if (cookie != null && cookie.contains("playground_session=")) {
|
if (sessionId != null) {
|
||||||
String sessionId = cookie.substring(cookie.indexOf("playground_session=") + 19);
|
|
||||||
int endIndex = sessionId.indexOf(";");
|
|
||||||
if (endIndex > 0) {
|
|
||||||
sessionId = sessionId.substring(0, endIndex);
|
|
||||||
}
|
|
||||||
return sessionId;
|
return sessionId;
|
||||||
}
|
}
|
||||||
return getClientIp(request);
|
return getClientIp(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从Cookie中提取session ID
|
||||||
|
*/
|
||||||
|
private String extractSessionIdFromCookie(HttpServerRequest request) {
|
||||||
|
String cookie = request.getHeader("Cookie");
|
||||||
|
if (cookie == null || !cookie.contains("playground_session=")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
final String SESSION_KEY = "playground_session=";
|
||||||
|
int startIndex = cookie.indexOf(SESSION_KEY);
|
||||||
|
if (startIndex == -1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
startIndex += SESSION_KEY.length();
|
||||||
|
int endIndex = cookie.indexOf(";", startIndex);
|
||||||
|
|
||||||
|
if (endIndex > startIndex) {
|
||||||
|
return cookie.substring(startIndex, endIndex).trim();
|
||||||
|
} else {
|
||||||
|
return cookie.substring(startIndex).trim();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Failed to extract session ID from cookie", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查是否已认证
|
* 检查是否已认证
|
||||||
*/
|
*/
|
||||||
@@ -379,21 +404,21 @@ public class PlaygroundApi {
|
|||||||
// 检查访问权限
|
// 检查访问权限
|
||||||
ensurePlaygroundAccess(ctx);
|
ensurePlaygroundAccess(ctx);
|
||||||
|
|
||||||
try (InputStream inputStream = getClass().getClassLoader()
|
InputStream inputStream = getClass().getClassLoader()
|
||||||
.getResourceAsStream("custom-parsers/types.js")) {
|
.getResourceAsStream("custom-parsers/types.js");
|
||||||
|
|
||||||
if (inputStream == null) {
|
if (inputStream == null) {
|
||||||
ResponseUtil.fireJsonResultResponse(response, JsonResult.error("types.js文件不存在"));
|
ResponseUtil.fireJsonResultResponse(response, JsonResult.error("types.js文件不存在"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String content = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))
|
try (inputStream) {
|
||||||
.lines()
|
String content = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))
|
||||||
.collect(Collectors.joining("\n"));
|
.lines()
|
||||||
|
.collect(Collectors.joining("\n"));
|
||||||
response.putHeader("Content-Type", "text/javascript; charset=utf-8")
|
|
||||||
.end(content);
|
|
||||||
|
|
||||||
|
response.putHeader("Content-Type", "text/javascript; charset=utf-8")
|
||||||
|
.end(content);
|
||||||
}
|
}
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
log.error("访问Playground失败", e);
|
log.error("访问Playground失败", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user