@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.
141 lines (140 loc) • 3.97 kB
JavaScript
import "../printer-api.interface.js";
import { errorSummary } from "../../utils/error.utils.js";
import { captureException } from "@sentry/node";
//#region src/services/core/batch-call.service.ts
var BatchCallService = class BatchCallService {
logger;
constructor(loggerFactory, printerApiFactory, printerCache, printerSocketStore, printerService) {
this.printerApiFactory = printerApiFactory;
this.printerCache = printerCache;
this.printerSocketStore = printerSocketStore;
this.printerService = printerService;
this.logger = loggerFactory(BatchCallService.name);
}
getPrinter(login) {
return this.printerApiFactory.getScopedPrinter(login);
}
async batchTogglePrintersEnabled(printerIds, enabled) {
const promises = [];
for (const printerId of printerIds) {
let promise = void 0;
const printerDto = await this.printerCache.getValue(printerId);
if (!printerDto) continue;
const time = Date.now();
if (enabled) {
if (!printerDto.enabled && !printerDto.disabledReason?.length) promise = this.printerService.updateEnabled(printerId, true).then(() => {
return {
success: true,
printerId,
time: Date.now() - time
};
}).catch((e) => {
return {
failure: true,
error: e.message,
printerId,
time: Date.now() - time
};
});
} else if (printerDto.enabled) promise = this.printerService.updateEnabled(printerId, false).then(() => {
return {
success: true,
printerId,
time: Date.now() - time
};
}).catch((e) => {
return {
failure: true,
error: e.message,
printerId,
time: Date.now() - time
};
});
else this.logger.warn("Did not toggle printer enabled, its in maintenance");
if (promise) promises.push(promise);
}
return await Promise.all(promises);
}
batchConnectSocket(printerIds) {
for (const printerId of printerIds) try {
this.printerSocketStore.reconnectPrinterAdapter(printerId);
} catch (e) {
captureException(e);
this.logger.error(`Error setting socket to reconnect ${errorSummary(e)}`);
}
}
async batchConnectUsb(printerIds) {
const promises = [];
for (const printerId of printerIds) {
const login = await this.printerCache.getLoginDtoAsync(printerId);
const time = Date.now();
const promise = this.getPrinter(login).connect().then(() => {
return {
success: true,
printerId,
time: Date.now() - time
};
}).catch((e) => {
return {
failure: true,
error: e.message,
printerId,
time: Date.now() - time
};
});
promises.push(promise);
}
return await Promise.all(promises);
}
async getBatchPrinterReprintFile(printerIds) {
const promises = [];
for (const printerId of printerIds) {
const promise = new Promise(async (resolve, _) => {
try {
const login = await this.printerCache.getLoginDtoAsync(printerId);
return resolve({
...await this.getPrinter(login).getReprintState(),
printerId
});
} catch (e) {
captureException(e);
return resolve({
connectionState: null,
printerId,
reprintState: 0
});
}
});
promises.push(promise);
}
return await Promise.all(promises);
}
async batchReprintCalls(printerIdFileList) {
const promises = [];
for (const printerIdFile of printerIdFileList) {
const { printerId, path } = printerIdFile;
const login = await this.printerCache.getLoginDtoAsync(printerId);
const time = Date.now();
const promise = this.getPrinter(login).startPrint(path).then(() => {
return {
success: true,
printerId,
time: Date.now() - time
};
}).catch((e) => {
captureException(e);
return {
failure: true,
error: e.message,
printerId,
time: Date.now() - time
};
});
promises.push(promise);
}
return await Promise.all(promises);
}
};
//#endregion
export { BatchCallService };
//# sourceMappingURL=batch-call.service.js.map