From 2070e1a96b2739e54e1763743d5ca82f3a7ae9bc Mon Sep 17 00:00:00 2001 From: j433866 Date: Wed, 19 Dec 2018 13:27:45 +0000 Subject: [PATCH] Add new Generate QR Code module --- src/core/config/Categories.json | 1 + src/core/operations/GenerateQRCode.mjs | 47 ++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/core/operations/GenerateQRCode.mjs diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index e9fe339..d7ec0d8 100755 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -351,6 +351,7 @@ "Generate UUID", "Generate TOTP", "Generate HOTP", + "Generate QR Code", "Haversine distance", "Render Image", "Remove EXIF", diff --git a/src/core/operations/GenerateQRCode.mjs b/src/core/operations/GenerateQRCode.mjs new file mode 100644 index 0000000..94cb67b --- /dev/null +++ b/src/core/operations/GenerateQRCode.mjs @@ -0,0 +1,47 @@ +/** + * @author j433866 [j433866@gmail.com] + * @copyright Crown Copyright 2018 + * @license Apache-2.0 + */ + +import Operation from "../Operation"; +import OperationError from "../errors/OperationError"; +import qr from "qr-image"; + + +/** + * Generate QR Code operation + */ +class GenerateQRCode extends Operation { + + /** + * GenerateQRCode constructor + */ + constructor() { + super(); + + this.name = "Generate QR Code"; + this.module = "Default"; + this.description = "Generates a QR code from text."; + this.infoURL = "https://en.wikipedia.org/wiki/QR_code"; + this.inputType = "string"; + this.outputType = "byteArray"; + this.args = []; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {File} + */ + run(input, args) { + const qrImage = new Buffer(qr.imageSync(input, { type : "png" })); + if (qrImage == null) { + return [input]; + } + return [...qrImage]; + } + +} + +export default GenerateQRCode;