mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-09-04 23:18:02 +08:00
refactor: refresh 中异步保存文件
This commit is contained in:
+1
-2
@@ -17,8 +17,7 @@ class PersistedCredential(Credential):
|
|||||||
self.dedeuserid,
|
self.dedeuserid,
|
||||||
self.ac_time_value,
|
self.ac_time_value,
|
||||||
)
|
)
|
||||||
# 暂时使用同步调用
|
await settings.asave()
|
||||||
settings.save()
|
|
||||||
|
|
||||||
|
|
||||||
credential = PersistedCredential()
|
credential = PersistedCredential()
|
||||||
|
|||||||
+12
@@ -6,6 +6,7 @@ from pydantic_core import PydanticCustomError
|
|||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
||||||
from constants import DEFAULT_CONFIG_PATH
|
from constants import DEFAULT_CONFIG_PATH
|
||||||
|
from utils import amakedirs, aopen
|
||||||
|
|
||||||
|
|
||||||
class SubtitleConfig(BaseModel):
|
class SubtitleConfig(BaseModel):
|
||||||
@@ -57,6 +58,17 @@ class Config(BaseModel):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise RuntimeError(f"Failed to save config file: {path}") from 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:
|
def init_settings() -> Config:
|
||||||
if not DEFAULT_CONFIG_PATH.exists():
|
if not DEFAULT_CONFIG_PATH.exists():
|
||||||
|
|||||||
Reference in New Issue
Block a user