ebanutsya

This commit is contained in:
2023-10-28 08:08:37 +03:00
parent 37d3fb5a78
commit 0bc1835405
19 changed files with 435 additions and 180 deletions

View File

@@ -0,0 +1,34 @@
import axios from "axios";
class PrintingService {
private static instance: PrintingService | null = null;
private readonly apiUrl: string;
private readonly port: number;
public static getInstance(port?: number): PrintingService {
if (!this.instance) {
this.instance = new PrintingService(port);
}
return this.instance;
}
private constructor(port = 2282) {
this.apiUrl = "127.0.0.1";
this.port = port;
}
private async print(printer: string, type: string, bytes: Uint8Array): Promise<string> {
let response = await axios.post(`http://${this.apiUrl}:${this.port}/print/${printer}/${type}`, bytes.buffer);
return response.data;
}
public async printPdf(printer: string, pdfBytes: Uint8Array): Promise<string> {
return this.print(printer, "pdf", pdfBytes);
}
public async printImage(printer: string, imageBytes: Uint8Array): Promise<string> {
return this.print(printer, "image", imageBytes);
}
}
export default PrintingService;