From bcb8f2a7044ad39e14e302acd93d30f196bcef59 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 22 Jan 2025 21:28:48 +0100 Subject: [PATCH] Use custom filename on download only if backup file name is backup slug --- supervisor/api/backups.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/supervisor/api/backups.py b/supervisor/api/backups.py index 1b1b8e38e61..6c826c32f18 100644 --- a/supervisor/api/backups.py +++ b/supervisor/api/backups.py @@ -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