2018-12-20 15:45:23 +01:00
/ * *
* @ author j433866 [ j433866 @ gmail . com ]
* @ copyright Crown Copyright 2018
* @ license Apache - 2.0
* /
import Operation from "../Operation" ;
import OperationError from "../errors/OperationError" ;
import Magic from "../lib/Magic" ;
2019-03-07 14:21:26 +01:00
import { parseQrCode } from "../lib/QRCode" ;
2018-12-20 15:45:23 +01:00
/ * *
* Parse QR Code operation
* /
class ParseQRCode extends Operation {
/ * *
* ParseQRCode constructor
* /
constructor ( ) {
super ( ) ;
this . name = "Parse QR Code" ;
this . module = "Image" ;
2018-12-25 22:54:38 +01:00
this . description = "Reads an image file and attempts to detect and read a Quick Response (QR) code from the image.<br><br><u>Normalise Image</u><br>Attempts to normalise the image before parsing it to improve detection of a QR code." ;
2018-12-20 15:45:23 +01:00
this . infoURL = "https://wikipedia.org/wiki/QR_code" ;
this . inputType = "byteArray" ;
this . outputType = "string" ;
2018-12-21 12:24:31 +01:00
this . args = [
{
"name" : "Normalise image" ,
"type" : "boolean" ,
2018-12-25 22:54:38 +01:00
"value" : false
2018-12-21 12:24:31 +01:00
}
] ;
2018-12-20 15:45:23 +01:00
}
/ * *
* @ param { byteArray } input
* @ param { Object [ ] } args
* @ returns { string }
* /
async run ( input , args ) {
2018-12-21 12:24:31 +01:00
const [ normalise ] = args ;
2019-03-07 14:21:26 +01:00
const type = Magic . magicFileType ( input ) ;
2018-12-25 22:54:38 +01:00
2019-03-07 14:21:26 +01:00
if ( ! type || type . mime . indexOf ( "image" ) !== 0 ) {
2018-12-20 15:45:23 +01:00
throw new OperationError ( "Invalid file type." ) ;
}
2019-03-07 14:21:26 +01:00
return await parseQrCode ( input , normalise ) ;
2018-12-20 15:45:23 +01:00
}
}
export default ParseQRCode ;