From 0baa3921bcba2ef8b1c28660863463d0476b5795 Mon Sep 17 00:00:00 2001 From: "DESKTOP-JKIE562\\PC" <1013397054@qq.com> Date: Thu, 4 Jun 2026 13:46:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(xinzeng):=E6=96=B0=E5=A2=9E=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/minio_service.py | 97 ++++++ .../platform-apps/PlatformAppsPage.vue | 328 ++++++++++++++++++ 2 files changed, 425 insertions(+) create mode 100644 backend/app/services/minio_service.py create mode 100644 frontend/src/features/admin/modules/platform-apps/PlatformAppsPage.vue diff --git a/backend/app/services/minio_service.py b/backend/app/services/minio_service.py new file mode 100644 index 00000000..68ef5961 --- /dev/null +++ b/backend/app/services/minio_service.py @@ -0,0 +1,97 @@ +import os +import uuid +from typing import BinaryIO +from minio import Minio +from minio.error import S3Error +from werkzeug.utils import secure_filename +from app.config import config, ACTIVE_ENV_NAME + +cfg = config[ACTIVE_ENV_NAME] + +class MinioService: + def __init__(self): + self.client = Minio( + cfg.MINIO_ENDPOINT, + access_key=cfg.MINIO_ACCESS_KEY, + secret_key=cfg.MINIO_SECRET_KEY, + secure=cfg.MINIO_SECURE, + ) + self.bucket_name = cfg.MINIO_BUCKET_NAME + self._ensure_bucket_exists() + + def _ensure_bucket_exists(self): + try: + if not self.client.bucket_exists(self.bucket_name): + self.client.make_bucket(self.bucket_name) + # Set bucket policy to public read + policy = { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": {"AWS": ["*"]}, + "Action": ["s3:GetObject"], + "Resource": [f"arn:aws:s3:::{self.bucket_name}/*"] + } + ] + } + import json + self.client.set_bucket_policy(self.bucket_name, json.dumps(policy)) + except Exception as e: + # log or print error + print(f"MinIO bucket error (or not reachable): {e}") + + def upload_file(self, file_stream: BinaryIO, filename: str, content_type: str, file_size: int) -> str: + """ + Uploads a file to MinIO and returns the generated object name. + """ + # If MinIO is not running, we could fallback to local storage or raise clear error + try: + self._ensure_bucket_exists() + except Exception: + pass + + ext = os.path.splitext(filename)[1] + unique_filename = f"{uuid.uuid4().hex}{ext}" + + try: + self.client.put_object( + bucket_name=self.bucket_name, + object_name=unique_filename, + data=file_stream, + length=file_size, + content_type=content_type + ) + except Exception as e: + # For development, if minio is down, let's mock it so UI can continue + print(f"Warning: Minio upload failed ({e}). Fallback to local storage.") + + # fallback to local storage + os.makedirs('data/agent-guides', exist_ok=True) + local_path = os.path.join('data/agent-guides', unique_filename) + file_stream.seek(0) + with open(local_path, 'wb') as f: + f.write(file_stream.read()) + + return unique_filename + + def get_public_url(self, object_name: str) -> str: + """ + Returns the public URL for the given object name. + """ + if os.path.exists(os.path.join('data/agent-guides', object_name)): + # It's a local fallback file + # the backend needs a static route to serve this, we'll assume /api/agents/guides/files/ + # but since we want it public without auth: + return f"/api/agents/guides/files/{object_name}" + + base_url = cfg.MINIO_PUBLIC_BASE_URL.rstrip('/') + return f"{base_url}/{self.bucket_name}/{object_name}" + + def delete_file(self, object_name: str): + try: + self.client.remove_object(self.bucket_name, object_name) + except S3Error as e: + print(f"Error deleting file from MinIO: {e}") + +minio_service = MinioService() diff --git a/frontend/src/features/admin/modules/platform-apps/PlatformAppsPage.vue b/frontend/src/features/admin/modules/platform-apps/PlatformAppsPage.vue new file mode 100644 index 00000000..bc34c888 --- /dev/null +++ b/frontend/src/features/admin/modules/platform-apps/PlatformAppsPage.vue @@ -0,0 +1,328 @@ + + + From 6fed283e4c126ca3ce1d74354fbf7e2b64601269 Mon Sep 17 00:00:00 2001 From: "DESKTOP-JKIE562\\PC" <1013397054@qq.com> Date: Thu, 4 Jun 2026 13:49:46 +0800 Subject: [PATCH 2/2] add --- ...a3b4c5_repair_schema_drift_indexes_and_.py | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 backend/migrations/versions/d0e1f2a3b4c5_repair_schema_drift_indexes_and_.py diff --git a/backend/migrations/versions/d0e1f2a3b4c5_repair_schema_drift_indexes_and_.py b/backend/migrations/versions/d0e1f2a3b4c5_repair_schema_drift_indexes_and_.py new file mode 100644 index 00000000..42ff33e8 --- /dev/null +++ b/backend/migrations/versions/d0e1f2a3b4c5_repair_schema_drift_indexes_and_.py @@ -0,0 +1,52 @@ +"""repair schema drift indexes and constraints + +Revision ID: d0e1f2a3b4c5 +Revises: c9d8e7f6a5b4 +Create Date: 2026-06-03 12:00:00.000000 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'd0e1f2a3b4c5' +down_revision = 'c9d8e7f6a5b4' +branch_labels = None +depends_on = None + + +def upgrade(): + op.create_index('ix_kb_documents_group_id', 'kb_documents', ['group_id'], unique=False) + op.create_index( + 'ix_kb_document_versions_document_id', + 'kb_document_versions', + ['document_id'], + unique=False, + ) + op.create_index('ix_schedule_tasks_last_run_at', 'schedule_tasks', ['last_run_at'], unique=False) + op.create_index('ix_schedule_tasks_created_at', 'schedule_tasks', ['created_at'], unique=False) + + op.execute("UPDATE schedule_runs SET wecom_notified = false WHERE wecom_notified IS NULL") + op.alter_column( + 'schedule_runs', + 'wecom_notified', + existing_type=sa.Boolean(), + nullable=False, + existing_server_default=sa.text('false'), + ) + + +def downgrade(): + op.alter_column( + 'schedule_runs', + 'wecom_notified', + existing_type=sa.Boolean(), + nullable=True, + existing_server_default=sa.text('false'), + ) + + op.drop_index('ix_schedule_tasks_created_at', table_name='schedule_tasks') + op.drop_index('ix_schedule_tasks_last_run_at', table_name='schedule_tasks') + op.drop_index('ix_kb_document_versions_document_id', table_name='kb_document_versions') + op.drop_index('ix_kb_documents_group_id', table_name='kb_documents')