add bbl file fetch from ui
This commit is contained in:
parent
08553e6e0a
commit
0a9330d41d
2 changed files with 62 additions and 8 deletions
|
|
@ -66,6 +66,10 @@ self.kiri.load(api => {
|
|||
};
|
||||
|
||||
function deepMerge(target, source) {
|
||||
// console.log({ target, source });
|
||||
if (!source) {
|
||||
return target;
|
||||
}
|
||||
const result = structuredClone(target);
|
||||
Object.keys(source).forEach((key) => {
|
||||
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
|
||||
|
|
@ -140,7 +144,7 @@ self.kiri.load(api => {
|
|||
|
||||
function printer_render(rec = {}) {
|
||||
$('bbl_rec').value = JSON.stringify(deepSortObject(rec), undefined, 2);
|
||||
let { info, print } = rec;
|
||||
let { info, print, files } = rec;
|
||||
let {
|
||||
ams_status,
|
||||
bed_target_temper,
|
||||
|
|
@ -168,6 +172,15 @@ self.kiri.load(api => {
|
|||
$('bbl_noz_target').value = nozzle_target_temper ?? '';
|
||||
$('bbl_bed_temp').value = bed_temper ?? '';
|
||||
$('bbl_bed_target').value = bed_target_temper ?? '';
|
||||
if (files) {
|
||||
h.bind($('bbl_files'), files.map(file => {
|
||||
return h.option({
|
||||
_: file.name || file,
|
||||
style: "max-width: 20em"
|
||||
});
|
||||
}));
|
||||
rec.files = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function render_list() {
|
||||
|
|
@ -201,6 +214,12 @@ self.kiri.load(api => {
|
|||
socket.stop();
|
||||
}
|
||||
|
||||
function list_files() {
|
||||
if (selected?.rec?.host) {
|
||||
socket.send({ cmd: "files", ...selected.rec });
|
||||
}
|
||||
}
|
||||
|
||||
api.event.on("init-done", function() {
|
||||
if (init) {
|
||||
return;
|
||||
|
|
@ -314,14 +333,15 @@ self.kiri.load(api => {
|
|||
})
|
||||
]),
|
||||
h.div({ class: "t-body t-inset f-col gap3 pad4" }, [
|
||||
h.div({ id: "bbl_files", class: "set-header", onclick() {
|
||||
console.log('reload files');
|
||||
h.div({ class: "set-header", onclick() {
|
||||
console.log('bbl reload files');
|
||||
list_files();
|
||||
} }, h.a({ class: "f-row" }, [
|
||||
h.label('files'),
|
||||
h.span({ class: "fat5 grow" }),
|
||||
h.i({ class: "fa-solid fa-rotate" })
|
||||
])),
|
||||
h.select({ id: "bbl_sel", style: "height: 100%", size: 5 }, []),
|
||||
h.select({ id: "bbl_files", style: "height: 100%", size: 5 }, []),
|
||||
])
|
||||
]),
|
||||
h.div({ class: "set-sep "}),
|
||||
|
|
|
|||
|
|
@ -104,14 +104,12 @@ module.exports = async (server) => {
|
|||
return promise;
|
||||
}
|
||||
|
||||
async function ftp_send(args = {}) {
|
||||
async function ftp_open(args = {}) {
|
||||
const client = new Client();
|
||||
const port = parseInt(args.port || 990);
|
||||
const host = args.host || "localhost";
|
||||
const user = args.user || "bblp";
|
||||
const password = args.password || '';
|
||||
const filename = args.filename || "test.3mf";
|
||||
const data = args.data || undefined;
|
||||
const password = args.password || args.code || '';
|
||||
// client.ftp.verbose = true;
|
||||
try {
|
||||
await client.access({
|
||||
|
|
@ -122,6 +120,17 @@ module.exports = async (server) => {
|
|||
secure: "implicit",
|
||||
secureOptions: { rejectUnauthorized: false }
|
||||
});
|
||||
} catch (err) {
|
||||
util.log({ ftp_error: error });
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
async function ftp_send(args = {}) {
|
||||
const client = await ftp_open(args);
|
||||
const filename = args.filename || "test.3mf";
|
||||
const data = args.data || undefined;
|
||||
try {
|
||||
const readableStream = new Readable();
|
||||
readableStream._read = () => {};
|
||||
readableStream.push(data);
|
||||
|
|
@ -132,6 +141,18 @@ module.exports = async (server) => {
|
|||
}
|
||||
}
|
||||
|
||||
async function ftp_list(args = {}) {
|
||||
const client = await ftp_open(args);
|
||||
const list = [];
|
||||
try {
|
||||
list.push(...(await client.list()));
|
||||
// list.push(...(await client.list("/cache")));
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
function decode_post(req, res, next) {
|
||||
if (req.method === 'POST') {
|
||||
let chunks = [];
|
||||
|
|
@ -243,6 +264,19 @@ module.exports = async (server) => {
|
|||
}));
|
||||
});
|
||||
break;
|
||||
case "files":
|
||||
ftp_list({ host, code }).then(files => {
|
||||
files = files
|
||||
.filter(file => file.name.toLowerCase().endsWith(".3mf"))
|
||||
.map(file => {
|
||||
return {
|
||||
name: file.name,
|
||||
size: file.size
|
||||
};
|
||||
});
|
||||
wsopen.forEach(ws => ws.send(JSON.stringify({ serial, message: { files }})));
|
||||
});
|
||||
break;
|
||||
case "keepalive":
|
||||
// util.log({ keepalive: serial });
|
||||
mcache[serial]?.keepalive();
|
||||
|
|
|
|||
Loading…
Reference in a new issue