更新文件: webdav_simulator.amd64, webdav_simulator.exe, webdav_simulator.py
This commit is contained in:
@ -30,6 +30,7 @@ import requests
|
||||
import json
|
||||
import traceback
|
||||
import time
|
||||
import re
|
||||
|
||||
from functools import lru_cache
|
||||
|
||||
@ -100,6 +101,7 @@ class VirtualFSProvider(DAVProvider):
|
||||
self.alist_config = alist_config
|
||||
self.sort_reverse = sort_reverse
|
||||
self.serverlist=list()
|
||||
self.sharedir_re = re.compile(r'我的.*分享')
|
||||
if self.alist_config["config"] == "":
|
||||
if self.alist_config["api_url"] != "":
|
||||
api_url = self.alist_config["api_url"]
|
||||
@ -138,12 +140,46 @@ class VirtualFSProvider(DAVProvider):
|
||||
def get_redirect_url(self, path):
|
||||
for server in self.serverlist:
|
||||
print("server:",server)
|
||||
if not "rootdirmap" in server:
|
||||
server["rootdirmap"]=dict()
|
||||
headers = {
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
|
||||
}
|
||||
if server["token"] != "":
|
||||
headers["Authorization"] = server["token"]
|
||||
alist_path = "/"
|
||||
params = {"path": alist_path}
|
||||
# print("params:",params)
|
||||
resp = requests.get(
|
||||
server["api_url"]+"/api/fs/list",
|
||||
headers=headers,
|
||||
params=params,
|
||||
stream=True
|
||||
)
|
||||
resp.raise_for_status()
|
||||
body = resp.content.decode('utf-8')
|
||||
print(f"detect rootdir alist_api:{server['api_url']}, headers:{headers}, params:{params}, respcode:{resp.status_code}, respbody:{body[:4096]}")
|
||||
try:
|
||||
data_dict = json.loads(body)
|
||||
dirlist = data_dict['data']['content']
|
||||
for dir in dirlist:
|
||||
if True or dir["is_dir"]:
|
||||
dirname=dir["name"]
|
||||
match = self.sharedir_re.findall(dirname)
|
||||
if len(match)>0:
|
||||
server["rootdirmap"][match[0]]=dirname
|
||||
except:
|
||||
traceback.print_exc()
|
||||
pass
|
||||
|
||||
pathsegs=path.split('/')
|
||||
pathlist=set()
|
||||
pathlist.add(path)
|
||||
if "我的115分享" in pathsegs[1]:
|
||||
pathlist.add(path.replace("🏷️我的115分享", "🏷️ 我的115分享"))
|
||||
pathlist.add(path.replace("🏷️ 我的115分享", "🏷️我的115分享"))
|
||||
match=self.sharedir_re.findall(pathsegs[1])
|
||||
if len(match)>0:
|
||||
if match[0] in server["rootdirmap"]:
|
||||
pathlist.add(os.path.join("/",server["rootdirmap"][match[0]],*pathsegs[2:]))
|
||||
else:
|
||||
pathlist.add(path)
|
||||
for tmppath in pathlist:
|
||||
try:
|
||||
headers = {
|
||||
|
Reference in New Issue
Block a user