Selaa lähdekoodia

refactor: streamline Python service management and update build process

- Simplified the build script in package.json by removing unnecessary type-checking step.
- Updated electron version in package.json for better compatibility.
- Refactored Python service configuration logic in index.vue to remove admin check, allowing non-admin users to manage service URLs.
- Changed server route authentication to allow any logged-in user or local requests for Python service management, enhancing accessibility.
Ethanfly 7 tuntia sitten
vanhempi
commit
376b1fd91c
3 muutettua tiedostoa jossa 12 lisäystä ja 28 poistoa
  1. 2 1
      client/package.json
  2. 4 17
      client/src/views/ServerConfig/index.vue
  3. 6 10
      server/src/routes/system.ts

+ 2 - 1
client/package.json

@@ -5,7 +5,7 @@
   "main": "dist-electron/main.js",
   "scripts": {
     "dev": "vite",
-    "build": "vue-tsc --noEmit && vite build && electron-builder",
+    "build": "vite build && electron-builder",
     "build:vite": "vite build",
     "preview": "vite preview",
     "electron:dev": "vite --mode electron",
@@ -50,6 +50,7 @@
   "build": {
     "appId": "com.media-manager.app",
     "productName": "智媒通",
+    "electronVersion": "28.1.3",
     "directories": {
       "output": "release"
     },

+ 4 - 17
client/src/views/ServerConfig/index.vue

@@ -75,7 +75,6 @@
       <div class="python-config">
         <div class="section-title-row">
           <div class="section-title">Python 服务配置</div>
-          <el-tag v-if="!canManagePythonService" type="info" size="small">需管理员登录</el-tag>
         </div>
         <el-form :model="pythonService" label-position="top" class="config-form">
           <el-form-item label="服务地址">
@@ -186,23 +185,11 @@ function normalizeBaseUrl(url?: string): string {
   }
 }
 
-function isLocalServerUrl(url?: string): boolean {
-  if (!url) return false;
-  try {
-    const u = new URL(url);
-    const host = u.hostname;
-    return host === 'localhost' || host === '127.0.0.1' || host === '::1';
-  } catch {
-    return false;
-  }
-}
-
 const apiBaseUrl = computed(() => {
   return normalizeBaseUrl(serverStore.currentServer?.url) || normalizeBaseUrl(serverForm.url);
 });
 
-const canManagePythonService = computed(() => authStore.isAdmin || isLocalServerUrl(apiBaseUrl.value));
-const pythonFormEnabled = computed(() => !!apiBaseUrl.value && canManagePythonService.value);
+const pythonFormEnabled = computed(() => !!apiBaseUrl.value);
 
 async function loadPythonService() {
   try {
@@ -232,7 +219,7 @@ async function saveAll() {
       url: normalizedServerUrl,
     });
 
-    if (pythonService.url && canManagePythonService.value) {
+    if (pythonService.url && pythonFormEnabled.value) {
       await request.put('/api/system/python-service', { url: normalizeBaseUrl(pythonService.url) }, { baseURL: normalizedServerUrl });
     }
 
@@ -245,8 +232,8 @@ async function saveAll() {
 }
 
 async function checkPythonService() {
-  if (!canManagePythonService.value) {
-    ElMessage.warning('需要管理员登录后才能配置');
+  if (!pythonFormEnabled.value) {
+    ElMessage.warning('请先填写服务器地址');
     return;
   }
   if (!apiBaseUrl.value) {

+ 6 - 10
server/src/routes/system.ts

@@ -16,17 +16,13 @@ function isLoopbackRequest(req: Request): boolean {
     || ip.startsWith('::ffff:127.');
 }
 
-function requireAdminOrLoopback(req: Request, res: Response, next: NextFunction): void {
+// 本地回环请求放行,否则需任一已登录用户(不要求管理员)
+function requireAuthOrLoopback(req: Request, res: Response, next: NextFunction): void {
   if (isLoopbackRequest(req)) {
     next();
     return;
   }
-
-  try {
-    authenticate(req, res, () => authorize('admin')(req, res, next));
-  } catch (e) {
-    next(e);
-  }
+  authenticate(req, res, next);
 }
 
 // 获取系统配置(公开)
@@ -99,7 +95,7 @@ router.put(
 
 router.get(
   '/python-service',
-  requireAdminOrLoopback,
+  requireAuthOrLoopback,
   asyncHandler(async (_req, res) => {
     const config = await systemService.getPythonServiceAdminConfig();
     res.json({ success: true, data: config });
@@ -108,7 +104,7 @@ router.get(
 
 router.put(
   '/python-service',
-  requireAdminOrLoopback,
+  requireAuthOrLoopback,
   [
     body('url').optional().isString(),
     validateRequest,
@@ -121,7 +117,7 @@ router.put(
 
 router.post(
   '/python-service/check',
-  requireAdminOrLoopback,
+  requireAuthOrLoopback,
   [
     body('url').optional().isString(),
     validateRequest,