Added icon reading and setting in scratch example

This commit is contained in:
Alexander Cerutti
2021-10-16 23:41:47 +02:00
parent 408416ab9c
commit 0a6b3f7528

View File

@@ -5,8 +5,13 @@
import app from "./webserver"; import app from "./webserver";
import path from "path"; import path from "path";
import { promises as fs } from "fs";
import { PKPass } from "passkit-generator"; import { PKPass } from "passkit-generator";
const iconFromModel = await fs.readFile(
path.resolve(__dirname, "models/exampleBooking.pass/icon.png"),
);
app.all(async function manageRequest(request, response) { app.all(async function manageRequest(request, response) {
const passName = const passName =
request.params.modelName + request.params.modelName +
@@ -56,6 +61,16 @@ app.all(async function manageRequest(request, response) {
}, },
); );
/**
* Required by Apple. If one is not available, a
* pass might be openable on a Mac but not on a
* specific iPhone model
*/
pass.addBuffer("icon.png", iconFromModel);
pass.addBuffer("icon@2x.png", iconFromModel);
pass.addBuffer("icon@3x.png", iconFromModel);
const stream = pass.getAsStream(); const stream = pass.getAsStream();
response.set({ response.set({