diff options
-rw-r--r-- | kvmd/apps/kvmd/api/msd.py | 11 | ||||
-rw-r--r-- | kvmd/apps/kvmd/http.py | 24 | ||||
-rw-r--r-- | web/share/js/kvm/msd.js | 9 |
3 files changed, 5 insertions, 39 deletions
diff --git a/kvmd/apps/kvmd/api/msd.py b/kvmd/apps/kvmd/api/msd.py index 4e1a7f14..1f1afd1e 100644 --- a/kvmd/apps/kvmd/api/msd.py +++ b/kvmd/apps/kvmd/api/msd.py @@ -48,9 +48,6 @@ from ..http import make_json_response from ..http import make_json_exception from ..http import start_streaming from ..http import stream_json -from ..http import get_multipart_reader -from ..http import get_multipart_reader_str -from ..http import get_multipart_reader_field # ====== @@ -86,15 +83,13 @@ class MsdApi: @exposed_http("POST", "/msd/write") async def __write_handler(self, request: Request) -> Response: - reader = await get_multipart_reader(request) - name = valid_msd_image_name(await get_multipart_reader_str(reader, "image")) - size = valid_int_f0(await get_multipart_reader_str(reader, "size")) - data_field = await get_multipart_reader_field(reader, "data") + name = valid_msd_image_name(request.query.get("image")) + size = valid_int_f0(request.content_length) written = 0 async with self.__msd.write_image(name, size) as chunk_size: while True: - chunk = await data_field.read_chunk(chunk_size) + chunk = await request.content.read(chunk_size) if not chunk: break written = await self.__msd.write_image_chunk(chunk) diff --git a/kvmd/apps/kvmd/http.py b/kvmd/apps/kvmd/http.py index ae2cebc0..0ecc1670 100644 --- a/kvmd/apps/kvmd/http.py +++ b/kvmd/apps/kvmd/http.py @@ -41,8 +41,6 @@ except ImportError: from ...logging import get_logger -from ...validators import ValidatorError - # ===== class HttpError(Exception): @@ -181,28 +179,6 @@ async def stream_json(response: aiohttp.web.StreamResponse, result: Dict) -> Non # ===== -async def get_multipart_reader(request: aiohttp.web.Request) -> aiohttp.MultipartReader: - try: - return (await request.multipart()) - except Exception: - raise ValidatorError("Expected multipart") - - -async def get_multipart_reader_str(reader: aiohttp.MultipartReader, name: str) -> str: - field = await get_multipart_reader_field(reader, name) - return (await field.read()).decode("utf-8") - - -async def get_multipart_reader_field(reader: aiohttp.MultipartReader, name: str) -> aiohttp.BodyPartReader: - field = await reader.next() - if not isinstance(field, aiohttp.BodyPartReader): - raise ValidatorError(f"Expected body part as {name!r} field") - if not field or field.name != name: - raise ValidatorError(f"Missing {name!r} field") - return field - - -# ===== _REQUEST_AUTH_INFO = "_kvmd_auth_info" diff --git a/web/share/js/kvm/msd.js b/web/share/js/kvm/msd.js index 25c68b01..e7ed1070 100644 --- a/web/share/js/kvm/msd.js +++ b/web/share/js/kvm/msd.js @@ -99,16 +99,11 @@ export function Msd() { }; var __clickUploadNewImageButton = function() { - let form_data = new FormData(); - form_data.append("image", __image_file.name); - form_data.append("size", __image_file.size); - form_data.append("data", __image_file); - __upload_http = new XMLHttpRequest(); - __upload_http.open("POST", "/api/msd/write", true); + __upload_http.open("POST", `/api/msd/write?image=${encodeURIComponent(__image_file.name)}`, true); __upload_http.upload.timeout = 15000; __upload_http.onreadystatechange = __uploadStateChange; - __upload_http.send(form_data); + __upload_http.send(__image_file); }; var __uploadStateChange = function() { |