20250918-新增主播库功能
This commit is contained in:
@@ -92,6 +92,7 @@ def start_socket_listener():
|
||||
LogManager.error(f"[ERROR]Socket服务启动失败: {e}")
|
||||
print(f"[ERROR]Socket服务启动失败: {e}")
|
||||
|
||||
|
||||
def _handle_conn(conn: socket.socket, addr):
|
||||
try:
|
||||
with conn:
|
||||
@@ -99,16 +100,16 @@ def _handle_conn(conn: socket.socket, addr):
|
||||
buffer = ""
|
||||
while True:
|
||||
data = conn.recv(1024)
|
||||
if not data: # 对端关闭
|
||||
if not data: # 对端关闭
|
||||
break
|
||||
buffer += data.decode('utf-8', errors='ignore')
|
||||
# 2. 尝试切出完整 JSON(简单按行,也可按长度头、分隔符)
|
||||
while True:
|
||||
line, sep, buffer = buffer.partition('\n')
|
||||
if not sep: # 没找到完整行
|
||||
if not sep: # 没找到完整行
|
||||
break
|
||||
line = line.strip()
|
||||
if not line: # 空行跳过
|
||||
if not line: # 空行跳过
|
||||
continue
|
||||
try:
|
||||
obj = json.loads(line)
|
||||
@@ -275,12 +276,14 @@ def stopScript():
|
||||
@app.route('/passAnchorData', methods=['POST'])
|
||||
def passAnchorData():
|
||||
try:
|
||||
LogManager.method_info("关注打招呼","关注打招呼")
|
||||
LogManager.method_info("关注打招呼", "关注打招呼")
|
||||
data: Dict[str, Any] = request.get_json()
|
||||
# 设备列表
|
||||
idList = data.get("deviceList", [])
|
||||
# 主播列表
|
||||
acList = data.get("anchorList", [])
|
||||
LogManager.info(f"[INFO] 获取数据: {idList} {acList}")
|
||||
|
||||
AiUtils.save_aclist_flat_append(acList)
|
||||
|
||||
# 是否需要回复
|
||||
@@ -401,6 +404,70 @@ def queryAnchorList():
|
||||
return ResultData(data=data).toJson()
|
||||
|
||||
|
||||
# 修改当前的主播列表数据
|
||||
|
||||
@app.route("/updateAnchorList", methods=['POST'])
|
||||
def updateAnchorList():
|
||||
"""
|
||||
invitationType: 1 普票 2 金票
|
||||
state: 1 通行(True) / 0 不通行(False)
|
||||
"""
|
||||
data = request.get_json(force=True, silent=True) or {}
|
||||
invitationType = data.get("invitationType")
|
||||
state = bool(data.get("state")) # 转成布尔
|
||||
|
||||
# 要更新成的值
|
||||
new_status = 1 if state else 0
|
||||
|
||||
# 用工具类解析路径,避免 cwd 影响
|
||||
file_path = AiUtils._resolve_path("Module/log/acList.json")
|
||||
|
||||
# 加载 JSON
|
||||
try:
|
||||
doc = json.loads(file_path.read_text(encoding="utf-8-sig"))
|
||||
except Exception as e:
|
||||
LogManager.error(f"[updateAnchorList] 读取失败: {e}")
|
||||
return ResultData(code=500, massage=f"读取失败: {e}").toJson()
|
||||
|
||||
# 定位 anchorList
|
||||
if isinstance(doc, list):
|
||||
acList = doc
|
||||
wrapper = None
|
||||
elif isinstance(doc, dict) and isinstance(doc.get("anchorList"), list):
|
||||
acList = doc["anchorList"]
|
||||
wrapper = doc
|
||||
else:
|
||||
return ResultData(code=500, massage="文件格式不合法").toJson()
|
||||
|
||||
# 遍历并更新
|
||||
updated = 0
|
||||
for item in acList:
|
||||
if isinstance(item, dict) and item.get("invitationType") == invitationType:
|
||||
item["status"] = new_status
|
||||
updated += 1
|
||||
|
||||
# 写回(保持原始结构)
|
||||
try:
|
||||
file_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
to_write = wrapper if wrapper is not None else acList
|
||||
file_path.write_text(json.dumps(to_write, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
except Exception as e:
|
||||
LogManager.error(f"[updateAnchorList] 写入失败: {e}")
|
||||
return ResultData(code=500, massage=f"写入失败: {e}").toJson()
|
||||
|
||||
if updated:
|
||||
return ResultData(data=updated, massage=f"已更新 {updated} 条记录").toJson()
|
||||
else:
|
||||
return ResultData(data=0, massage="未找到符合条件的记录").toJson()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# 删除主播
|
||||
@app.route("/deleteAnchorWithIds", methods=['POST'])
|
||||
def deleteAnchorWithIds():
|
||||
|
||||
Reference in New Issue
Block a user