mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-05-07 02:32:41 +08:00
fix: update backup export to use JSON mode
This commit is contained in:
@@ -28,7 +28,7 @@ async def export_backup(
|
|||||||
data = await BackupService.export_data(sections=sections)
|
data = await BackupService.export_data(sections=sections)
|
||||||
timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
||||||
headers = {"Content-Disposition": f"attachment; filename=foxel_backup_{timestamp}.json"}
|
headers = {"Content-Disposition": f"attachment; filename=foxel_backup_{timestamp}.json"}
|
||||||
return JSONResponse(content=data.model_dump(), headers=headers)
|
return JSONResponse(content=data.model_dump(mode="json"), headers=headers)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/import", summary="导入数据")
|
@router.post("/import", summary="导入数据")
|
||||||
|
|||||||
@@ -82,6 +82,9 @@ class BackupService:
|
|||||||
share_links = cls._serialize_datetime_fields(
|
share_links = cls._serialize_datetime_fields(
|
||||||
shares, ["created_at", "expires_at"]
|
shares, ["created_at", "expires_at"]
|
||||||
)
|
)
|
||||||
|
user_accounts = cls._serialize_datetime_fields(
|
||||||
|
users, ["created_at", "last_login"]
|
||||||
|
)
|
||||||
ai_providers = cls._serialize_datetime_fields(
|
ai_providers = cls._serialize_datetime_fields(
|
||||||
providers, ["created_at", "updated_at"]
|
providers, ["created_at", "updated_at"]
|
||||||
)
|
)
|
||||||
@@ -99,7 +102,7 @@ class BackupService:
|
|||||||
version=VERSION,
|
version=VERSION,
|
||||||
sections=sections,
|
sections=sections,
|
||||||
storage_adapters=list(adapters),
|
storage_adapters=list(adapters),
|
||||||
user_accounts=list(users),
|
user_accounts=user_accounts,
|
||||||
automation_tasks=list(tasks),
|
automation_tasks=list(tasks),
|
||||||
share_links=share_links,
|
share_links=share_links,
|
||||||
configurations=list(configs),
|
configurations=list(configs),
|
||||||
@@ -132,6 +135,11 @@ class BackupService:
|
|||||||
if payload.share_links
|
if payload.share_links
|
||||||
else []
|
else []
|
||||||
)
|
)
|
||||||
|
user_accounts = (
|
||||||
|
cls._parse_datetime_fields(payload.user_accounts, ["created_at", "last_login"])
|
||||||
|
if payload.user_accounts
|
||||||
|
else []
|
||||||
|
)
|
||||||
ai_providers = (
|
ai_providers = (
|
||||||
cls._parse_datetime_fields(payload.ai_providers, ["created_at", "updated_at"])
|
cls._parse_datetime_fields(payload.ai_providers, ["created_at", "updated_at"])
|
||||||
if payload.ai_providers
|
if payload.ai_providers
|
||||||
@@ -189,10 +197,10 @@ class BackupService:
|
|||||||
|
|
||||||
if "user_accounts" in sections and payload.user_accounts:
|
if "user_accounts" in sections and payload.user_accounts:
|
||||||
if mode == "merge":
|
if mode == "merge":
|
||||||
await cls._merge_records(UserAccount, payload.user_accounts, conn)
|
await cls._merge_records(UserAccount, user_accounts, conn)
|
||||||
else:
|
else:
|
||||||
await UserAccount.bulk_create(
|
await UserAccount.bulk_create(
|
||||||
[UserAccount(**user) for user in payload.user_accounts],
|
[UserAccount(**user) for user in user_accounts],
|
||||||
using_db=conn,
|
using_db=conn,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user