增加快速文件互传功能(基于 MSD)

为 MSD 路径添加配置选项
为 文件镜像名称添加配置选项
修复 make 测试环境
This commit is contained in:
mofeng-git
2024-11-22 17:40:55 +00:00
parent 5450d7297c
commit b8ddf7c2da
14 changed files with 262 additions and 36 deletions

View File

@@ -596,8 +596,18 @@
</div>
</td>
</tr>
<tr>
<td i18n="kvm_text84">文件内容:</td>
<td>
<div class="radio-box">
<input checked type="radio" id="msd-mode-radio-image" name="file-mode-radio" value="1">
<label for="msd-mode-radio-image" i18n="kvm_text90">ImageFiles</label>
<input type="radio" id="msd-mode-radio-file" name="file-mode-radio" value="0">
<label for="msd-mode-radio-file" i18n="kvm_text91">NormalFiles</label>
</div>
</td>
</tr>
</table>
<hr>
<div id="msd-storages"></div>
<hr>
<div class="buttons buttons-row">
@@ -674,6 +684,14 @@
<button class="row25" disabled id="msd-disconnect-button" i18n="kvm_text77">Disconnect</button>
<button class="row25" disabled id="msd-reset-button" i18n="kvm_text78">Reset</button>
</div>
<hr>
<div class="text"><b i18n="kvm_text85">Quick file transfer:</b><br><sub i18n="kvm_text86">&bull; Select NormalFiles tab to upload, package them and mount image</sub><br><sub i18n="kvm_text87">&bull; Disconnect MSD, unpackage it, select tab to download</sub><br></div>
<hr>
<div class="buttons buttons-row">
<button class="row50" id="msd-file-image-update-button" i18n="kvm_text88">Package files into image</button>
<button class="row50" id="msd-file-image-unzip-button" i18n="kvm_text89">Unpackage files from image</button>
</div>
<hr>
</div>
</li>
<li class="right" id="macro-dropdown"><a class="menu-button" href="#"><img class="led-gray" id="hid-recorder-led" src="/share/svg/led-gear.svg"><span i18n="kvm_text32">Macro</span></a>

View File

@@ -50,7 +50,14 @@ li(id="msd-dropdown" class="right feature-disabled")
label(for="msd-mode-radio-flash") Flash
td &nbsp;
+menu_switch_notable("msd-rw-switch", "Writable", false, false, "msd-rw-switch")
hr
tr
td(i18n="kvm_text84") 文件内容:
td
div(class="radio-box")
input(checked type="radio" id="msd-mode-radio-image" name="file-mode-radio" value="1")
label(for="msd-mode-radio-image" i18n="kvm_text90") ImageFiles
input(type="radio" id="msd-mode-radio-file" name="file-mode-radio" value="0")
label(for="msd-mode-radio-file" i18n="kvm_text91") NormalFiles
div(id="msd-storages")
hr
div(class="buttons buttons-row")
@@ -98,3 +105,20 @@ li(id="msd-dropdown" class="right feature-disabled")
button(disabled id="msd-connect-button" class="row50" i18n="kvm_text76") Connect drive to Server
button(disabled id="msd-disconnect-button" class="row25" i18n="kvm_text77") Disconnect
button(disabled id="msd-reset-button" class="row25" i18n="kvm_text78") Reset
hr
div(class="text")
b(i18n="kvm_text85") Quick file transfer:
br
sub(i18n="kvm_text86") &bull; Select NormalFiles tab to upload, package them and mount image
br
sub(i18n="kvm_text87") &bull; Disconnect MSD, unpackage it, select tab to download
br
hr
div(class="buttons buttons-row")
button(id="msd-file-image-update-button" class="row50" i18n="kvm_text88") Package files into image
button(id="msd-file-image-unzip-button" class="row50" i18n="kvm_text89") Unpackage files from image
hr

View File

@@ -114,6 +114,14 @@
"kvm_text81":"Start recording",
"kvm_text82":"End recording",
"kvm_text83":"Web UI settings",
"kvm_text84":"File display:",
"kvm_text85":"Quick file transfer:",
"kvm_text86":"&bull; Select NormalFiles tab to upload, package them and mount image",
"kvm_text87":"&bull; Disconnect MSD, unpackage it, select tab to download",
"kvm_text88":"Package files into image",
"kvm_text89":"Unpackage files from image",
"kvm_text90":"ImageFiles",
"kvm_text91":"NormalFiles",
"atx-ask-switch":"Ask click confirmation",
"hid-recorder-loop-switch":"Infinite loop playback",

View File

@@ -93,9 +93,9 @@
"kvm_text60":"驱动器",
"kvm_text61":"虚拟存储驱动器",
"kvm_text62":"镜像",
"kvm_text62":"文件",
"kvm_text63":"驱动<a target=\"_blank\" href=\"https://docs.pikvm.org/msd\">模式</a>:",
"kvm_text64":"选择要上传的镜像",
"kvm_text64":"选择要上传的文件",
"kvm_text65":"上传",
"kvm_text66":"中止",
"kvm_text68":"指定本地文件:",
@@ -114,6 +114,16 @@
"kvm_text81":"开始录制",
"kvm_text82":"结束录制",
"kvm_text83":"网页界面设置",
"kvm_text84":"文件显示:",
"kvm_text85":"快速文件互传:",
"kvm_text86":"&bull; 切换互传文件上传文件,打包生成镜像文件,挂载 NormalFiles 镜像",
"kvm_text87":"&bull; 断开 MSD 连接,选择从镜像文件解压,切换互传文件下载所需文件",
"kvm_text88":"从互传文件打包镜像文件",
"kvm_text89":"从镜像文件解压互传文件",
"kvm_text90":"镜像文件",
"kvm_text91":"互传文件",
"atx-ask-switch":"点击二次确认",
"hid-recorder-loop-switch":"无限循环重放",

