Update app.py
Browse files
app.py
CHANGED
@@ -526,10 +526,37 @@ async def unbanUser(chatId, userId):
|
|
526 |
|
527 |
def webdav_upload(filename, data):
|
528 |
url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}{filename}")
|
|
|
|
|
529 |
try:
|
530 |
-
|
531 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
532 |
print(f"WebDAV 上传成功: {filename}")
|
|
|
533 |
except requests.exceptions.RequestException as e:
|
534 |
print(f"WebDAV 上传失败: {filename}, {e}")
|
535 |
|
|
|
526 |
|
527 |
def webdav_upload(filename, data):
|
528 |
url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}{filename}")
|
529 |
+
headers = {'Content-Type': 'application/json'}
|
530 |
+
|
531 |
try:
|
532 |
+
#尝试创建目录
|
533 |
+
dir_url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}")
|
534 |
+
response = requests.request('MKCOL', dir_url, auth=(WEBDAV_USERNAME, WEBDAV_PASSWORD))
|
535 |
+
if response.status_code == 201:
|
536 |
+
print(f"WebDAV 目录创建成功: {WEBDAV_DIR}")
|
537 |
+
elif response.status_code == 405:
|
538 |
+
print(f"WebDAV 目录已存在: {WEBDAV_DIR}")
|
539 |
+
elif response.status_code != 409:
|
540 |
+
response.raise_for_status()
|
541 |
+
|
542 |
+
# 检查文件是否存在
|
543 |
+
check_response = requests.request('PROPFIND', url, auth=(WEBDAV_USERNAME, WEBDAV_PASSWORD))
|
544 |
+
|
545 |
+
if check_response.status_code == 207:
|
546 |
+
print(f"WebDAV 文件已存在,使用PUT更新: {filename}")
|
547 |
+
response = requests.put(url, auth=(WEBDAV_USERNAME, WEBDAV_PASSWORD), data=json.dumps(data, default=str), headers=headers)
|
548 |
+
response.raise_for_status()
|
549 |
+
else:
|
550 |
+
print(f"WebDAV 文件不存在,使用COPY创建: {filename}")
|
551 |
+
copy_url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}{filename}.tmp")
|
552 |
+
response = requests.put(copy_url, auth=(WEBDAV_USERNAME, WEBDAV_PASSWORD), data=json.dumps(data, default=str), headers=headers)
|
553 |
+
response.raise_for_status()
|
554 |
+
response = requests.request('COPY', copy_url, auth=(WEBDAV_USERNAME, WEBDAV_PASSWORD), headers={'Destination': url})
|
555 |
+
response.raise_for_status()
|
556 |
+
response = requests.request('DELETE', copy_url, auth=(WEBDAV_USERNAME, WEBDAV_PASSWORD))
|
557 |
+
response.raise_for_status()
|
558 |
print(f"WebDAV 上传成功: {filename}")
|
559 |
+
|
560 |
except requests.exceptions.RequestException as e:
|
561 |
print(f"WebDAV 上传失败: {filename}, {e}")
|
562 |
|