@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.
115 lines (114 loc) • 3.44 kB
JavaScript
import { uploadFileInputSchema } from "./printer-api.interface.js";
import { NotImplementedException } from "../exceptions/runtime.exceptions.js";
//#region src/services/octoprint.api.ts
var OctoprintApi = class {
client;
constructor(octoprintClient, printerLogin) {
this.printerLogin = printerLogin;
this.client = octoprintClient;
}
get type() {
return 0;
}
get login() {
return this.printerLogin;
}
set login(login) {
this.printerLogin = login;
}
async getVersion() {
return (await this.client.getApiVersion(this.login)).data?.server;
}
async validateConnection() {
await this.getVersion();
}
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 NotImplementedException();
}
async restartPrinterFirmware() {
throw new 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(recursive = false, startDir = "") {
const items = await this.client.getLocalFiles(this.login, recursive, startDir);
return {
dirs: items.filter((f) => f.dir),
files: items.filter((f) => !f.dir)
};
}
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(input) {
const validated = uploadFileInputSchema.parse(input);
await this.client.uploadFileAsMultiPart(this.login, validated.stream, validated.fileName, validated.contentLength, validated.startPrint, validated.uploadToken);
}
async deleteFile(path) {
await this.client.deleteFileOrFolder(this.login, path);
}
async deleteFolder(path) {
await this.client.deleteFileOrFolder(this.login, path);
}
async getSettings() {
return (await this.client.getSettings(this.login)).data;
}
async getReprintState() {
const connectionState = (await this.client.getConnection(this.login)).data.current?.state;
const currentJobFile = (await this.client.getJob(this.login)).data?.job?.file;
if (!currentJobFile?.path) return {
connectionState,
reprintState: 1
};
return {
connectionState,
file: {
path: currentJobFile.path,
size: currentJobFile.size,
date: currentJobFile.date,
dir: false
},
reprintState: 2
};
}
};
//#endregion
export { OctoprintApi };
//# sourceMappingURL=octoprint.api.js.map