From 1ca53adc4debeb67d9a65797ffabd90841de8c21 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Sat, 17 Nov 2018 23:27:09 +0100 Subject: [PATCH] Added working example for load --- examples/download.js | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 examples/download.js diff --git a/examples/download.js b/examples/download.js new file mode 100644 index 0000000..ca63389 --- /dev/null +++ b/examples/download.js @@ -0,0 +1,60 @@ +/** + * .void() and .expiration() methods example + * To check if a ticket is void, look at the barcode; + * If it is grayed, the ticket is voided. May not be showed on macOS. + * + * To check if a ticket has an expiration date, you'll + * have to wait two minutes. + */ + +const app = require("./webserver"); +const { Pass } = require(".."); + +app.all(function manageRequest(request, response) { + let passName = request.params.modelName + "_" + (new Date()).toISOString().split('T')[0].replace(/-/ig, ""); + + let pass = new Pass({ + model: `./models/${request.params.modelName}`, + certificates: { + wwdr: "../certificates/WWDR.pem", + signerCert: "../certificates/signerCert.pem", + signerKey: { + keyFile: "../certificates/signerKey.pem", + passphrase: "123456" + } + }, + overrides: request.body || request.params || request.query, + }); + + pass.load("https://s.gravatar.com/avatar/83cd11399b7ea79977bc302f3931ee52?size=32&default=retro", "icon.png"); + pass.load("https://s.gravatar.com/avatar/83cd11399b7ea79977bc302f3931ee52?size=64&default=retro", "icon@2x.png"); + + // This to import them directly in the localization folder + /* + pass.load("https://s.gravatar.com/avatar/83cd11399b7ea79977bc302f3931ee52?size=32&default=retro", "en.lproj/icon.png"); + pass.load("https://s.gravatar.com/avatar/83cd11399b7ea79977bc302f3931ee52?size=64&default=retro", "en.lproj/icon@2x.png"); + + pass.localize("en", { + "EVENT": "Event", + "LOCATION": "Location" + }); + */ + + pass.generate().then(function (stream) { + response.set({ + "Content-type": "application/vnd.apple.pkpass", + "Content-disposition": `attachment; filename=${passName}.pkpass` + }); + + stream.pipe(response); + }).catch(err => { + + console.log(err); + + response.set({ + "Content-type": "text/html", + }); + + response.send(err.message); + }); +});