aList => OpenList

This commit is contained in:
jxxghp
2025-06-28 08:43:09 +08:00
parent e2c90639f3
commit 562c1de0c9
3 changed files with 71 additions and 34 deletions
+4 -4
View File
@@ -131,7 +131,7 @@ class CacheToolsBackend(CacheBackend):
- 不支持按 `key` 独立隔离 TTL 和 Maxsize,仅支持作用于 region 级别 - 不支持按 `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() 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) 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): skip_none: Optional[bool] = True, skip_empty: Optional[bool] = False):
""" """
自定义缓存装饰器,支持为每个 key 动态传递 maxsize 和 ttl 自定义缓存装饰器,支持为每个 key 动态传递 maxsize 和 ttl
:param region: 缓存的区 :param region: 缓存的区
:param maxsize: 缓存的最大条目数,默认值为 1000 :param maxsize: 缓存的最大条目数,默认值为 512
:param ttl: 缓存的存活时间,单位秒,默认值为 1800 :param ttl: 缓存的存活时间,单位秒,默认值为 1800
:param skip_none: 跳过 None 缓存,默认为 True :param skip_none: 跳过 None 缓存,默认为 True
:param skip_empty: 跳过空值缓存(如 None, [], {}, "", set()),默认为 False :param skip_empty: 跳过空值缓存(如 None, [], {}, "", set()),默认为 False
+30 -30
View File
@@ -19,7 +19,7 @@ from app.utils.url import UrlUtils
class Alist(StorageBase, metaclass=Singleton): class Alist(StorageBase, metaclass=Singleton):
""" """
Alist相关操作 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: if resp is None:
logger.warning("alist】请求登录失败,无法连接alist服务") logger.warning("OpenList】请求登录失败,无法连接alist服务")
return "" return ""
if resp.status_code != 200: if resp.status_code != 200:
logger.warning(f"alist】更新令牌请求发送失败,状态码:{resp.status_code}") logger.warning(f"OpenList】更新令牌请求发送失败,状态码:{resp.status_code}")
return "" return ""
result = resp.json() result = resp.json()
if result["code"] != 200: if result["code"] != 200:
logger.critical(f'alist】更新令牌,错误信息:{result["message"]}') logger.critical(f'OpenList】更新令牌,错误信息:{result["message"]}')
return "" return ""
logger.debug("alist】AList获取令牌成功") logger.debug("OpenList】AList获取令牌成功")
return result["data"]["token"] return result["data"]["token"]
def __get_header_with_token(self) -> dict: def __get_header_with_token(self) -> dict:
@@ -199,11 +199,11 @@ class Alist(StorageBase, metaclass=Singleton):
""" """
if resp is None: if resp is None:
logger.warn(f"alist】请求获取目录 {fileitem.path} 的文件列表失败,无法连接alist服务") logger.warn(f"OpenList】请求获取目录 {fileitem.path} 的文件列表失败,无法连接alist服务")
return [] return []
if resp.status_code != 200: if resp.status_code != 200:
logger.warn( logger.warn(
f"alist】请求获取目录 {fileitem.path} 的文件列表失败,状态码:{resp.status_code}" f"OpenList】请求获取目录 {fileitem.path} 的文件列表失败,状态码:{resp.status_code}"
) )
return [] return []
@@ -211,7 +211,7 @@ class Alist(StorageBase, metaclass=Singleton):
if result["code"] != 200: if result["code"] != 200:
logger.warn( logger.warn(
f'alist】获取目录 {fileitem.path} 的文件列表失败,错误信息:{result["message"]}' f'OpenList】获取目录 {fileitem.path} 的文件列表失败,错误信息:{result["message"]}'
) )
return [] return []
@@ -257,15 +257,15 @@ class Alist(StorageBase, metaclass=Singleton):
} }
""" """
if resp is None: if resp is None:
logger.warn(f"alist】请求创建目录 {path} 失败,无法连接alist服务") logger.warn(f"OpenList】请求创建目录 {path} 失败,无法连接alist服务")
return None return None
if resp.status_code != 200: if resp.status_code != 200:
logger.warn(f"alist】请求创建目录 {path} 失败,状态码:{resp.status_code}") logger.warn(f"OpenList】请求创建目录 {path} 失败,状态码:{resp.status_code}")
return None return None
result = resp.json() result = resp.json()
if result["code"] != 200: if result["code"] != 200:
logger.warn(f'alist】创建目录 {path} 失败,错误信息:{result["message"]}') logger.warn(f'OpenList】创建目录 {path} 失败,错误信息:{result["message"]}')
return None return None
return self.get_item(path) return self.get_item(path)
@@ -347,15 +347,15 @@ class Alist(StorageBase, metaclass=Singleton):
} }
""" """
if resp is None: if resp is None:
logger.warn(f"alist】请求获取文件 {path} 失败,无法连接alist服务") logger.warn(f"OpenList】请求获取文件 {path} 失败,无法连接alist服务")
return None return None
if resp.status_code != 200: if resp.status_code != 200:
logger.warn(f"alist】请求获取文件 {path} 失败,状态码:{resp.status_code}") logger.warn(f"OpenList】请求获取文件 {path} 失败,状态码:{resp.status_code}")
return None return None
result = resp.json() result = resp.json()
if result["code"] != 200: if result["code"] != 200:
logger.debug(f'alist】获取文件 {path} 失败,错误信息:{result["message"]}') logger.debug(f'OpenList】获取文件 {path} 失败,错误信息:{result["message"]}')
return None return None
return schemas.FileItem( return schemas.FileItem(
@@ -404,18 +404,18 @@ class Alist(StorageBase, metaclass=Singleton):
} }
""" """
if resp is None: if resp is None:
logger.warn(f"alist】请求删除文件 {fileitem.path} 失败,无法连接alist服务") logger.warn(f"OpenList】请求删除文件 {fileitem.path} 失败,无法连接alist服务")
return False return False
if resp.status_code != 200: if resp.status_code != 200:
logger.warn( logger.warn(
f"alist】请求删除文件 {fileitem.path} 失败,状态码:{resp.status_code}" f"OpenList】请求删除文件 {fileitem.path} 失败,状态码:{resp.status_code}"
) )
return False return False
result = resp.json() result = resp.json()
if result["code"] != 200: if result["code"] != 200:
logger.warn( logger.warn(
f'alist】删除文件 {fileitem.path} 失败,错误信息:{result["message"]}' f'OpenList】删除文件 {fileitem.path} 失败,错误信息:{result["message"]}'
) )
return False return False
return True return True
@@ -446,18 +446,18 @@ class Alist(StorageBase, metaclass=Singleton):
} }
""" """
if not resp: if not resp:
logger.warn(f"alist】请求重命名文件 {fileitem.path} 失败,无法连接alist服务") logger.warn(f"OpenList】请求重命名文件 {fileitem.path} 失败,无法连接alist服务")
return False return False
if resp.status_code != 200: if resp.status_code != 200:
logger.warn( logger.warn(
f"alist】请求重命名文件 {fileitem.path} 失败,状态码:{resp.status_code}" f"OpenList】请求重命名文件 {fileitem.path} 失败,状态码:{resp.status_code}"
) )
return False return False
result = resp.json() result = resp.json()
if result["code"] != 200: if result["code"] != 200:
logger.warn( logger.warn(
f'alist】重命名文件 {fileitem.path} 失败,错误信息:{result["message"]}' f'OpenList】重命名文件 {fileitem.path} 失败,错误信息:{result["message"]}'
) )
return False return False
@@ -511,15 +511,15 @@ class Alist(StorageBase, metaclass=Singleton):
} }
""" """
if not resp: if not resp:
logger.warn(f"alist】请求获取文件 {path} 失败,无法连接alist服务") logger.warn(f"OpenList】请求获取文件 {path} 失败,无法连接alist服务")
return None return None
if resp.status_code != 200: if resp.status_code != 200:
logger.warn(f"alist】请求获取文件 {path} 失败,状态码:{resp.status_code}") logger.warn(f"OpenList】请求获取文件 {path} 失败,状态码:{resp.status_code}")
return None return None
result = resp.json() result = resp.json()
if result["code"] != 200: if result["code"] != 200:
logger.warn(f'alist】获取文件 {path} 失败,错误信息:{result["message"]}') logger.warn(f'OpenList】获取文件 {path} 失败,错误信息:{result["message"]}')
return None return None
if result["data"]["raw_url"]: if result["data"]["raw_url"]:
@@ -566,7 +566,7 @@ class Alist(StorageBase, metaclass=Singleton):
) )
if resp.status_code != 200: if resp.status_code != 200:
logger.warn(f"alist】请求上传文件 {path} 失败,状态码:{resp.status_code}") logger.warn(f"OpenList】请求上传文件 {path} 失败,状态码:{resp.status_code}")
return None return None
new_item = self.get_item(Path(fileitem.path) / path.name) new_item = self.get_item(Path(fileitem.path) / path.name)
@@ -616,19 +616,19 @@ class Alist(StorageBase, metaclass=Singleton):
""" """
if resp is None: if resp is None:
logger.warn( logger.warn(
f"alist】请求复制文件 {fileitem.path} 失败,无法连接alist服务" f"OpenList】请求复制文件 {fileitem.path} 失败,无法连接alist服务"
) )
return False return False
if resp.status_code != 200: if resp.status_code != 200:
logger.warn( logger.warn(
f"alist】请求复制文件 {fileitem.path} 失败,状态码:{resp.status_code}" f"OpenList】请求复制文件 {fileitem.path} 失败,状态码:{resp.status_code}"
) )
return False return False
result = resp.json() result = resp.json()
if result["code"] != 200: if result["code"] != 200:
logger.warn( logger.warn(
f'alist】复制文件 {fileitem.path} 失败,错误信息:{result["message"]}' f'OpenList】复制文件 {fileitem.path} 失败,错误信息:{result["message"]}'
) )
return False return False
# 重命名 # 重命名
@@ -675,19 +675,19 @@ class Alist(StorageBase, metaclass=Singleton):
""" """
if resp is None: if resp is None:
logger.warn( logger.warn(
f"alist】请求移动文件 {fileitem.path} 失败,无法连接alist服务" f"OpenList】请求移动文件 {fileitem.path} 失败,无法连接alist服务"
) )
return False return False
if resp.status_code != 200: if resp.status_code != 200:
logger.warn( logger.warn(
f"alist】请求移动文件 {fileitem.path} 失败,状态码:{resp.status_code}" f"OpenList】请求移动文件 {fileitem.path} 失败,状态码:{resp.status_code}"
) )
return False return False
result = resp.json() result = resp.json()
if result["code"] != 200: if result["code"] != 200:
logger.warn( logger.warn(
f'alist】移动文件 {fileitem.path} 失败,错误信息:{result["message"]}' f'OpenList】移动文件 {fileitem.path} 失败,错误信息:{result["message"]}'
) )
return False return False
return True return True
+37
View File
@@ -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