mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-22 08:36:30 +00:00
Add content-disposition header to snapshot download (#2116)
* Add content-disposition header to snapshot download * compile it
This commit is contained in:
parent
ba576d8748
commit
ccb8e5fe06
@ -2,9 +2,11 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import re
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
|
from aiohttp.hdrs import CONTENT_DISPOSITION
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from ..const import (
|
from ..const import (
|
||||||
@ -30,6 +32,7 @@ from .utils import api_process, api_validate
|
|||||||
|
|
||||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
RE_SLUGIFY_NAME = re.compile(r"[^A-Za-z0-9]+")
|
||||||
|
|
||||||
# pylint: disable=no-value-for-parameter
|
# pylint: disable=no-value-for-parameter
|
||||||
SCHEMA_RESTORE_PARTIAL = vol.Schema(
|
SCHEMA_RESTORE_PARTIAL = vol.Schema(
|
||||||
@ -175,6 +178,9 @@ class APISnapshots(CoreSysAttributes):
|
|||||||
_LOGGER.info("Download snapshot %s", snapshot.slug)
|
_LOGGER.info("Download snapshot %s", snapshot.slug)
|
||||||
response = web.FileResponse(snapshot.tarfile)
|
response = web.FileResponse(snapshot.tarfile)
|
||||||
response.content_type = CONTENT_TYPE_TAR
|
response.content_type = CONTENT_TYPE_TAR
|
||||||
|
response.headers[
|
||||||
|
CONTENT_DISPOSITION
|
||||||
|
] = f"attachment; filename={RE_SLUGIFY_NAME.sub('_', snapshot.name)}.tar"
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@api_process
|
@api_process
|
||||||
|
Loading…
x
Reference in New Issue
Block a user