View File

@@ -46,7 +46,8 @@ export function Msd() {
tools.radio.setOnClick("msd-mode-radio", () => __sendParam("cdrom", tools.radio.getValue("msd-mode-radio")));
tools.el.setOnClick($("msd-rw-switch"), () => __sendParam("rw", $("msd-rw-switch").checked));
tools.radio.setOnClick("file-mode-radio", __refreshFileMode, false);
tools.el.setOnClick($("msd-select-new-button"), __toggleSelectSub);
$("msd-new-file").onchange = __selectNewFile;
$("msd-new-url").oninput = __selectNewUrl;
@@ -58,6 +59,9 @@ export function Msd() {
tools.el.setOnClick($("msd-connect-button"), () => __clickConnectButton(true));
tools.el.setOnClick($("msd-disconnect-button"), () => __clickConnectButton(false));
tools.el.setOnClick($("msd-file-image-update-button"), () => __clickMakeImageButton(true));
tools.el.setOnClick($("msd-file-image-unzip-button"), () => __clickMakeImageButton(false));
tools.el.setOnClick($("msd-reset-button"), __clickResetButton);
};
@@ -97,9 +101,12 @@ export function Msd() {
if (state.storage.images !== undefined) {
__state.storage.images = state.storage.images;
}
if (state.storage.filespath !== undefined) {
__state.storage.filespath = state.storage.filespath;
}
}
if (state.drive || (state.storage && state.storage.images !== undefined)) {
__updateImageSelector(__state.drive, __state.storage.images);
__updateImageSelector(__state.drive, __state.storage.images, __state.storage.filespath);
}
}
} else {
@@ -132,6 +139,7 @@ export function Msd() {
tools.radio.setEnabled("msd-mode-radio", (o && !d.connected && !busy));
tools.radio.setValue("msd-mode-radio", `${Number(o && d.cdrom)}`);
tools.radio.setEnabled("file-mode-radio", (o && !d.connected && !busy));
tools.el.setEnabled($("msd-rw-switch"), (o && !d.connected && !busy));
$("msd-rw-switch").checked = (o && d.rw);
@@ -174,6 +182,16 @@ export function Msd() {
}
$("msd-led").className = led_cls;
$("msd-status").innerText = $("msd-led").title = msg;
if (tools.radio.getValue("file-mode-radio") == "0"){
tools.el.setEnabled($("msd-connect-button"), false);
tools.el.setEnabled($("msd-file-image-update-button"), false);
tools.el.setEnabled($("msd-file-image-unzip-button"), false);
} else {
tools.el.setEnabled($("msd-connect-button"), (o && d.image && !d.connected && !busy));
tools.el.setEnabled($("msd-file-image-update-button"), (o && !d.connected && !busy));
tools.el.setEnabled($("msd-file-image-unzip-button"), (o && !d.connected && !busy));
}
};
var __updateUploading = function(uploading) {
@@ -227,17 +245,20 @@ export function Msd() {
}
};
var __updateImageSelector = function(drive, images) {
var __updateImageSelector = function(drive, images, filespath) {
let sel = "";
let el = $("msd-image-selector");
let fm = tools.radio.getValue("file-mode-radio");
el.options.length = 1;
for (let name of Object.keys(images).sort()) {
tools.selector.addSeparator(el);
tools.selector.addOption(el, name, name);
tools.selector.addComment(el, __makeImageSelectorInfo(images[name]));
if (drive.image && drive.image.name === name && drive.image.in_storage) {
sel = name;
}
if ((fm == "0" && name.startsWith(filespath + "/")) || (fm == "1" && !name.startsWith(filespath + "/"))) {
tools.selector.addSeparator(el);
tools.selector.addOption(el, name, name);
tools.selector.addComment(el, __makeImageSelectorInfo(images[name]));
if (drive.image && drive.image.name === name && drive.image.in_storage) {
sel = name;
}
}
}
if (drive.image && !drive.image.in_storage) {
sel = ".__external__"; // Just some magic name
@@ -295,10 +316,23 @@ export function Msd() {
});
};
var __refreshFileMode = function() {
if (__state.storage.images !== undefined) {
__updateImageSelector(__state.drive, __state.storage.images, __state.storage.filespath);
}
__refreshControls();
};
var __clickUploadNewButton = function() {
let file = tools.input.getFile($("msd-new-file"));
__http = new XMLHttpRequest();
let prefix = encodeURIComponent($("msd-new-part-selector").value);
let prefix = ""
if (tools.radio.getValue("file-mode-radio") == "1"){
prefix = encodeURIComponent($("msd-new-part-selector").value);
}else{
prefix = "NormalFiles";
}
if (file) {
let image = encodeURIComponent(file.name);
__http.open("POST", `/api/msd/write?prefix=${prefix}&image=${image}&remove_incomplete=1`, true);
@@ -370,6 +404,21 @@ export function Msd() {
tools.el.setEnabled($(`msd-${connected ? "connect" : "disconnect"}-button`), false);
};
var __clickMakeImageButton = function(zipped) {
tools.el.setEnabled($("msd-file-image-update-button"), false);
tools.el.setEnabled($("msd-file-image-unzip-button"), false);
tools.httpPost("/api/msd/make_image", {"zipped": zipped}, function(http) {
if (http.status !== 200) {
wm.error("Can't make File Image", http.responseText);
}
__refreshControls();
});
__refreshControls();
if (__state.storage.images !== undefined) {
__updateImageSelector(__state.drive, __state.storage.images, __state.storage.filespath);
}
};
var __clickResetButton = function() {
wm.confirm("Are you sure you want to reset Mass Storage?").then(function(ok) {
if (ok) {