mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-05-06 20:42:48 +08:00
refactor: refresh 中异步保存文件
This commit is contained in:
@@ -17,8 +17,7 @@ class PersistedCredential(Credential):
|
||||
self.dedeuserid,
|
||||
self.ac_time_value,
|
||||
)
|
||||
# 暂时使用同步调用
|
||||
settings.save()
|
||||
await settings.asave()
|
||||
|
||||
|
||||
credential = PersistedCredential()
|
||||
|
||||
12
settings.py
12
settings.py
@@ -6,6 +6,7 @@ from pydantic_core import PydanticCustomError
|
||||
from typing_extensions import Annotated
|
||||
|
||||
from constants import DEFAULT_CONFIG_PATH
|
||||
from utils import amakedirs, aopen
|
||||
|
||||
|
||||
class SubtitleConfig(BaseModel):
|
||||
@@ -57,6 +58,17 @@ class Config(BaseModel):
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to save config file: {path}") from e
|
||||
|
||||
async def asave(self, path: Path | None = None) -> "Config":
|
||||
if not path:
|
||||
path = DEFAULT_CONFIG_PATH
|
||||
try:
|
||||
await amakedirs(path.parent, exist_ok=True)
|
||||
async with aopen(path, "w") as f:
|
||||
await f.write(Config.model_dump_json(self, indent=4))
|
||||
return self
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to save config file: {path}") from e
|
||||
|
||||
|
||||
def init_settings() -> Config:
|
||||
if not DEFAULT_CONFIG_PATH.exists():
|
||||
|
||||
Reference in New Issue
Block a user