Explorar el Código

[ADD] doc format rejection

robert hace 6 años
padre
commit
8366697b38
Se han modificado 2 ficheros con 18 adiciones y 2 borrados
  1. 1 1
      package.json
  2. 17 1
      src/print.js

+ 1 - 1
package.json

@@ -1,7 +1,7 @@
 {
   "name": "printers-tray",
   "productName": "PrintersTray",
-  "version": "1.0.3",
+  "version": "1.0.4",
   "description": "Printers Tray",
   "main": "src/index.js",
   "scripts": {

+ 17 - 1
src/print.js

@@ -1,5 +1,5 @@
 import UUID from 'uuid/v4'
-import { printDirect, getPrinters, getDefaultPrinterName, getJob, getSupportedJobCommands, getSupportedPrintFormats } from 'printer'
+import { printDirect, getPrinters, getDefaultPrinterName, getJob, getSupportedPrintFormats } from 'printer'
 
 const REQUEST_PRINTER_NAME = 'request_printer_name'
 const SHOW_PRINT_STATUS = 'show_print_status'
@@ -104,6 +104,22 @@ const doPrint = (socket, request) => {
     }
 
     let format = getFormat(mimeTypeRegex[0])
+
+    const supportedFormats = getSupportedPrintFormats(request.printer)
+
+    if (!supportedFormats.includes(format)) {
+        socket.emit(SHOW_PRINT_STATUS, {
+            status: 'error',
+            printer: request.printer,
+            cause: {
+                id: 'unsupported_format',
+                error: null
+            }
+        })
+
+        return;
+    }
+
     let buffer = Buffer.from(data, 'base64')
 
     printDirect({