mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 21:25:26 +00:00
Updated examples
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* examples, creation through templates is already shown
|
||||
*/
|
||||
|
||||
import app from "./webserver";
|
||||
import app, { getCertificates } from "./webserver";
|
||||
import path from "path";
|
||||
import { promises as fs } from "fs";
|
||||
import { PKPass } from "passkit-generator";
|
||||
@@ -62,7 +62,11 @@ async function readDirectory(filePath: string) {
|
||||
|
||||
return dirContent.map(async (fileName) => {
|
||||
const content = await fs.readFile(path.resolve(filePath, fileName));
|
||||
return getObjectFromModelFile(filePath, content, 1);
|
||||
return getObjectFromModelFile(
|
||||
path.resolve(filePath, fileName),
|
||||
content,
|
||||
2,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -70,42 +74,43 @@ async function readDirectory(filePath: string) {
|
||||
// *** EXAMPLE FROM NOW ON *** //
|
||||
// *************************** //
|
||||
|
||||
/**
|
||||
* Reading model before answering. Maybe we need to do
|
||||
* something else with it.
|
||||
*/
|
||||
const passTemplate = new Promise<PKPass>(async (resolve) => {
|
||||
const modelPath = path.resolve(__dirname, `../models/examplePass.pass`);
|
||||
const [modelFilesList, certificates] = await Promise.all([
|
||||
fs.readdir(modelPath),
|
||||
getCertificates(),
|
||||
]);
|
||||
|
||||
const modelPath = path.resolve(__dirname, `../models/examplePass.pass`);
|
||||
const modelRecords = (
|
||||
await Promise.all(
|
||||
/**
|
||||
* Obtaining flattened array of buffer records
|
||||
* containing file name and the buffer itself.
|
||||
*
|
||||
* This goes also to read every nested l10n
|
||||
* subfolder.
|
||||
*/
|
||||
|
||||
const modelFilesList = await fs.readdir(modelPath);
|
||||
modelFilesList.map((fileOrDirectoryPath) => {
|
||||
const fullPath = path.resolve(modelPath, fileOrDirectoryPath);
|
||||
|
||||
const modelRecords = (
|
||||
await Promise.all(
|
||||
/**
|
||||
* Obtaining flattened array of buffer records
|
||||
* containing file name and the buffer itself.
|
||||
*
|
||||
* This goes also to read every nested l10n
|
||||
* subfolder.
|
||||
*/
|
||||
|
||||
modelFilesList.map((fileOrDirectoryPath) => {
|
||||
const fullPath = path.resolve(modelPath, fileOrDirectoryPath);
|
||||
|
||||
return readFileOrDirectory(fullPath);
|
||||
}),
|
||||
return readFileOrDirectory(fullPath);
|
||||
}),
|
||||
)
|
||||
)
|
||||
)
|
||||
.flat(1)
|
||||
.reduce((acc, current) => ({ ...acc, ...current }), {});
|
||||
.flat(1)
|
||||
.reduce((acc, current) => ({ ...acc, ...current }), {});
|
||||
|
||||
/** Creating a PKPass Template */
|
||||
/** Creating a PKPass Template */
|
||||
|
||||
const templatePass = new PKPass(modelRecords, {
|
||||
wwdr: path.resolve(__dirname, "../../certificates/WWDR.pem"),
|
||||
signerCert: path.resolve(__dirname, "../../certificates/signerCert.pem"),
|
||||
signerKey: path.resolve(__dirname, "../../certificates/signerKey.pem"),
|
||||
signerKeyPassphrase: "123456",
|
||||
return resolve(
|
||||
new PKPass(modelRecords, {
|
||||
wwdr: certificates.wwdr,
|
||||
signerCert: certificates.signerCert,
|
||||
signerKey: certificates.signerKey,
|
||||
signerKeyPassphrase: certificates.signerKeyPassphrase,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
app.all(async function manageRequest(request, response) {
|
||||
@@ -114,6 +119,8 @@ app.all(async function manageRequest(request, response) {
|
||||
"_" +
|
||||
new Date().toISOString().split("T")[0].replace(/-/gi, "");
|
||||
|
||||
const templatePass = await passTemplate;
|
||||
|
||||
try {
|
||||
const pass = await PKPass.from(
|
||||
templatePass,
|
||||
|
||||
Reference in New Issue
Block a user