mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 18:25:24 +00:00
Removed Promise returning into _patch; Now the catch is done when calling _patch and not inside _patch itself
This commit is contained in:
117
index.js
117
index.js
@@ -106,23 +106,22 @@ class Pass {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this._patch(this._filterOptions(this.overrides), passStructBuffer)
|
try {
|
||||||
.then(function _afterJSONParse(passFileBuffer) {
|
let patchedPass = this._patch(this._filterOptions(this.overrides), passStructBuffer);
|
||||||
manifest["pass.json"] = forge.md.sha1.create().update(passFileBuffer.toString("binary")).digest().toHex();
|
|
||||||
archive.append(passFileBuffer, { name: "pass.json" });
|
|
||||||
|
|
||||||
// no errors happened
|
manifest["pass.json"] = forge.md.sha1.create().update(patchedPass.toString("binary")).digest().toHex();
|
||||||
return passCallback(null);
|
archive.append(patchedPass, { name: "pass.json" });
|
||||||
})
|
|
||||||
.catch(err => {
|
return passCallback();
|
||||||
return passCallback({
|
} catch (e) {
|
||||||
status: false,
|
return passCallback({
|
||||||
error: {
|
status: false,
|
||||||
message: `Unable to read pass.json as buffer @ ${this.model}. Unable to continue.\n${err}`,
|
error: {
|
||||||
ecode: 418
|
message: `Unable to read pass.json as buffer @ ${this.model}. Unable to continue.\n${err}`,
|
||||||
}
|
ecode: 418
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -292,59 +291,54 @@ class Pass {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
_patch(options, passBuffer) {
|
_patch(options, passBuffer) {
|
||||||
|
|
||||||
if (!options) {
|
if (!options) {
|
||||||
return Promise.resolve(passBuffer);
|
return passBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((success, reject) => {
|
let passFile = JSON.parse(passBuffer.toString("utf8"));
|
||||||
try {
|
|
||||||
let passFile = JSON.parse(passBuffer.toString("utf8"));
|
|
||||||
|
|
||||||
// "barcodes" support got introduced in iOS 9 as array of barcode.
|
// "barcodes" support got introduced in iOS 9 as array of barcode.
|
||||||
// "barcode" is still used in older iOS versions
|
// "barcode" is still used in older iOS versions
|
||||||
|
|
||||||
if (passFile["barcode"]) {
|
if (passFile["barcode"]) {
|
||||||
let barcode = passFile["barcode"];
|
let barcode = passFile["barcode"];
|
||||||
|
|
||||||
if (!(barcode instanceof Object) || !schema.isValid(barcode, schema.constants.barcode) || !options.barcode && barcode.message === "") {
|
if (!(barcode instanceof Object) || !schema.isValid(barcode, schema.constants.barcode) || !options.barcode && barcode.message === "") {
|
||||||
console.log("\x1b[41m", `Barcode syntax of the chosen model (${path.parse(this.model).base}) is not correct or the override content was not provided got removed. Please refer to https://apple.co/2myAbst.`, "\x1b[0m");
|
console.log("\x1b[41m", `Barcode syntax of the chosen model (${path.parse(this.model).base}) is not correct or the override content was not provided got removed. Please refer to https://apple.co/2myAbst.`, "\x1b[0m");
|
||||||
delete passFile["barcode"];
|
delete passFile["barcode"];
|
||||||
} else {
|
} else {
|
||||||
// options.barcode may not be defined
|
// options.barcode may not be defined
|
||||||
passFile["barcode"].message = options.barcode || passFile["barcode"].message;
|
passFile["barcode"].message = options.barcode || passFile["barcode"].message;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log("\x1b[33m", `Your pass model (${path.parse(this.model).base}) is not compatible with iOS versions lower than iOS 9. Please refer to https://apple.co/2O5K65k to make it backward-compatible.`, "\x1b[0m");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (passFile["barcodes"] && passFile["barcodes"] instanceof Array) {
|
|
||||||
if (!passFile["barcodes"].length) {
|
|
||||||
console.log("\x1b[33m", `No barcodes support specified. The element got removed.`, "\x1b[0m");
|
|
||||||
delete passFile["barcodes"];
|
|
||||||
}
|
|
||||||
|
|
||||||
passFile["barcodes"].forEach((b,i) => {
|
|
||||||
if (!schema.isValid(b, schema.constants.barcode) && !!options.barcode && b.message !== "") {
|
|
||||||
passFile["barcodes"].splice(i, 1);
|
|
||||||
console.log("\x1b[41m", `Barcode @ index ${i} of the chosen model (${path.parse(this.model).base}) is not well-formed or have syntax errors and got removed. Please refer to https://apple.co/2myAbst.`, "\x1b[0m");
|
|
||||||
} else {
|
|
||||||
// options.barcode may not be defined
|
|
||||||
b.message = options.barcode || b.message;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log("\x1b[33m", `Your pass model (${path.parse(this.model).base}) is not compatible with iOS versions greater than iOS 8. Refer to https://apple.co/2O5K65k to make it forward-compatible.`, "\x1b[0m");
|
|
||||||
}
|
|
||||||
|
|
||||||
delete options["barcode"];
|
|
||||||
|
|
||||||
Object.assign(passFile, options);
|
|
||||||
|
|
||||||
return success(Buffer.from(JSON.stringify(passFile)));
|
|
||||||
} catch(e) {
|
|
||||||
return reject(e);
|
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
console.log("\x1b[33m", `Your pass model (${path.parse(this.model).base}) is not compatible with iOS versions lower than iOS 9. Please refer to https://apple.co/2O5K65k to make it backward-compatible.`, "\x1b[0m");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (passFile["barcodes"] && passFile["barcodes"] instanceof Array) {
|
||||||
|
if (!passFile["barcodes"].length) {
|
||||||
|
console.log("\x1b[33m", `No barcodes support specified. The element got removed.`, "\x1b[0m");
|
||||||
|
delete passFile["barcodes"];
|
||||||
|
}
|
||||||
|
|
||||||
|
passFile["barcodes"].forEach((b,i) => {
|
||||||
|
if (!schema.isValid(b, schema.constants.barcode) && !!options.barcode && b.message !== "") {
|
||||||
|
passFile["barcodes"].splice(i, 1);
|
||||||
|
console.log("\x1b[41m", `Barcode @ index ${i} of the chosen model (${path.parse(this.model).base}) is not well-formed or have syntax errors and got removed. Please refer to https://apple.co/2myAbst.`, "\x1b[0m");
|
||||||
|
} else {
|
||||||
|
// options.barcode may not be defined
|
||||||
|
b.message = options.barcode || b.message;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log("\x1b[33m", `Your pass model (${path.parse(this.model).base}) is not compatible with iOS versions greater than iOS 8. Refer to https://apple.co/2O5K65k to make it forward-compatible.`, "\x1b[0m");
|
||||||
|
}
|
||||||
|
|
||||||
|
delete options["barcode"];
|
||||||
|
|
||||||
|
Object.assign(passFile, options);
|
||||||
|
|
||||||
|
return Buffer.from(JSON.stringify(passFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -386,7 +380,6 @@ class Pass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((success, reject) => {
|
return new Promise((success, reject) => {
|
||||||
|
|
||||||
if (!options.model || typeof options.model !== "string") {
|
if (!options.model || typeof options.model !== "string") {
|
||||||
return reject({
|
return reject({
|
||||||
status: false,
|
status: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user