Update app.py
Browse files
app.py
CHANGED
@@ -525,46 +525,47 @@ async def unbanUser(chatId, userId):
|
|
525 |
await sendTelegramMessage(chatId, f"用户 {userId} 已被解禁。")
|
526 |
print(f"用户 {userId} 在群组 {chatId} 中被解禁。")
|
527 |
|
528 |
-
async def unbanUser(chatId, userId):
|
529 |
-
if userId in BANNED_USERS:
|
530 |
-
del BANNED_USERS[userId]
|
531 |
-
await sendTelegramMessage(chatId, f"用户 {userId} 已被解禁。")
|
532 |
-
print(f"用户 {userId} 在群组 {chatId} 中被解禁。")
|
533 |
-
|
534 |
def webdav_upload(filename, data):
|
535 |
url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}{filename}")
|
536 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
537 |
try:
|
538 |
-
|
539 |
-
|
540 |
-
subprocess.run(['curl', '-X', 'MKCOL', '-u', f'{WEBDAV_USERNAME}:{WEBDAV_PASSWORD}', dir_url], check=True, capture_output=True)
|
541 |
-
print(f"WebDAV 目录创建成功: {WEBDAV_DIR}")
|
542 |
-
except subprocess.CalledProcessError as e:
|
543 |
-
if b'405' in e.stderr:
|
544 |
-
print(f"WebDAV 目录已存在: {WEBDAV_DIR}")
|
545 |
-
else:
|
546 |
-
print(f"WebDAV 目录创建失败: {WEBDAV_DIR}, {e.stderr.decode()}")
|
547 |
-
return
|
548 |
-
|
549 |
-
try:
|
550 |
-
# 上传文件
|
551 |
-
json_data = json.dumps(data, default=str)
|
552 |
-
process = subprocess.run(['curl', '-X', 'PUT', '-u', f'{WEBDAV_USERNAME}:{WEBDAV_PASSWORD}', '-H', 'Content-Type: application/json', '--data', json_data, url], check=True, capture_output=True)
|
553 |
-
print(f"WebDAV 上传成功: {filename}")
|
554 |
except subprocess.CalledProcessError as e:
|
555 |
-
print(f"WebDAV 上传失败: {filename}, {e.stderr.
|
556 |
|
557 |
def webdav_download(filename):
|
558 |
url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}{filename}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
559 |
try:
|
560 |
-
|
561 |
print(f"WebDAV 下载成功: {filename}")
|
562 |
-
|
563 |
-
return json.loads(process.stdout.decode())
|
564 |
-
else:
|
565 |
-
return None
|
566 |
except subprocess.CalledProcessError as e:
|
567 |
-
print(f"WebDAV 下载失败: {filename}, {e.stderr.
|
|
|
|
|
|
|
568 |
return None
|
569 |
|
570 |
def sync_data_to_webdav():
|
|
|
525 |
await sendTelegramMessage(chatId, f"用户 {userId} 已被解禁。")
|
526 |
print(f"用户 {userId} 在群组 {chatId} 中被解禁。")
|
527 |
|
|
|
|
|
|
|
|
|
|
|
|
|
528 |
def webdav_upload(filename, data):
|
529 |
url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}{filename}")
|
530 |
|
531 |
+
# 使用 curl 上传
|
532 |
+
curl_command = [
|
533 |
+
'curl',
|
534 |
+
'-k', # 忽略证书验证
|
535 |
+
'-u', f'{WEBDAV_USERNAME}:{WEBDAV_PASSWORD}',
|
536 |
+
'-X', 'PUT',
|
537 |
+
'-H', 'Content-Type: application/json',
|
538 |
+
'--data', json.dumps(data, default=str),
|
539 |
+
url
|
540 |
+
]
|
541 |
+
|
542 |
try:
|
543 |
+
result = subprocess.run(curl_command, capture_output=True, text=True, check=True)
|
544 |
+
print(f"WebDAV 上传成功: {filename}, {result.stdout.strip()}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
545 |
except subprocess.CalledProcessError as e:
|
546 |
+
print(f"WebDAV 上传失败: {filename}, {e.stderr.strip()}")
|
547 |
|
548 |
def webdav_download(filename):
|
549 |
url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}{filename}")
|
550 |
+
|
551 |
+
# 使用 curl 下载
|
552 |
+
curl_command = [
|
553 |
+
'curl',
|
554 |
+
'-k', # 忽略证书验证
|
555 |
+
'-u', f'{WEBDAV_USERNAME}:{WEBDAV_PASSWORD}',
|
556 |
+
'-H', 'Accept: application/json',
|
557 |
+
url
|
558 |
+
]
|
559 |
+
|
560 |
try:
|
561 |
+
result = subprocess.run(curl_command, capture_output=True, text=True, check=True)
|
562 |
print(f"WebDAV 下载成功: {filename}")
|
563 |
+
return json.loads(result.stdout)
|
|
|
|
|
|
|
564 |
except subprocess.CalledProcessError as e:
|
565 |
+
print(f"WebDAV 下载失败: {filename}, {e.stderr.strip()}")
|
566 |
+
return None
|
567 |
+
except json.JSONDecodeError as e:
|
568 |
+
print(f"WebDAV JSON 解析失败: {filename}, {e}")
|
569 |
return None
|
570 |
|
571 |
def sync_data_to_webdav():
|