Ethanfly 19 timmar sedan
förälder
incheckning
2ba397b49c
1 ändrade filer med 16 tillägg och 1 borttagningar
  1. 16 1
      client/src/views/ServerConfig/index.vue

+ 16 - 1
client/src/views/ServerConfig/index.vue

@@ -192,9 +192,23 @@ const apiBaseUrl = computed(() => {
 
 const pythonFormEnabled = computed(() => !!apiBaseUrl.value);
 
+function isLocalServerUrl(url?: string): boolean {
+  if (!url) return false;
+  try {
+    const u = new URL(url);
+    const h = u.hostname;
+    return h === 'localhost' || h === '127.0.0.1' || h === '::1';
+  } catch {
+    return false;
+  }
+}
+
+// 仅当已登录或本地服务器时加载 Python 配置,避免未登录访问远程接口触发 401
 async function loadPythonService() {
   try {
     if (!pythonFormEnabled.value) return;
+    const canLoad = authStore.isAuthenticated || isLocalServerUrl(apiBaseUrl.value);
+    if (!canLoad) return;
     const config = await request.get('/api/system/python-service', { baseURL: apiBaseUrl.value });
     pythonService.url = String(config.url || '');
   } catch {
@@ -220,7 +234,8 @@ async function saveAll() {
       url: normalizedServerUrl,
     });
 
-    if (pythonService.url && pythonFormEnabled.value) {
+    const canSavePython = authStore.isAuthenticated || isLocalServerUrl(normalizedServerUrl);
+    if (pythonService.url && pythonFormEnabled.value && canSavePython) {
       await request.put('/api/system/python-service', { url: normalizeBaseUrl(pythonService.url) }, { baseURL: normalizedServerUrl });
     }