|
@@ -192,9 +192,23 @@ const apiBaseUrl = computed(() => {
|
|
|
|
|
|
|
|
const pythonFormEnabled = computed(() => !!apiBaseUrl.value);
|
|
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() {
|
|
async function loadPythonService() {
|
|
|
try {
|
|
try {
|
|
|
if (!pythonFormEnabled.value) return;
|
|
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 });
|
|
const config = await request.get('/api/system/python-service', { baseURL: apiBaseUrl.value });
|
|
|
pythonService.url = String(config.url || '');
|
|
pythonService.url = String(config.url || '');
|
|
|
} catch {
|
|
} catch {
|
|
@@ -220,7 +234,8 @@ async function saveAll() {
|
|
|
url: normalizedServerUrl,
|
|
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 });
|
|
await request.put('/api/system/python-service', { url: normalizeBaseUrl(pythonService.url) }, { baseURL: normalizedServerUrl });
|
|
|
}
|
|
}
|
|
|
|
|
|