Skip to content

Commit

Permalink
Use custom filename on download only if backup file name is backup slug
Browse files Browse the repository at this point in the history
  • Loading branch information
agners committed Jan 22, 2025
1 parent 8c14810 commit bcb8f2a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions supervisor/api/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,14 @@ async def download(self, request: web.Request):
raise APIError(f"Backup {backup.slug} is not in location {location}")

_LOGGER.info("Downloading backup %s", backup.slug)
response = web.FileResponse(backup.all_locations[location])
filename = backup.all_locations[location]
response = web.FileResponse(filename)
response.content_type = CONTENT_TYPE_TAR

if filename == f"{backup.slug}.tar":
filename = f"{RE_SLUGIFY_NAME.sub('_', backup.name)}.tar"
response.headers[CONTENT_DISPOSITION] = (
f"attachment; filename={RE_SLUGIFY_NAME.sub('_', backup.name)}.tar"
f"attachment; filename={filename}"
)
return response

Expand Down

0 comments on commit bcb8f2a

Please sign in to comment.