@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.
122 lines (121 loc) • 4.13 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "OctoprintApi", {
enumerable: true,
get: function() {
return OctoprintApi;
}
});
const _printerapiinterface = require("./printer-api.interface");
const _runtimeexceptions = require("../exceptions/runtime.exceptions");
class OctoprintApi {
printerLogin;
client;
constructor(octoprintClient, printerLogin){
this.printerLogin = printerLogin;
this.client = octoprintClient;
}
get type() {
return _printerapiinterface.OctoprintType;
}
get login() {
return this.printerLogin;
}
set login(login) {
this.printerLogin = login;
}
async getVersion() {
const result = await this.client.getApiVersion(this.login);
return result.data?.server;
}
async connect() {
await this.client.sendConnectionCommand(this.login, this.client.connectCommand);
}
async disconnect() {
await this.client.sendConnectionCommand(this.login, this.client.disconnectCommand);
}
async restartServer() {
await this.client.postServerRestartCommand(this.login);
}
async restartHost() {
throw new _runtimeexceptions.NotImplementedException();
}
async restartPrinterFirmware() {
throw new _runtimeexceptions.NotImplementedException();
}
async startPrint(filePath) {
await this.client.postSelectPrintFile(this.login, filePath, true);
}
async pausePrint() {
await this.client.sendJobCommand(this.login, this.client.pauseJobCommand);
}
async resumePrint() {
await this.client.sendJobCommand(this.login, this.client.resumeJobCommand);
}
async cancelPrint() {
await this.client.sendJobCommand(this.login, this.client.cancelJobCommand);
}
async sendGcode(script) {
await this.client.sendCustomGCodeCommand(this.login, script);
}
async quickStop() {
await this.client.sendCustomGCodeCommand(this.login, "M112");
}
async movePrintHead(amounts) {
await this.client.sendPrintHeadJogCommand(this.login, amounts);
}
async homeAxes(axes) {
await this.client.sendPrintHeadHomeCommand(this.login, axes);
}
async getFile(path) {
return this.client.getFile(this.login, path);
}
async getFiles() {
const files = await this.client.getLocalFiles(this.login, false);
return files.map((f)=>({
path: f.path,
size: f.size,
date: f.date
}));
}
async downloadFile(path) {
return await this.client.downloadFile(this.login, path);
}
async getFileChunk(path, startBytes, endBytes) {
return await this.client.getFileChunk(this.login, path, startBytes, endBytes);
}
async uploadFile(fileOrBuffer, startPrint, uploadToken) {
await this.client.uploadFileAsMultiPart(this.login, fileOrBuffer, startPrint, uploadToken);
}
async deleteFile(path) {
await this.client.deleteFileOrFolder(this.login, path);
}
async deleteFolder(path) {
await this.client.deleteFileOrFolder(this.login, path);
}
async getSettings() {
const response = await this.client.getSettings(this.login);
return response.data;
}
async getReprintState() {
const connectedResponse = await this.client.getConnection(this.login);
const connectionState = connectedResponse.data.current?.state;
const selectedJobResponse = await this.client.getJob(this.login);
const selectedJob = selectedJobResponse.data;
const currentJobFile = selectedJob?.job?.file;
if (!currentJobFile?.path) {
return {
connectionState,
reprintState: _printerapiinterface.ReprintState.NoLastPrint
};
}
return {
connectionState,
file: currentJobFile,
reprintState: _printerapiinterface.ReprintState.LastPrintReady
};
}
}
//# sourceMappingURL=octoprint.api.js.map