mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 22:25:24 +00:00
Added first untested and incomplete implementation of PKPass.from
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import FieldsArray from "../src/fieldsArray";
|
import FieldsArray from "../src/fieldsArray";
|
||||||
import { Certificates } from "../src/schemas";
|
import { Certificates } from "../src/schemas";
|
||||||
import { default as Bundle, filesSymbol } from "./Bundle";
|
import { default as Bundle, filesSymbol } from "./Bundle";
|
||||||
|
import { getModelFolderContents } from "./parser";
|
||||||
|
|
||||||
const fieldKeysPoolSymbol = Symbol("fieldKeysPoolSymbol");
|
const fieldKeysPoolSymbol = Symbol("fieldKeysPoolSymbol");
|
||||||
|
|
||||||
@@ -16,6 +17,47 @@ export class PKPass extends Bundle {
|
|||||||
public headerFields /******/ = new FieldsArray(this[fieldKeysPoolSymbol]);
|
public headerFields /******/ = new FieldsArray(this[fieldKeysPoolSymbol]);
|
||||||
public backFields /********/ = new FieldsArray(this[fieldKeysPoolSymbol]);
|
public backFields /********/ = new FieldsArray(this[fieldKeysPoolSymbol]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Either create a pass from another one
|
||||||
|
* or a disk path.
|
||||||
|
*
|
||||||
|
* @param source
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
|
||||||
|
static async from(source: PKPass | string): Promise<PKPass> {
|
||||||
|
let certificates: Certificates = undefined;
|
||||||
|
let buffers: NamedBuffers = undefined;
|
||||||
|
|
||||||
|
if (source instanceof PKPass) {
|
||||||
|
/** Cloning is happening here */
|
||||||
|
certificates = source.certificates;
|
||||||
|
buffers = {};
|
||||||
|
|
||||||
|
const buffersEntries = Object.entries(source[filesSymbol]);
|
||||||
|
|
||||||
|
/** Cloning all the buffers to prevent unwanted edits */
|
||||||
|
for (let i = 0; i < buffersEntries.length; i++) {
|
||||||
|
const [fileName, contentBuffer] = buffersEntries[i];
|
||||||
|
|
||||||
|
buffers[fileName] = Buffer.from(contentBuffer);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/** Disk model reading is happening here */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @TODO Rename bundles in something else.
|
||||||
|
* @TODO determine how to use localized files
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { bundle, l10nBundle } = await getModelFolderContents(source);
|
||||||
|
|
||||||
|
buffers = bundle;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PKPass(buffers, certificates);
|
||||||
|
}
|
||||||
|
|
||||||
constructor(buffers: NamedBuffers, certificates: Certificates) {
|
constructor(buffers: NamedBuffers, certificates: Certificates) {
|
||||||
super("application/vnd.apple.pkpass");
|
super("application/vnd.apple.pkpass");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user