mirror of
https://github.com/wangdage12/Snap.Server.git
synced 2026-02-17 08:52:10 +08:00
添加sentry、新增公告筛选功能
This commit is contained in:
9
app.py
9
app.py
@@ -1,5 +1,14 @@
|
|||||||
from app.init import create_app
|
from app.init import create_app
|
||||||
from app.config_loader import config_loader
|
from app.config_loader import config_loader
|
||||||
|
import sentry_sdk
|
||||||
|
|
||||||
|
sentry_sdk.init(
|
||||||
|
dsn="https://d1cad1d2b442cf8431df3ee4bab925e0@o4507525750521856.ingest.us.sentry.io/4510623668830208",
|
||||||
|
# Add data like request headers and IP for users,
|
||||||
|
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
|
||||||
|
send_default_pii=True,
|
||||||
|
traces_sample_rate=1.0,
|
||||||
|
)
|
||||||
|
|
||||||
# 创建应用实例
|
# 创建应用实例
|
||||||
app = create_app()
|
app = create_app()
|
||||||
|
|||||||
@@ -4,3 +4,4 @@ pycryptodome==3.20.0
|
|||||||
PyJWT==2.10.1
|
PyJWT==2.10.1
|
||||||
pymongo==4.15.5
|
pymongo==4.15.5
|
||||||
Werkzeug==3.1.4
|
Werkzeug==3.1.4
|
||||||
|
sentry-sdk[flask]
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
from flask import Blueprint, jsonify
|
from flask import Blueprint, jsonify, request
|
||||||
from services.announcement_service import get_announcements
|
from services.announcement_service import get_announcements
|
||||||
|
|
||||||
announcement_bp = Blueprint("announcement", __name__)
|
announcement_bp = Blueprint("announcement", __name__)
|
||||||
|
|
||||||
@announcement_bp.route("/List", methods=["POST"])
|
@announcement_bp.route("/List", methods=["POST"])
|
||||||
def list_announcements():
|
def list_announcements():
|
||||||
|
# 获取用户已关闭的公告ID列表,也可能没有请求体
|
||||||
|
request_data = request.get_json(silent=True) or []
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"code": 0,
|
"code": 0,
|
||||||
"message": "OK",
|
"message": "OK",
|
||||||
"data": get_announcements()
|
"data": get_announcements(request_data)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,11 +1,19 @@
|
|||||||
from app.extensions import client
|
from app.extensions import client, logger
|
||||||
from app.config import Config
|
from app.config import Config
|
||||||
|
|
||||||
def get_announcements():
|
def get_announcements(request_data: list):
|
||||||
if Config.ISTEST_MODE:
|
if Config.ISTEST_MODE:
|
||||||
return []
|
return []
|
||||||
|
# 记录请求体到日志,请求体中是用户已关闭的公告ID列表
|
||||||
|
logger.debug("Request body: %s", request_data)
|
||||||
|
|
||||||
announcements = list(client.ht_server.announcement.find({}))
|
announcements = list(client.ht_server.announcement.find({}))
|
||||||
|
result = []
|
||||||
for a in announcements:
|
for a in announcements:
|
||||||
|
# 拷贝并移除 _id 字段,避免 ObjectId 无法序列化
|
||||||
|
a = dict(a)
|
||||||
a.pop('_id', None)
|
a.pop('_id', None)
|
||||||
return announcements
|
# 如果请求体中包含该公告ID,说明用户已关闭该公告,不返回该公告
|
||||||
|
if a.get('Id') not in request_data:
|
||||||
|
result.append(a)
|
||||||
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user