Compare commits

...

5 Commits

Author SHA1 Message Date
Cp0204
60cb9ba152 ♻️ 优化插件函数错误/失败返回值
Some checks are pending
Docker Publish / build-and-push (push) Waiting to run
- 提高代码一致性和可读性,避免返回错误类型
2024-11-27 20:21:38 +08:00
Cp0204
a56565e187 添加快捷键支持 CTRL+S 保存,CTRL+R 运行 2024-11-27 19:17:20 +08:00
Cp0204
925144ea79 🐛 修复获取挂载路径失败的错误处理
- 在获取文件列表时添加错误检查
- 如果获取失败,打印错误信息以便调试
2024-11-27 19:07:06 +08:00
Cp0204
0a47d48c60 ♻️ 重构 storage_id_to_path() 逻辑
- 更严谨的 storage_id 格式检查
- 改进错误处理,增加对 QuarkTV 驱动的提示
2024-11-27 18:55:54 +08:00
Cp0204
749d1b7039 🐛 修复 storage_id_to_path() 未匹配返回值 #43
- 在不支持的驱动情况下,确保返回值为 (False, (None, None))
- 提高代码的健壮性和可读性
2024-11-27 16:57:12 +08:00
7 changed files with 136 additions and 96 deletions

View File

@ -288,8 +288,8 @@
</div>
</div>
<div class="bottom-buttons">
<button class="btn btn-success"><i class="bi bi-save"></i> 保存</button>
<button type="button" class="btn btn-primary" @click="runScriptNow()"><i class="bi bi-play-fill"></i> 运行</button>
<button class="btn btn-success" title="CTRL+S"><i class="bi bi-save"></i> 保存</button>
<button type="button" class="btn btn-primary" title="CTRL+R" @click="runScriptNow()"><i class="bi bi-play-fill"></i> 运行</button>
<button type="button" class="btn btn-info" @click="scrollToX(0)" @dblclick="scrollToX()" data-toggle="tooltip" data-placement="top" title="单击回顶,双击到底"><i class="bi bi-chevron-bar-up"></i> 回顶</button>
<a class="btn btn-danger" href="/logout"><i class="bi bi-box-arrow-right"></i> 退出</a>
</div>
@ -432,7 +432,8 @@
mounted() {
this.fetchData();
this.checkNewVersion();
$('[data-toggle="tooltip"]').tooltip()
$('[data-toggle="tooltip"]').tooltip();
document.addEventListener('keydown', this.handleKeyDown);
},
methods: {
checkNewVersion() {
@ -475,6 +476,17 @@
console.error('Error fetching data:', error);
});
},
handleKeyDown(event) {
if (event.ctrlKey || event.metaKey) {
if (event.keyCode === 83 || event.key === 's') {
event.preventDefault();
this.saveConfig();
} else if (event.keyCode === 82 || event.key === 'r') {
event.preventDefault();
this.runScriptNow();
}
}
},
saveConfig() {
axios.post('/update', this.formData)
.then(response => {

View File

@ -62,25 +62,39 @@ class Alist:
return False
def storage_id_to_path(self, storage_id):
storage_mount_path, quark_root_dir = None, None
# 1. 检查是否符合 /aaa:/bbb 格式
match = re.match(r"^(\/[^:]*):(\/[^:]*)$", storage_id)
if match:
return True, (match.group(1), match.group(2))
# 2. 调用 Alist API 获取存储信息
storage_info = self.get_storage_info(storage_id)
if storage_info:
if storage_info["driver"] == "Quark":
addition = json.loads(storage_info["addition"])
# 存储挂载路径
storage_mount_path = storage_info["mount_path"]
# 夸克根文件夹
quark_root_dir = self.get_root_folder_full_path(
addition["cookie"], addition["root_folder_id"]
)
if storage_mount_path and quark_root_dir:
return True, (storage_mount_path, quark_root_dir)
else:
print(f"Alist刷新: 不支持[{storage_info['driver']}]驱动 ❌")
if match := re.match(r"^(\/[^:]*):(\/[^:]*)$", storage_id):
# 存储挂载路径, 夸克根文件夹
storage_mount_path, quark_root_dir = match.group(1), match.group(2)
file_list = self.get_file_list(storage_mount_path)
if file_list.get("code") != 200:
print(f"Alist刷新: 获取挂载路径失败❌ {file_list.get('message')}")
return False, (None, None)
# 2. 检查是否数字,调用 Alist API 获取存储信息
elif re.match(r"^\d+$", storage_id):
if storage_info := self.get_storage_info(storage_id):
if storage_info["driver"] == "Quark":
addition = json.loads(storage_info["addition"])
# 存储挂载路径
storage_mount_path = storage_info["mount_path"]
# 夸克根文件夹
quark_root_dir = self.get_root_folder_full_path(
addition["cookie"], addition["root_folder_id"]
)
elif storage_info["driver"] == "QuarkTV":
print(
f"Alist刷新: [QuarkTV]驱动⚠️ storage_id请手动填入 /Alist挂载路径:/Quark目录路径"
)
else:
print(f"Alist刷新: 不支持[{storage_info['driver']}]驱动 ❌")
else:
print(f"Alist刷新: storage_id[{storage_id}]格式错误❌")
# 返回结果
if storage_mount_path and quark_root_dir:
return True, (storage_mount_path, quark_root_dir)
else:
return False, (None, None)
def get_storage_info(self, storage_id):
url = f"{self.url}/api/admin/storage/get"
@ -96,9 +110,27 @@ class Alist:
print(f"Alist刷新: 存储{storage_id}连接失败❌ {data.get('message')}")
except requests.exceptions.RequestException as e:
print(f"Alist刷新: 获取Alist存储出错 {e}")
return False
return []
def refresh(self, path, force_refresh=True):
def refresh(self, path):
data = self.get_file_list(path, True)
if data.get("code") == 200:
print(f"📁 Alist刷新目录[{path}] 成功✅")
return data.get("data")
elif "object not found" in data.get("message", ""):
# 如果是根目录就不再往上查找
if path == "/" or path == self.storage_mount_path:
print(f"📁 Alist刷新根目录不存在请检查 Alist 配置")
return False
# 获取父目录
parent_path = os.path.dirname(path)
print(f"📁 Alist刷新[{path}] 不存在,转父目录 [{parent_path}]")
# 递归刷新父目录
return self.refresh(parent_path)
else:
print(f"📁 Alist刷新失败❌ {data.get('message')}")
def get_file_list(self, path, force_refresh=False):
url = f"{self.url}/api/fs/list"
headers = {"Authorization": self.token}
payload = {
@ -111,25 +143,10 @@ class Alist:
try:
response = requests.request("POST", url, headers=headers, json=payload)
response.raise_for_status()
data = response.json()
if data.get("code") == 200:
print(f"📁 Alist刷新目录[{path}] 成功✅")
return data.get("data")
elif "object not found" in data.get("message", ""):
# 如果是根目录就不再往上查找
if path == "/" or path == self.storage_mount_path:
print(f"📁 Alist刷新根目录不存在请检查 Alist 配置")
return False
# 获取父目录
parent_path = os.path.dirname(path)
print(f"📁 Alist刷新[{path}] 不存在,转父目录 [{parent_path}]")
# 递归刷新父目录
return self.refresh(parent_path)
else:
print(f"📁 Alist刷新失败❌ {data.get('message')}")
except requests.exceptions.RequestException as e:
print(f"Alist刷新目录出错: {e}")
return False
return response.json()
except Exception as e:
print(f"📁 Alist刷新: 获取文件列表出错❌ {e}")
return {}
def get_root_folder_full_path(self, cookie, pdir_fid):
if pdir_fid == "0":
@ -162,4 +179,4 @@ class Alist:
return "/".join(file_names)
except requests.exceptions.RequestException as e:
print(f"Alist刷新: 获取Quark路径出错 {e}")
return False
return ""

View File

@ -61,8 +61,8 @@ class Alist_strm:
try:
selected_configs = [int(x.strip()) for x in selected_configs_str.split(",")]
except ValueError:
print("Error: 运行alist-strm配置错误id应以,分割")
return None
print("🔗 alist-strm配置运行: 出错❌ id应以,分割")
return False
data = [("selected_configs", config_id) for config_id in selected_configs]
data.append(("action", "run_selected"))
try:

View File

@ -72,28 +72,43 @@ class Alist_strm_gen:
task["savepath"].replace(self.quark_root_dir, "", 1).lstrip("/"),
)
).replace("\\", "/")
self.refresh(alist_path)
self.check_dir(alist_path)
def storage_id_to_path(self, storage_id):
storage_mount_path, quark_root_dir = None, None
# 1. 检查是否符合 /aaa:/bbb 格式
match = re.match(r"^(\/[^:]*):(\/[^:]*)$", storage_id)
if match:
return True, (match.group(1), match.group(2))
# 2. 调用 Alist API 获取存储信息
storage_info = self.get_storage_info(storage_id)
if storage_info:
if storage_info["driver"] == "Quark":
addition = json.loads(storage_info["addition"])
# 存储挂载路径
storage_mount_path = storage_info["mount_path"]
# 夸克根文件夹
quark_root_dir = self.get_root_folder_full_path(
addition["cookie"], addition["root_folder_id"]
)
if storage_mount_path and quark_root_dir:
return True, (storage_mount_path, quark_root_dir)
else:
print(f"Alist刷新: 不支持[{storage_info['driver']}]驱动 ❌")
if match := re.match(r"^(\/[^:]*):(\/[^:]*)$", storage_id):
# 存储挂载路径, 夸克根文件夹
storage_mount_path, quark_root_dir = match.group(1), match.group(2)
file_list = self.get_file_list(storage_mount_path)
if file_list.get("code") != 200:
print(f"Alist-Strm生成: 获取挂载路径失败❌ {file_list.get('message')}")
return False, (None, None)
# 2. 检查是否数字,调用 Alist API 获取存储信息
elif re.match(r"^\d+$", storage_id):
if storage_info := self.get_storage_info(storage_id):
if storage_info["driver"] == "Quark":
addition = json.loads(storage_info["addition"])
# 存储挂载路径
storage_mount_path = storage_info["mount_path"]
# 夸克根文件夹
quark_root_dir = self.get_root_folder_full_path(
addition["cookie"], addition["root_folder_id"]
)
elif storage_info["driver"] == "QuarkTV":
print(
f"Alist-Strm生成: [QuarkTV]驱动⚠️ storage_id请手动填入 /Alist挂载路径:/Quark目录路径"
)
else:
print(f"Alist-Strm生成: 不支持[{storage_info['driver']}]驱动 ❌")
else:
print(f"Alist-Strm生成: storage_id[{storage_id}]格式错误❌")
# 返回结果
if storage_mount_path and quark_root_dir:
print(f"Alist-Strm生成: [{storage_mount_path}:{quark_root_dir}]")
return True, (storage_mount_path, quark_root_dir)
else:
return False, (None, None)
def get_storage_info(self, storage_id):
url = f"{self.url}/api/admin/storage/get"
@ -104,46 +119,43 @@ class Alist_strm_gen:
response.raise_for_status()
data = response.json()
if data.get("code") == 200:
print(
f"Alist-Strm生成: {data['data']['driver']}[{data['data']['mount_path']}]"
)
return data.get("data", [])
else:
print(f"Alist-Strm生成: 连接失败❌ {response.get('message')}")
print(f"Alist-Strm生成: 获取存储失败❌ {data.get('message')}")
except requests.exceptions.RequestException as e:
print(f"Alist-Strm生成: 获取Alist存储出错 {e}")
print(f"Alist-Strm生成: 获取存储出错 {e}")
return False
def refresh(self, path):
try:
response = self.get_file_list(path)
if response.get("code") != 200:
print(f"📺 生成 STRM 文件失败❌ {response.get('message')}")
return
else:
files = response.get("data").get("content")
for item in files:
item_path = f"{path}/{item.get('name')}".replace("//", "/")
if item.get("is_dir"):
self.refresh(item_path)
else:
self.generate_strm(item_path)
except Exception as e:
print(f"📺 获取 Alist 文件列表失败❌ {e}")
def check_dir(self, path):
data = self.get_file_list(path)
if data.get("code") != 200:
print(f"📺 Alist-Strm生成: 获取文件列表失败❌{data.get('message')}")
return
elif files := data.get("data", {}).get("content"):
for item in files:
item_path = f"{path}/{item.get('name')}".replace("//", "/")
if item.get("is_dir"):
self.check_dir(item_path)
else:
self.generate_strm(item_path)
def get_file_list(self, path):
def get_file_list(self, path, force_refresh=False):
url = f"{self.url}/api/fs/list"
headers = {"Authorization": self.token}
payload = {
"path": path,
"refresh": False,
"refresh": force_refresh,
"password": "",
"page": 1,
"per_page": 0,
}
response = requests.request("POST", url, headers=headers, json=payload)
response.raise_for_status()
return response.json()
try:
response = requests.request("POST", url, headers=headers, json=payload)
response.raise_for_status()
return response.json()
except Exception as e:
print(f"📺 Alist-Strm生成: 获取文件列表出错❌ {e}")
return False
def generate_strm(self, file_path):
ext = file_path.split(".")[-1]

View File

@ -76,7 +76,7 @@ class Aria2:
return response.json()
except requests.exceptions.RequestException as e:
print(f"Aria2下载: 错误{e}")
return None
return {}
def get_version(self):
"""检查与 Aria2 的连接."""
@ -91,4 +91,4 @@ class Aria2:
def add_uri(self, params=None):
"""添加 URI 下载任务."""
response = self._make_rpc_request("aria2.addUri", params)
return response.get("result") if response else None
return response.get("result") if response else {}

View File

@ -84,7 +84,7 @@ class Emby:
def search(self, media_name):
if not media_name:
return False
return ""
url = f"{self.url}/emby/Items"
headers = {"X-Emby-Token": self.token}
querystring = {
@ -113,4 +113,4 @@ class Emby:
print(f"🎞️ 搜索Emby媒体库{response.text}")
except requests.exceptions.RequestException as e:
print(f"搜索Emby媒体库出错: {e}")
return False
return ""

View File

@ -90,7 +90,6 @@ class Plex:
return libraries
else:
print(f"🎞️ 获取Plex媒体库信息失败❌ 状态码:{response.status_code}")
return None
except Exception as e:
print(f"获取Plex媒体库信息出错: {e}")
return None
return []