add bbl file fetch from ui

This commit is contained in:
Stewart Allen 2025-01-29 00:35:56 -05:00
commit 0a9330d41d
2 changed files with 62 additions and 8 deletions

View file

@ -66,6 +66,10 @@ self.kiri.load(api => {
}; };
function deepMerge(target, source) { function deepMerge(target, source) {
// console.log({ target, source });
if (!source) {
return target;
}
const result = structuredClone(target); const result = structuredClone(target);
Object.keys(source).forEach((key) => { Object.keys(source).forEach((key) => {
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) { if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
@ -140,7 +144,7 @@ self.kiri.load(api => {
function printer_render(rec = {}) { function printer_render(rec = {}) {
$('bbl_rec').value = JSON.stringify(deepSortObject(rec), undefined, 2); $('bbl_rec').value = JSON.stringify(deepSortObject(rec), undefined, 2);
let { info, print } = rec; let { info, print, files } = rec;
let { let {
ams_status, ams_status,
bed_target_temper, bed_target_temper,
@ -168,6 +172,15 @@ self.kiri.load(api => {
$('bbl_noz_target').value = nozzle_target_temper ?? ''; $('bbl_noz_target').value = nozzle_target_temper ?? '';
$('bbl_bed_temp').value = bed_temper ?? ''; $('bbl_bed_temp').value = bed_temper ?? '';
$('bbl_bed_target').value = bed_target_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() { function render_list() {
@ -201,6 +214,12 @@ self.kiri.load(api => {
socket.stop(); socket.stop();
} }
function list_files() {
if (selected?.rec?.host) {
socket.send({ cmd: "files", ...selected.rec });
}
}
api.event.on("init-done", function() { api.event.on("init-done", function() {
if (init) { if (init) {
return; return;
@ -314,14 +333,15 @@ self.kiri.load(api => {
}) })
]), ]),
h.div({ class: "t-body t-inset f-col gap3 pad4" }, [ h.div({ class: "t-body t-inset f-col gap3 pad4" }, [
h.div({ id: "bbl_files", class: "set-header", onclick() { h.div({ class: "set-header", onclick() {
console.log('reload files'); console.log('bbl reload files');
list_files();
} }, h.a({ class: "f-row" }, [ } }, h.a({ class: "f-row" }, [
h.label('files'), h.label('files'),
h.span({ class: "fat5 grow" }), h.span({ class: "fat5 grow" }),
h.i({ class: "fa-solid fa-rotate" }) 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 "}), h.div({ class: "set-sep "}),

View file

@ -104,14 +104,12 @@ module.exports = async (server) => {
return promise; return promise;
} }
async function ftp_send(args = {}) { async function ftp_open(args = {}) {
const client = new Client(); const client = new Client();
const port = parseInt(args.port || 990); const port = parseInt(args.port || 990);
const host = args.host || "localhost"; const host = args.host || "localhost";
const user = args.user || "bblp"; const user = args.user || "bblp";
const password = args.password || ''; const password = args.password || args.code || '';
const filename = args.filename || "test.3mf";
const data = args.data || undefined;
// client.ftp.verbose = true; // client.ftp.verbose = true;
try { try {
await client.access({ await client.access({
@ -122,6 +120,17 @@ module.exports = async (server) => {
secure: "implicit", secure: "implicit",
secureOptions: { rejectUnauthorized: false } 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(); const readableStream = new Readable();
readableStream._read = () => {}; readableStream._read = () => {};
readableStream.push(data); 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) { function decode_post(req, res, next) {
if (req.method === 'POST') { if (req.method === 'POST') {
let chunks = []; let chunks = [];
@ -243,6 +264,19 @@ module.exports = async (server) => {
})); }));
}); });
break; 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": case "keepalive":
// util.log({ keepalive: serial }); // util.log({ keepalive: serial });
mcache[serial]?.keepalive(); mcache[serial]?.keepalive();