Backup API now instead returns 500 on failure
Removed the "success" flag
This commit is contained in:
@@ -162,8 +162,7 @@ class HealthCheck(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class BackupResponse(BaseModel):
|
class BackupResponse(BaseModel):
|
||||||
success: bool = Field(description="Whether the backup was created successfully.", example=True)
|
path: str = Field(
|
||||||
path: Optional[str] = Field(
|
|
||||||
default=None,
|
default=None,
|
||||||
description="Path to the created backup file.",
|
description="Path to the created backup file.",
|
||||||
example="/home/app/.local/share/spoolman/backups/spoolman.db",
|
example="/home/app/.local/share/spoolman/backups/spoolman.db",
|
||||||
|
|||||||
@@ -40,13 +40,21 @@ async def health() -> models.HealthCheck:
|
|||||||
|
|
||||||
|
|
||||||
# Add endpoint for triggering a db backup
|
# Add endpoint for triggering a db backup
|
||||||
@app.post("/backup", description="Trigger a database backup. Only applicable for SQLite databases.")
|
@app.post(
|
||||||
async def backup() -> models.BackupResponse:
|
"/backup",
|
||||||
|
description="Trigger a database backup. Only applicable for SQLite databases.",
|
||||||
|
response_model=models.BackupResponse,
|
||||||
|
responses={500: {"model": models.Message}},
|
||||||
|
)
|
||||||
|
async def backup(): # noqa: ANN201
|
||||||
"""Trigger a database backup."""
|
"""Trigger a database backup."""
|
||||||
path = await backup_task()
|
path = await backup_task()
|
||||||
if path is None:
|
if path is None:
|
||||||
return models.BackupResponse(success=False)
|
return JSONResponse(
|
||||||
return models.BackupResponse(success=True, path=str(path))
|
status_code=500,
|
||||||
|
content={"message": "Backup failed. See server logs for more information."},
|
||||||
|
)
|
||||||
|
return models.BackupResponse(path=str(path))
|
||||||
|
|
||||||
|
|
||||||
# Add routers
|
# Add routers
|
||||||
|
|||||||
Reference in New Issue
Block a user