UNPKG

@fdm-monster/server

Version:

FDM Monster is a bulk OctoPrint, Klipper, PrusaLink and BambuLab manager to set up, configure and monitor 3D printers. Our aim is to provide neat overview over your farm.

49 lines (48 loc) 1.28 kB
//#region src/services/octoprint/utils/file.utils.ts function normalizePrinterFile(file) { if (!file) throw new Error("File should not be null for normalization"); const keys = Object.keys(file); const fileCopy = { ...file }; const knownKeys = [ "path", "date", "hash", "size" ]; const unknownKeys = keys.filter((k) => !knownKeys.includes(k)); const customData = {}; for (const unknownKey of unknownKeys) { customData[unknownKey] = fileCopy[unknownKey]; delete fileCopy[unknownKey]; } return { path: fileCopy.path, size: fileCopy.size, date: fileCopy.date, dir: fileCopy.type === "folder" }; } function flattenOctoPrintFiles(items, parentPath = "") { const files = []; for (const item of items) { const fullPath = parentPath ? `${parentPath}/${item.name}` : item.name; if (item.type === "folder") { files.push({ path: fullPath, size: 0, date: item.date || null, dir: true }); if (item.children) files.push(...flattenOctoPrintFiles(item.children, fullPath)); } else if (item.type === "machinecode") files.push({ path: fullPath, size: item.size, date: item.date, dir: false }); } return files; } //#endregion export { flattenOctoPrintFiles, normalizePrinterFile }; //# sourceMappingURL=file.utils.js.map