From 562c1de0c969d9e01d87d7917f5d704dfc236195 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 28 Jun 2025 08:43:09 +0800 Subject: [PATCH] aList => OpenList --- app/core/cache.py | 8 +-- app/modules/filemanager/storages/alist.py | 60 +++++++++++------------ database/versions/3891a5e722a1_2_1_7.py | 37 ++++++++++++++ 3 files changed, 71 insertions(+), 34 deletions(-) create mode 100644 database/versions/3891a5e722a1_2_1_7.py diff --git a/app/core/cache.py b/app/core/cache.py index 547e580c..c5a12b97 100644 --- a/app/core/cache.py +++ b/app/core/cache.py @@ -131,7 +131,7 @@ class CacheToolsBackend(CacheBackend): - 不支持按 `key` 独立隔离 TTL 和 Maxsize,仅支持作用于 region 级别 """ - def __init__(self, maxsize: Optional[int] = 1000, ttl: Optional[int] = 1800): + def __init__(self, maxsize: Optional[int] = 512, ttl: Optional[int] = 1800): """ 初始化缓存实例 @@ -454,7 +454,7 @@ class RedisBackend(CacheBackend): self.client.close() -def get_cache_backend(maxsize: Optional[int] = 1000, ttl: Optional[int] = 1800) -> CacheBackend: +def get_cache_backend(maxsize: Optional[int] = 512, ttl: Optional[int] = 1800) -> CacheBackend: """ 根据配置获取缓存后端实例 @@ -482,13 +482,13 @@ def get_cache_backend(maxsize: Optional[int] = 1000, ttl: Optional[int] = 1800) return CacheToolsBackend(maxsize=maxsize, ttl=ttl) -def cached(region: Optional[str] = None, maxsize: Optional[int] = 1000, ttl: Optional[int] = 1800, +def cached(region: Optional[str] = None, maxsize: Optional[int] = 512, ttl: Optional[int] = 1800, skip_none: Optional[bool] = True, skip_empty: Optional[bool] = False): """ 自定义缓存装饰器,支持为每个 key 动态传递 maxsize 和 ttl :param region: 缓存的区 - :param maxsize: 缓存的最大条目数,默认值为 1000 + :param maxsize: 缓存的最大条目数,默认值为 512 :param ttl: 缓存的存活时间,单位秒,默认值为 1800 :param skip_none: 跳过 None 缓存,默认为 True :param skip_empty: 跳过空值缓存(如 None, [], {}, "", set()),默认为 False diff --git a/app/modules/filemanager/storages/alist.py b/app/modules/filemanager/storages/alist.py index e23e6f24..76bdd7df 100644 --- a/app/modules/filemanager/storages/alist.py +++ b/app/modules/filemanager/storages/alist.py @@ -19,7 +19,7 @@ from app.utils.url import UrlUtils class Alist(StorageBase, metaclass=Singleton): """ Alist相关操作 - api文档:https://alist.nn.ci/zh/guide/api + api文档:https://oplist.org/zh/ """ # 存储类型 @@ -101,20 +101,20 @@ class Alist(StorageBase, metaclass=Singleton): """ if resp is None: - logger.warning("【alist】请求登录失败,无法连接alist服务") + logger.warning("【OpenList】请求登录失败,无法连接alist服务") return "" if resp.status_code != 200: - logger.warning(f"【alist】更新令牌请求发送失败,状态码:{resp.status_code}") + logger.warning(f"【OpenList】更新令牌请求发送失败,状态码:{resp.status_code}") return "" result = resp.json() if result["code"] != 200: - logger.critical(f'【alist】更新令牌,错误信息:{result["message"]}') + logger.critical(f'【OpenList】更新令牌,错误信息:{result["message"]}') return "" - logger.debug("【alist】AList获取令牌成功") + logger.debug("【OpenList】AList获取令牌成功") return result["data"]["token"] def __get_header_with_token(self) -> dict: @@ -199,11 +199,11 @@ class Alist(StorageBase, metaclass=Singleton): """ if resp is None: - logger.warn(f"【alist】请求获取目录 {fileitem.path} 的文件列表失败,无法连接alist服务") + logger.warn(f"【OpenList】请求获取目录 {fileitem.path} 的文件列表失败,无法连接alist服务") return [] if resp.status_code != 200: logger.warn( - f"【alist】请求获取目录 {fileitem.path} 的文件列表失败,状态码:{resp.status_code}" + f"【OpenList】请求获取目录 {fileitem.path} 的文件列表失败,状态码:{resp.status_code}" ) return [] @@ -211,7 +211,7 @@ class Alist(StorageBase, metaclass=Singleton): if result["code"] != 200: logger.warn( - f'【alist】获取目录 {fileitem.path} 的文件列表失败,错误信息:{result["message"]}' + f'【OpenList】获取目录 {fileitem.path} 的文件列表失败,错误信息:{result["message"]}' ) return [] @@ -257,15 +257,15 @@ class Alist(StorageBase, metaclass=Singleton): } """ if resp is None: - logger.warn(f"【alist】请求创建目录 {path} 失败,无法连接alist服务") + logger.warn(f"【OpenList】请求创建目录 {path} 失败,无法连接alist服务") return None if resp.status_code != 200: - logger.warn(f"【alist】请求创建目录 {path} 失败,状态码:{resp.status_code}") + logger.warn(f"【OpenList】请求创建目录 {path} 失败,状态码:{resp.status_code}") return None result = resp.json() if result["code"] != 200: - logger.warn(f'【alist】创建目录 {path} 失败,错误信息:{result["message"]}') + logger.warn(f'【OpenList】创建目录 {path} 失败,错误信息:{result["message"]}') return None return self.get_item(path) @@ -347,15 +347,15 @@ class Alist(StorageBase, metaclass=Singleton): } """ if resp is None: - logger.warn(f"【alist】请求获取文件 {path} 失败,无法连接alist服务") + logger.warn(f"【OpenList】请求获取文件 {path} 失败,无法连接alist服务") return None if resp.status_code != 200: - logger.warn(f"【alist】请求获取文件 {path} 失败,状态码:{resp.status_code}") + logger.warn(f"【OpenList】请求获取文件 {path} 失败,状态码:{resp.status_code}") return None result = resp.json() if result["code"] != 200: - logger.debug(f'【alist】获取文件 {path} 失败,错误信息:{result["message"]}') + logger.debug(f'【OpenList】获取文件 {path} 失败,错误信息:{result["message"]}') return None return schemas.FileItem( @@ -404,18 +404,18 @@ class Alist(StorageBase, metaclass=Singleton): } """ if resp is None: - logger.warn(f"【alist】请求删除文件 {fileitem.path} 失败,无法连接alist服务") + logger.warn(f"【OpenList】请求删除文件 {fileitem.path} 失败,无法连接alist服务") return False if resp.status_code != 200: logger.warn( - f"【alist】请求删除文件 {fileitem.path} 失败,状态码:{resp.status_code}" + f"【OpenList】请求删除文件 {fileitem.path} 失败,状态码:{resp.status_code}" ) return False result = resp.json() if result["code"] != 200: logger.warn( - f'【alist】删除文件 {fileitem.path} 失败,错误信息:{result["message"]}' + f'【OpenList】删除文件 {fileitem.path} 失败,错误信息:{result["message"]}' ) return False return True @@ -446,18 +446,18 @@ class Alist(StorageBase, metaclass=Singleton): } """ if not resp: - logger.warn(f"【alist】请求重命名文件 {fileitem.path} 失败,无法连接alist服务") + logger.warn(f"【OpenList】请求重命名文件 {fileitem.path} 失败,无法连接alist服务") return False if resp.status_code != 200: logger.warn( - f"【alist】请求重命名文件 {fileitem.path} 失败,状态码:{resp.status_code}" + f"【OpenList】请求重命名文件 {fileitem.path} 失败,状态码:{resp.status_code}" ) return False result = resp.json() if result["code"] != 200: logger.warn( - f'【alist】重命名文件 {fileitem.path} 失败,错误信息:{result["message"]}' + f'【OpenList】重命名文件 {fileitem.path} 失败,错误信息:{result["message"]}' ) return False @@ -511,15 +511,15 @@ class Alist(StorageBase, metaclass=Singleton): } """ if not resp: - logger.warn(f"【alist】请求获取文件 {path} 失败,无法连接alist服务") + logger.warn(f"【OpenList】请求获取文件 {path} 失败,无法连接alist服务") return None if resp.status_code != 200: - logger.warn(f"【alist】请求获取文件 {path} 失败,状态码:{resp.status_code}") + logger.warn(f"【OpenList】请求获取文件 {path} 失败,状态码:{resp.status_code}") return None result = resp.json() if result["code"] != 200: - logger.warn(f'【alist】获取文件 {path} 失败,错误信息:{result["message"]}') + logger.warn(f'【OpenList】获取文件 {path} 失败,错误信息:{result["message"]}') return None if result["data"]["raw_url"]: @@ -566,7 +566,7 @@ class Alist(StorageBase, metaclass=Singleton): ) if resp.status_code != 200: - logger.warn(f"【alist】请求上传文件 {path} 失败,状态码:{resp.status_code}") + logger.warn(f"【OpenList】请求上传文件 {path} 失败,状态码:{resp.status_code}") return None new_item = self.get_item(Path(fileitem.path) / path.name) @@ -616,19 +616,19 @@ class Alist(StorageBase, metaclass=Singleton): """ if resp is None: logger.warn( - f"【alist】请求复制文件 {fileitem.path} 失败,无法连接alist服务" + f"【OpenList】请求复制文件 {fileitem.path} 失败,无法连接alist服务" ) return False if resp.status_code != 200: logger.warn( - f"【alist】请求复制文件 {fileitem.path} 失败,状态码:{resp.status_code}" + f"【OpenList】请求复制文件 {fileitem.path} 失败,状态码:{resp.status_code}" ) return False result = resp.json() if result["code"] != 200: logger.warn( - f'【alist】复制文件 {fileitem.path} 失败,错误信息:{result["message"]}' + f'【OpenList】复制文件 {fileitem.path} 失败,错误信息:{result["message"]}' ) return False # 重命名 @@ -675,19 +675,19 @@ class Alist(StorageBase, metaclass=Singleton): """ if resp is None: logger.warn( - f"【alist】请求移动文件 {fileitem.path} 失败,无法连接alist服务" + f"【OpenList】请求移动文件 {fileitem.path} 失败,无法连接alist服务" ) return False if resp.status_code != 200: logger.warn( - f"【alist】请求移动文件 {fileitem.path} 失败,状态码:{resp.status_code}" + f"【OpenList】请求移动文件 {fileitem.path} 失败,状态码:{resp.status_code}" ) return False result = resp.json() if result["code"] != 200: logger.warn( - f'【alist】移动文件 {fileitem.path} 失败,错误信息:{result["message"]}' + f'【OpenList】移动文件 {fileitem.path} 失败,错误信息:{result["message"]}' ) return False return True diff --git a/database/versions/3891a5e722a1_2_1_7.py b/database/versions/3891a5e722a1_2_1_7.py new file mode 100644 index 00000000..c3989a68 --- /dev/null +++ b/database/versions/3891a5e722a1_2_1_7.py @@ -0,0 +1,37 @@ +"""2.1.7 + +Revision ID: 3891a5e722a1 +Revises: 3df653756eec +Create Date: 2025-06-28 08:40:14.516836 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import sqlite + +from app.db.systemconfig_oper import SystemConfigOper +from app.schemas.types import SystemConfigKey + +# revision identifiers, used by Alembic. +revision = '3891a5e722a1' +down_revision = '3df653756eec' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + # rename AList存储 + _systemconfig = SystemConfigOper() + _storages = _systemconfig.get(SystemConfigKey.Storages) + if _storages: + for storage in _storages: + if storage["type"] == "alist": + storage["name"] = "OpenList" + break + _systemconfig.set(SystemConfigKey.Storages, _storages) + # ### end Alembic commands ### + + +def downgrade() -> None: + pass