diff options
author | Maxim Devaev <[email protected]> | 2023-03-17 00:10:51 +0200 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2023-03-17 00:10:51 +0200 |
commit | 921d7da513c663eaaa690472beccb0d8d0c5a310 (patch) | |
tree | d7553276780da9f1c65622b38387cce7b186ea2b | |
parent | 74a19e40dae259d530ef5420663ccfaf7ba38f51 (diff) |
optional upload prefix
-rw-r--r-- | kvmd/apps/kvmd/api/msd.py | 6 | ||||
-rw-r--r-- | web/kvm/index.html | 10 | ||||
-rw-r--r-- | web/kvm/navbar-msd.pug | 6 | ||||
-rw-r--r-- | web/share/css/navbar.css | 10 | ||||
-rw-r--r-- | web/share/js/kvm/msd.js | 5 |
5 files changed, 33 insertions, 4 deletions
diff --git a/kvmd/apps/kvmd/api/msd.py b/kvmd/apps/kvmd/api/msd.py index 16118141..59915864 100644 --- a/kvmd/apps/kvmd/api/msd.py +++ b/kvmd/apps/kvmd/api/msd.py @@ -136,7 +136,8 @@ class MsdApi: @exposed_http("POST", "/msd/write") async def __write_handler(self, request: Request) -> Response: - name = valid_msd_image_name(request.query.get("image")) + unsafe_prefix = request.query.get("prefix", "") + "/" + name = valid_msd_image_name(unsafe_prefix + request.query.get("image", "")) size = valid_int_f0(request.content_length) remove_incomplete = self.__get_remove_incomplete(request) written = 0 @@ -151,6 +152,7 @@ class MsdApi: @exposed_http("POST", "/msd/write_remote") async def __write_remote_handler(self, request: Request) -> (Response | StreamResponse): # pylint: disable=too-many-locals + unsafe_prefix = request.query.get("prefix", "") + "/" url = valid_url(request.query.get("url")) insecure = valid_bool(request.query.get("insecure", False)) timeout = valid_float_f01(request.query.get("timeout", 10.0)) @@ -175,7 +177,7 @@ class MsdApi: name = str(request.query.get("image", "")).strip() if len(name) == 0: name = htclient.get_filename(remote) - name = valid_msd_image_name(name) + name = valid_msd_image_name(unsafe_prefix + name) size = valid_int_f0(remote.content_length) diff --git a/web/kvm/index.html b/web/kvm/index.html index 9029fc36..568da0ec 100644 --- a/web/kvm/index.html +++ b/web/kvm/index.html @@ -533,6 +533,12 @@ <input type="text" id="msd-new-url" style="width: 100%"> </td> </tr> + <tr> + <td>Optional upload prefix:</td> + <td> + <input type="text" id="msd-new-prefix" style="width: 100%" placeholder="... like /foo/bar"> + </td> + </tr> </table> <hr> <table class="kv"> @@ -544,6 +550,10 @@ <td></td> <td>• To speed up the upload, close the stream window.</td> </tr> + <tr> + <td></td> + <td>• A non-empty upload prefix will be created when uploading.</td> + </tr> </table> </div> <div class="hidden" id="msd-uploading-sub"> diff --git a/web/kvm/navbar-msd.pug b/web/kvm/navbar-msd.pug index 1ffd763e..f668ae32 100644 --- a/web/kvm/navbar-msd.pug +++ b/web/kvm/navbar-msd.pug @@ -71,6 +71,9 @@ li(id="msd-dropdown" class="right feature-disabled") tr td #[b Or] paste a URL: td #[input(type="text" id="msd-new-url" style="width: 100%")] + tr + td Optional upload prefix: + td #[input(type="text" id="msd-new-prefix" style="width: 100%" placeholder="... like /foo/bar")] hr table(class="kv") tr @@ -79,6 +82,9 @@ li(id="msd-dropdown" class="right feature-disabled") tr td td • To speed up the upload, close the stream window. + tr + td + td • A non-empty upload prefix will be created when uploading. div(id="msd-uploading-sub" class="hidden") hr table(class="kv") diff --git a/web/share/css/navbar.css b/web/share/css/navbar.css index a33af82c..5be9ac81 100644 --- a/web/share/css/navbar.css +++ b/web/share/css/navbar.css @@ -176,6 +176,16 @@ ul#navbar li div.menu div.buttons select { padding: 0 16px; } +ul#navbar li div.menu input[type=text] { + height: 1.5em; +} +ul#navbar li div.menu input[type=text]::-moz-placeholder { + text-align: center; +} +ul#navbar li div.menu input[type=text]::-webkit-input-placeholder { + text-align: center; +} + ul#navbar li div.menu hr { margin: 0; display: block; diff --git a/web/share/js/kvm/msd.js b/web/share/js/kvm/msd.js index fae72e43..6b8d33b2 100644 --- a/web/share/js/kvm/msd.js +++ b/web/share/js/kvm/msd.js @@ -114,11 +114,12 @@ export function Msd() { var __clickUploadNewButton = function() { let file = tools.input.getFile($("msd-new-file")); __http = new XMLHttpRequest(); + let prefix = encodeURIComponent($("msd-new-prefix").value); if (file) { - __http.open("POST", `/api/msd/write?image=${encodeURIComponent(file.name)}&remove_incomplete=1`, true); + __http.open("POST", `/api/msd/write?prefix=${prefix}&image=${encodeURIComponent(file.name)}&remove_incomplete=1`, true); } else { let url = $("msd-new-url").value; - __http.open("POST", `/api/msd/write_remote?url=${encodeURIComponent(url)}&remove_incomplete=1`, true); + __http.open("POST", `/api/msd/write_remote?prefix=${prefix}&url=${encodeURIComponent(url)}&remove_incomplete=1`, true); } __http.upload.timeout = 7 * 24 * 3600; __http.onreadystatechange = __httpStateChange; |