更新文件: webdav_simulator.amd64, webdav_simulator.exe, webdav_simulator.py
This commit is contained in:
Binary file not shown.
Binary file not shown.
@ -31,6 +31,8 @@ import json
|
||||
import traceback
|
||||
import time
|
||||
|
||||
from functools import lru_cache
|
||||
|
||||
def convert_path(webdav_path: str) -> str:
|
||||
return f"/{webdav_path.replace('/dav','',1)}"
|
||||
|
||||
@ -97,38 +99,13 @@ class VirtualFSProvider(DAVProvider):
|
||||
self.root_node = root_node
|
||||
self.alist_config = alist_config
|
||||
self.sort_reverse = sort_reverse
|
||||
|
||||
def get_resource_inst(self, path, environ):
|
||||
if path == '/':
|
||||
return VirtualResource('/', self.root_node, environ, self.alist_config, sort_reverse=self.sort_reverse)
|
||||
parts = [p for p in path.strip('/').split('/') if p]
|
||||
current = self.root_node
|
||||
for part in parts:
|
||||
if part in current.children:
|
||||
current = current.children[part]
|
||||
else:
|
||||
return None
|
||||
return VirtualResource(path, current, environ, self.alist_config, sort_reverse=self.sort_reverse)
|
||||
|
||||
def custom_request_handler(self, environ, start_response, default_handler):
|
||||
"""Optionally implement custom request handling.
|
||||
|
||||
requestmethod = environ["REQUEST_METHOD"]
|
||||
Either
|
||||
|
||||
- handle the request completely
|
||||
- do additional processing and call default_handler(environ, start_response)
|
||||
"""
|
||||
requestmethod = environ["REQUEST_METHOD"]
|
||||
path = environ["PATH_INFO"]
|
||||
if requestmethod == "GET" and not path.endswith('/') and len(path.split('/'))>2:
|
||||
serverlist=list()
|
||||
self.serverlist=list()
|
||||
if self.alist_config["config"] == "":
|
||||
if self.alist_config["api_url"] != "":
|
||||
api_url = self.alist_config["api_url"]
|
||||
if api_url.endswith("/"):
|
||||
api_url = api_url[:-1]
|
||||
serverlist.append({"api_url":api_url,"token":self.alist_config["token"],"prefix":self.alist_config["prefix"]})
|
||||
self.serverlist.append({"api_url":api_url,"token":self.alist_config["token"],"prefix":self.alist_config["prefix"]})
|
||||
else:
|
||||
# 解析配置
|
||||
config_list = self.alist_config["config"].split("#")
|
||||
@ -143,9 +120,23 @@ class VirtualFSProvider(DAVProvider):
|
||||
api_url = config[0]
|
||||
if api_url.endswith("/"):
|
||||
api_url = api_url[:-1]
|
||||
serverlist.append({"api_url":api_url,"token":config[1],"prefix":config[2]})
|
||||
self.serverlist.append({"api_url":api_url,"token":config[1],"prefix":config[2]})
|
||||
|
||||
for server in serverlist:
|
||||
def get_resource_inst(self, path, environ):
|
||||
if path == '/':
|
||||
return VirtualResource('/', self.root_node, environ, self.alist_config, sort_reverse=self.sort_reverse)
|
||||
parts = [p for p in path.strip('/').split('/') if p]
|
||||
current = self.root_node
|
||||
for part in parts:
|
||||
if part in current.children:
|
||||
current = current.children[part]
|
||||
else:
|
||||
return None
|
||||
return VirtualResource(path, current, environ, self.alist_config, sort_reverse=self.sort_reverse)
|
||||
|
||||
@lru_cache(maxsize=1024, typed=True)
|
||||
def get_redirect_url(self, path):
|
||||
for server in self.serverlist:
|
||||
print("server:",server)
|
||||
pathsegs=path.split('/')
|
||||
pathlist=set()
|
||||
@ -178,14 +169,35 @@ class VirtualFSProvider(DAVProvider):
|
||||
# 获取 raw_url
|
||||
raw_url = data_dict['data']['raw_url']
|
||||
if raw_url:
|
||||
print(f"raw_url: {raw_url}")
|
||||
send_redirect(environ, start_response, raw_url)
|
||||
return [b"Redirecting..."]
|
||||
# print(f"raw_url: {raw_url}")
|
||||
# send_redirect(environ, start_response, raw_url)
|
||||
# return [b"Redirecting..."]
|
||||
return raw_url
|
||||
except:
|
||||
traceback.print_exc()
|
||||
time.sleep(3)
|
||||
time.sleep(1)
|
||||
pass
|
||||
time.sleep(3)
|
||||
time.sleep(1)
|
||||
return ""
|
||||
|
||||
|
||||
def custom_request_handler(self, environ, start_response, default_handler):
|
||||
"""Optionally implement custom request handling.
|
||||
|
||||
requestmethod = environ["REQUEST_METHOD"]
|
||||
Either
|
||||
|
||||
- handle the request completely
|
||||
- do additional processing and call default_handler(environ, start_response)
|
||||
"""
|
||||
requestmethod = environ["REQUEST_METHOD"]
|
||||
path = environ["PATH_INFO"]
|
||||
if requestmethod == "GET" and not path.endswith('/') and len(path.split('/'))>2:
|
||||
redirect_url = self.get_redirect_url(path)
|
||||
if redirect_url!="":
|
||||
print(f"redirect_urL:{redirect_url}")
|
||||
send_redirect(environ, start_response, redirect_url)
|
||||
return [b"Redirecting..."]
|
||||
|
||||
return default_handler(environ, start_response)
|
||||
|
||||
|
Reference in New Issue
Block a user