@fdm-monster/server
Version:
FDM Monster is a bulk OctoPrint manager to set up, configure and monitor 3D printers. Our aim is to provide extremely optimized websocket performance and reliability.
160 lines (159 loc) • 5.2 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "MoonrakerApi", {
enumerable: true,
get: function() {
return MoonrakerApi;
}
});
const _printerapiinterface = require("./printer-api.interface");
const _runtimeexceptions = require("../exceptions/runtime.exceptions");
class MoonrakerApi {
printerLogin;
client;
constructor(moonrakerClient, printerLogin){
this.printerLogin = printerLogin;
this.client = moonrakerClient;
}
get type() {
return _printerapiinterface.MoonrakerType;
}
set login(login) {
this.printerLogin = login;
}
get login() {
return this.printerLogin;
}
async getVersion() {
const result = await this.client.getApiVersion(this.login);
return result.data?.server;
}
async connect() {
throw new _runtimeexceptions.NotImplementedException();
}
async disconnect() {
throw new _runtimeexceptions.NotImplementedException();
}
async restartServer() {
await this.client.postRestartServer(this.login);
}
async restartHost() {
await this.client.postHostRestart(this.login);
}
async restartPrinterFirmware() {
await this.client.postFirmwareRestart(this.login);
}
async startPrint(filename) {
await this.client.postPrintStart(this.login, filename);
}
async pausePrint() {
await this.client.postPrintPause(this.login);
}
async resumePrint() {
await this.client.postPrintResume(this.login);
}
async cancelPrint() {
await this.client.postPrintCancel(this.login);
}
async sendGcode(script) {
await this.client.postGcodeScript(this.login, script);
}
async quickStop() {
await this.client.postQuickStop(this.login);
}
async movePrintHead(amounts) {
const setSpeed = !!amounts.speed ? amounts.speed : 10;
let g1CommandAxes = "";
if (!Number.isNaN(amounts.x)) {
g1CommandAxes += ` X${amounts.x}`;
}
if (!Number.isNaN(amounts.y)) {
g1CommandAxes += ` Y${amounts.y}`;
}
if (!Number.isNaN(amounts.z)) {
g1CommandAxes += ` Z${amounts.z}`;
}
await this.client.postGcodeScript(this.login, `
G91
G1 ${g1CommandAxes} F${setSpeed}
G90`);
}
async getFile(path) {
const metadata = await this.client.getServerFileMetadata(this.login, path);
const file = metadata.data.result;
return {
size: file.size,
path,
date: file.modified
};
}
async getFiles() {
const files = await this.client.getServerFilesList(this.login);
return files.data.result.map((f)=>({
size: f.size,
path: f.path,
date: f.modified
}));
}
async homeAxes(axes) {
let homeCommand = `G28`;
if (!!axes.x) {
homeCommand += ` X`;
}
if (!!axes.y) {
homeCommand += ` Y`;
}
if (!!axes.z) {
homeCommand += ` Z`;
}
await this.client.postGcodeScript(this.login, homeCommand);
}
async downloadFile(path) {
return await this.client.getServerFilesDownload(this.login, "gcodes", path);
}
async getFileChunk(path, startBytes, endBytes) {
return await this.client.getServerFilesDownloadChunk(this.login, "gcodes", path, startBytes, endBytes);
}
async uploadFile(fileOrBuffer, startPrint, uploadToken) {
await this.client.postServerFileUpload(this.login, fileOrBuffer, startPrint, uploadToken);
}
async deleteFile(path) {
await this.client.deleteServerFile(this.login, "gcodes", path);
}
async deleteFolder(path) {
await this.client.deleteServerFilesDirectory(this.login, path, false);
}
async getSettings() {
const result = await this.client.getServerConfig(this.login);
return result.data?.result;
}
async getReprintState() {
const response = await this.client.getPrinterObjectsQuery(this.login, {
print_stats: [],
webhooks: []
});
const result = response.data.result;
const operational = result.status.webhooks.state === "ready";
const response2 = await this.client.getServerHistoryList(this.login, 5, 0);
const jobs = (response2.data?.result.jobs ?? []).sort((a, b)=>a.start_time > b.start_time ? 1 : 0);
if (jobs.length === 0 || !operational) {
return {
connectionState: operational ? "Operational" : "Error",
reprintState: _printerapiinterface.ReprintState.NoLastPrint
};
}
const job = jobs[0];
return {
connectionState: "Operational",
reprintState: _printerapiinterface.ReprintState.LastPrintReady,
file: {
date: job.start_time,
path: job.filename,
size: job.metadata.size
}
};
}
}
//# sourceMappingURL=moonraker.api.js.map