Merge branch 'sophie' into dev
This commit is contained in:
commit
550aeb0d6c
22 files changed
+1537
-39
No files matched your search
@@ -0,0 +1,8 @@
|
||||
venv
|
||||
__pycache__
|
||||
*.pyc
|
||||
*.pyo
|
||||
local_test.db
|
||||
.git
|
||||
.vscode
|
||||
tests
|
||||
@@ -2,13 +2,6 @@ FROM python:3.12-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install system dependencies
|
||||
# libpq-dev is required for psycopg2
|
||||
RUN apt-get update && apt-get install -y \
|
||||
gcc \
|
||||
libpq-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Python dependencies
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
+28
-1
@@ -5,10 +5,11 @@ backend/app/__init__.py
|
||||
"""
|
||||
import logging
|
||||
|
||||
from flask import Flask
|
||||
from flask import Flask, jsonify, request
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_migrate import Migrate
|
||||
from flask_cors import CORS
|
||||
from werkzeug.exceptions import HTTPException
|
||||
from app.config import config
|
||||
|
||||
db = SQLAlchemy()
|
||||
@@ -69,4 +70,30 @@ def create_app(config_name='default'):
|
||||
def _sync_persisted_settings():
|
||||
_apply_persisted_settings(app)
|
||||
|
||||
def _should_return_json_error() -> bool:
|
||||
if request.path.startswith('/api/'):
|
||||
return True
|
||||
accepted = request.headers.get('Accept', '')
|
||||
return 'application/json' in accepted.lower()
|
||||
|
||||
@app.errorhandler(HTTPException)
|
||||
def _handle_http_exception(exc: HTTPException):
|
||||
if not _should_return_json_error():
|
||||
return exc
|
||||
message = exc.description or exc.name or 'HTTP error'
|
||||
return jsonify({'error': str(message)}), int(exc.code or 500)
|
||||
|
||||
@app.errorhandler(Exception)
|
||||
def _handle_unexpected_exception(exc: Exception):
|
||||
app.logger.exception(
|
||||
'Unhandled exception on %s %s',
|
||||
request.method,
|
||||
request.path,
|
||||
exc_info=exc,
|
||||
)
|
||||
if not _should_return_json_error():
|
||||
return '<h1><p>Internal Server Error</p></h1>', 500
|
||||
message = str(exc).strip() or 'Internal server error'
|
||||
return jsonify({'error': message}), 500
|
||||
|
||||
return app
|
||||
@@ -1,4 +1,4 @@
|
||||
from flask import Blueprint, request, jsonify, current_app
|
||||
from flask import Blueprint, request, jsonify, current_app
|
||||
from app import db
|
||||
from app.models import User, Agent, QuickQuestion, UserFavoriteAgent, UserDefaultAgent, UserHomepageConfig, Announcement, LoginAudit, WecomCallbackAudit, GeneralFeedback, ChatLog
|
||||
from app.services.wecom_notify import mark_wecom_message_opened, send_wecom_event_message
|
||||
|
||||
@@ -73,7 +73,8 @@ class DevelopmentConfig(Config):
|
||||
SQLALCHEMY_DATABASE_URI = os.getenv(
|
||||
'DATABASE_URL',
|
||||
#'postgresql://postgres:123456@8.152.207.171:5432/hxops_db',
|
||||
'postgresql://postgres:difyai123456@localhost:5432/hxops_db',
|
||||
#'postgresql://postgres:difyai123456@localhost:5432/hxops_db',
|
||||
'postgresql://postgres:123456@localhost:5432/hxops_db',
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ with app.app_context():
|
||||
print(f'id={u.id}, username={u.username}, role={u.role}')
|
||||
|
||||
print()
|
||||
print('=== 各用户对 Agent 3 的会话统计 ===')
|
||||
print('=== 各用户对 Agent 3 的会话统计 ===')
|
||||
for uid in [1, 2, 3, 4, 5]:
|
||||
count = db.session.query(func.count(ChatLog.id)).filter(
|
||||
ChatLog.user_id == uid,
|
||||
|
||||
Reference in new issue
Block a user