refactor(config): retire RuntimeSettingsCompat host usage

This commit is contained in:
jxxghp
2026-08-26 15:55:21 +08:00
parent cdab54254d
commit 9dbe424c3d
162 changed files with 1966 additions and 1745 deletions
+10 -12
View File
@@ -8,19 +8,17 @@ from typing import List, Optional, Tuple, Union
import requests
from app.runtime.settings import RuntimeSettingsCompat
from app.runtime.stop import runtime_stop_state
from app.schemas.file import StorageUsage as _SchemaStorageUsage
from app.schemas.workflow import FileItem as _SchemaFileItem
settings = RuntimeSettingsCompat()
from app.adapters.network.http import RequestUtils
from app.foundation import temporal as time_tools
from app.foundation.singleton import WeakSingleton
from app.modules.filemanager.storages import StorageBase, transfer_process
from app.runtime.log import logger
from app.runtime.settings import get_runtime_setting
from app.runtime.stop import runtime_stop_state
from app.schemas.exception import StorageQueryError
from app.schemas.file import StorageUsage as _SchemaStorageUsage
from app.schemas.types import StorageSchema
from app.schemas.workflow import FileItem as _SchemaFileItem
lock = threading.Lock()
@@ -48,7 +46,7 @@ class AliPan(StorageBase, metaclass=WeakSingleton):
base_url = "https://openapi.alipan.com"
# 阿里云盘目录时间不随子文件变更而更新,默认关闭目录修改时间检查
snapshot_check_folder_modtime = settings.ALIPAN_SNAPSHOT_CHECK_FOLDER_MODTIME
snapshot_check_folder_modtime = get_runtime_setting('ALIPAN_SNAPSHOT_CHECK_FOLDER_MODTIME')
# 文件块大小,默认10MB
chunk_size = 10 * 1024 * 1024
@@ -117,7 +115,7 @@ class AliPan(StorageBase, metaclass=WeakSingleton):
resp = self.session.post(
f"{self.base_url}/oauth/authorize/qrcode",
json={
"client_id": settings.ALIPAN_APP_ID,
"client_id": get_runtime_setting('ALIPAN_APP_ID'),
"scopes": [
"user:base",
"file:all:read",
@@ -181,7 +179,7 @@ class AliPan(StorageBase, metaclass=WeakSingleton):
resp = self.session.post(
f"{self.base_url}/oauth/access_token",
json={
"client_id": settings.ALIPAN_APP_ID,
"client_id": get_runtime_setting('ALIPAN_APP_ID'),
"grant_type": "authorization_code",
"code": self._auth_state["authCode"],
"code_verifier": self._auth_state["code_verifier"],
@@ -205,7 +203,7 @@ class AliPan(StorageBase, metaclass=WeakSingleton):
resp = self.session.post(
f"{self.base_url}/oauth/access_token",
json={
"client_id": settings.ALIPAN_APP_ID,
"client_id": get_runtime_setting('ALIPAN_APP_ID'),
"grant_type": "refresh_token",
"refresh_token": refresh_token,
},
@@ -745,7 +743,7 @@ class AliPan(StorageBase, metaclass=WeakSingleton):
logger.error(f"【阿里云盘】下载链接为空: {fileitem.name}")
return None
local_path = self._build_download_path(fileitem, path or settings.TEMP_PATH)
local_path = self._build_download_path(fileitem, path or get_runtime_setting('TEMP_PATH'))
if not local_path:
return None
@@ -759,7 +757,7 @@ class AliPan(StorageBase, metaclass=WeakSingleton):
try:
# 构建请求头,包含必要的认证信息
headers = {
"User-Agent": settings.NORMAL_USER_AGENT,
"User-Agent": get_runtime_setting('NORMAL_USER_AGENT'),
"Referer": "https://www.aliyundrive.com/",
"Accept": "*/*",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
+7 -9
View File
@@ -5,20 +5,18 @@ from datetime import datetime
from pathlib import Path
from typing import List, Optional
from app.runtime.cache import cached
from app.runtime.settings import RuntimeSettingsCompat
from app.runtime.stop import runtime_stop_state
from app.schemas.file import StorageUsage as _SchemaStorageUsage
from app.schemas.workflow import FileItem as _SchemaFileItem
settings = RuntimeSettingsCompat()
from app.adapters.network.http import RequestUtils
from app.foundation.singleton import WeakSingleton
from app.foundation.url import UrlUtils
from app.modules.filemanager.storages import StorageBase, transfer_process
from app.runtime.cache import cached
from app.runtime.log import logger
from app.runtime.settings import get_runtime_setting
from app.runtime.stop import runtime_stop_state
from app.schemas.exception import OperationInterrupted, StorageQueryError
from app.schemas.file import StorageUsage as _SchemaStorageUsage
from app.schemas.types import StorageSchema
from app.schemas.workflow import FileItem as _SchemaFileItem
# OpenList/AList 在 per_page<=0 时会退回后端默认 200,显式指定最大页大小避免大目录被截断。
OPENLIST_MAX_LIST_PAGE_SIZE = 500
@@ -41,7 +39,7 @@ class Alist(StorageBase, metaclass=WeakSingleton):
}
# 快照检查目录修改时间
snapshot_check_folder_modtime = settings.OPENLIST_SNAPSHOT_CHECK_FOLDER_MODTIME
snapshot_check_folder_modtime = get_runtime_setting('OPENLIST_SNAPSHOT_CHECK_FOLDER_MODTIME')
def __init__(self):
super().__init__()
@@ -692,7 +690,7 @@ class Alist(StorageBase, metaclass=WeakSingleton):
download_url = download_url + "?sign=" + result["data"]["sign"]
if not path:
local_path = settings.TEMP_PATH / fileitem.name
local_path = get_runtime_setting('TEMP_PATH') / fileitem.name
else:
local_path = path / fileitem.name
+5 -7
View File
@@ -4,19 +4,17 @@ import time
from pathlib import Path
from typing import List, Optional
from app.runtime.settings import RuntimeSettingsCompat
from app.runtime.stop import runtime_stop_state
from app.schemas.file import StorageUsage as _SchemaStorageUsage
from app.schemas.workflow import FileItem as _SchemaFileItem
settings = RuntimeSettingsCompat()
from app.adapters.system.fsproxy import fsproxy
from app.adapters.system.host import SystemUtils
from app.application.directory import DirectoryHelper
from app.modules.filemanager.storages import StorageBase, transfer_process
from app.runtime.log import logger
from app.runtime.settings import get_runtime_setting
from app.runtime.stop import runtime_stop_state
from app.schemas.exception import StorageQueryError
from app.schemas.file import StorageUsage as _SchemaStorageUsage
from app.schemas.types import StorageSchema
from app.schemas.workflow import FileItem as _SchemaFileItem
class LocalStorage(StorageBase):
@@ -477,7 +475,7 @@ class LocalStorage(StorageBase):
total_storage, free_storage = SystemUtils.space_usage(
[Path(d.download_path) for d in directory_helper.get_local_download_dirs() if d.download_path] +
[Path(d.library_path) for d in directory_helper.get_local_library_dirs() if d.library_path],
btrfs_fsid_dedup=settings.BTRFS_FSID_DEDUP,
btrfs_fsid_dedup=get_runtime_setting('BTRFS_FSID_DEDUP'),
)
return _SchemaStorageUsage(
total=total_storage,
+5 -7
View File
@@ -6,17 +6,15 @@ from collections import OrderedDict
from pathlib import Path
from typing import List, Optional, Union
from app.runtime.settings import RuntimeSettingsCompat
from app.schemas.file import StorageUsage as _SchemaStorageUsage
from app.schemas.workflow import FileItem as _SchemaFileItem
settings = RuntimeSettingsCompat()
from app.adapters.system.host import SystemUtils
from app.foundation import temporal as time_tools
from app.modules.filemanager.storages import StorageBase, transfer_process
from app.runtime.log import logger
from app.runtime.settings import get_runtime_setting
from app.schemas.exception import StorageQueryError
from app.schemas.file import StorageUsage as _SchemaStorageUsage
from app.schemas.types import StorageSchema
from app.schemas.workflow import FileItem as _SchemaFileItem
_MAX_FOLDER_LOCKS = 4096
_folder_locks: OrderedDict[str, threading.Lock] = OrderedDict()
@@ -50,7 +48,7 @@ class Rclone(StorageBase):
"copy": "复制"
}
snapshot_check_folder_modtime = settings.RCLONE_SNAPSHOT_CHECK_FOLDER_MODTIME
snapshot_check_folder_modtime = get_runtime_setting('RCLONE_SNAPSHOT_CHECK_FOLDER_MODTIME')
def init_storage(self):
"""
@@ -376,7 +374,7 @@ class Rclone(StorageBase):
"""
带实时进度显示的下载
"""
local_path = self._build_download_path(fileitem, path or settings.TEMP_PATH)
local_path = self._build_download_path(fileitem, path or get_runtime_setting('TEMP_PATH'))
if not local_path:
return None
+5 -7
View File
@@ -12,17 +12,15 @@ from smbprotocol.exceptions import (
SMBResponseException,
)
from app.runtime.settings import RuntimeSettingsCompat
from app.runtime.stop import runtime_stop_state
from app.schemas.file import StorageUsage as _SchemaStorageUsage
from app.schemas.workflow import FileItem as _SchemaFileItem
settings = RuntimeSettingsCompat()
from app.foundation.singleton import WeakSingleton
from app.modules.filemanager.storages import StorageBase, transfer_process
from app.runtime.log import logger
from app.runtime.settings import get_runtime_setting
from app.runtime.stop import runtime_stop_state
from app.schemas.exception import StorageQueryError
from app.schemas.file import StorageUsage as _SchemaStorageUsage
from app.schemas.types import StorageSchema
from app.schemas.workflow import FileItem as _SchemaFileItem
lock = threading.Lock()
@@ -550,7 +548,7 @@ class SMB(StorageBase, metaclass=WeakSingleton):
"""
带实时进度显示的下载
"""
local_path = self._build_download_path(fileitem, path or settings.TEMP_PATH)
local_path = self._build_download_path(fileitem, path or get_runtime_setting('TEMP_PATH'))
if not local_path:
return None
smb_path = self._normalize_path(fileitem.path)
+8 -10
View File
@@ -12,19 +12,17 @@ from cryptography.hazmat.primitives import hashes
from oss2 import SizedFileAdapter, determine_part_size
from oss2.models import PartInfo
from app.runtime.settings import RuntimeSettingsCompat
from app.runtime.stop import runtime_stop_state
from app.schemas.file import StorageUsage as _SchemaStorageUsage
from app.schemas.workflow import FileItem as _SchemaFileItem
settings = RuntimeSettingsCompat()
from app.foundation import size as size_tools
from app.foundation.singleton import WeakSingleton
from app.modules.filemanager.storages import StorageBase, transfer_process
from app.runtime.log import logger
from app.runtime.rate import QpsRateLimiter, RateStats
from app.runtime.settings import get_runtime_setting
from app.runtime.stop import runtime_stop_state
from app.schemas.exception import StorageQueryError
from app.schemas.file import StorageUsage as _SchemaStorageUsage
from app.schemas.types import StorageSchema
from app.schemas.workflow import FileItem as _SchemaFileItem
lock = Lock()
@@ -130,7 +128,7 @@ class U115Pan(StorageBase, metaclass=WeakSingleton):
生成 OAuth2 授权 URL
"""
try:
resp = self.session.get(f"{settings.U115_AUTH_SERVER}/u115/auth_url")
resp = self.session.get(f"{get_runtime_setting('U115_AUTH_SERVER')}/u115/auth_url")
if resp is None:
return {}, "无法连接到授权服务器"
@@ -165,7 +163,7 @@ class U115Pan(StorageBase, metaclass=WeakSingleton):
resp = self.session.post(
"https://passportapi.115.com/open/authDeviceCode",
data={
"client_id": settings.U115_APP_ID,
"client_id": get_runtime_setting('U115_APP_ID'),
"code_challenge": code_challenge,
"code_challenge_method": "sha256",
},
@@ -229,7 +227,7 @@ class U115Pan(StorageBase, metaclass=WeakSingleton):
try:
resp = self.session.get(
f"{settings.U115_AUTH_SERVER}/u115/token", params={"state": state}
f"{get_runtime_setting('U115_AUTH_SERVER')}/u115/token", params={"state": state}
)
if resp is None:
return {}, "无法连接到授权服务器"
@@ -910,7 +908,7 @@ class U115Pan(StorageBase, metaclass=WeakSingleton):
logger.error(f"【115】下载链接为空: {fileitem.name}")
return None
local_path = self._build_download_path(fileitem, path or settings.TEMP_PATH)
local_path = self._build_download_path(fileitem, path or get_runtime_setting('TEMP_PATH'))
if not local_path:
return None