mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 17:25:21 +00:00
Moved pass types into _validateType
This commit is contained in:
12
index.js
12
index.js
@@ -6,10 +6,14 @@ const async = require("async");
|
|||||||
const stream = require("stream");
|
const stream = require("stream");
|
||||||
const schema = require("./schema.js");
|
const schema = require("./schema.js");
|
||||||
|
|
||||||
|
const util = require("util");
|
||||||
|
|
||||||
|
const readdir = util.promisify(fs.readdir);
|
||||||
|
const readFile = util.promisify(fs.readFile);
|
||||||
|
|
||||||
class Pass {
|
class Pass {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.passTypes = ["boardingPass", "eventTicket", "coupon", "generic", "storeCard"];
|
|
||||||
this.overrides = this.options.overrides || {};
|
this.overrides = this.options.overrides || {};
|
||||||
this.Certificates = {};
|
this.Certificates = {};
|
||||||
this.model = "";
|
this.model = "";
|
||||||
@@ -205,15 +209,17 @@ class Pass {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
_validateType(passBuffer) {
|
_validateType(passBuffer) {
|
||||||
|
let passTypes = ["boardingPass", "eventTicket", "coupon", "generic", "storeCard"];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let passFile = JSON.parse(passBuffer.toString("utf8"));
|
let passFile = JSON.parse(passBuffer.toString("utf8"));
|
||||||
let index = this.passTypes.findIndex(passType => passFile.hasOwnProperty(passType));
|
let index = passTypes.findIndex(passType => passFile.hasOwnProperty(passType));
|
||||||
|
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let type = this.passTypes[index];
|
let type = passTypes[index];
|
||||||
return schema.isValid(passFile[type], schema.constants[(type === "boardingPass" ? "boarding" : "basic") + "Structure"]);
|
return schema.isValid(passFile[type], schema.constants[(type === "boardingPass" ? "boarding" : "basic") + "Structure"]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user