ebanutsya
This commit is contained in:
34
src/utils/PrintingService.ts
Normal file
34
src/utils/PrintingService.ts
Normal 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;
|
||||
Reference in New Issue
Block a user