ardasen commited on
Commit
6863f93
·
verified ·
1 Parent(s): 352a903

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.json +14 -0
  2. index.js +130 -0
  3. package-lock.json +0 -0
  4. package.json +17 -0
app.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "expo": {
3
+ "name": "server",
4
+ "slug": "server",
5
+ "version": "1.0.0",
6
+ "description": "",
7
+ "sdkVersion": "49.0.0",
8
+ "platforms": [
9
+ "ios",
10
+ "android",
11
+ "web"
12
+ ]
13
+ }
14
+ }
index.js ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+ const crypto = require('crypto');
4
+ const fastify = require('fastify')(
5
+ {
6
+ logger: true,
7
+ bodyLimit: 15 * 1048576,
8
+ }
9
+ );
10
+ const { PKPass } = require('passkit-generator');
11
+
12
+ // Certificates
13
+ const certDirectory = path.resolve(process.cwd(), 'cert');
14
+ const wwdr = fs.readFileSync(path.join(certDirectory, 'wwdr.pem'));
15
+ const signerCert = fs.readFileSync(path.join(certDirectory, 'signerCert.pem'));
16
+ const signerKey = fs.readFileSync(path.join(certDirectory, 'signerKey.key'));
17
+
18
+ fastify.post('/', async (request, reply) => {
19
+ const {
20
+ name,
21
+ cardNr,
22
+ dateFrom,
23
+ dateTo,
24
+ dateBirth,
25
+ aztecCode,
26
+ type,
27
+ image
28
+ } = request.body;
29
+
30
+ const passID = crypto.createHash('md5').update(`${name}_${Date.now()}`).digest('hex')
31
+
32
+
33
+ // Generate the pass
34
+ const pass = await PKPass.from(
35
+ {
36
+ // Path to your pass model directory
37
+ model: path.resolve(process.cwd(), 'transit.pass'),
38
+ certificates: {
39
+ wwdr,
40
+ signerCert,
41
+ signerKey,
42
+ },
43
+ },
44
+ {
45
+ serialNumber: passID,
46
+ },
47
+ );
48
+
49
+ // MARK: add Infos to the pass
50
+ // Barcode Type
51
+ const barcode = {
52
+ format: "PKBarcodeFormatAztec",
53
+ message: aztecCode,
54
+ messageEncoding: "iso-8859-1"
55
+ };
56
+
57
+ // Barcode Data
58
+ pass.setBarcodes(barcode);
59
+
60
+ // Expiration Format
61
+ const [day, month, year] = dateTo.split('.');
62
+ const date = new Date(`${year}-${month}-${day}T23:59:00+01:00`);
63
+
64
+ // Expiration Date
65
+ pass.setExpirationDate(date);
66
+
67
+ // headerFields
68
+ pass.headerFields.push(
69
+ {
70
+ key: 'type',
71
+ value: type
72
+ }
73
+ );
74
+
75
+ // primaryFields
76
+ pass.primaryFields.push(
77
+ {
78
+ key: 'name',
79
+ value: name
80
+ }
81
+ );
82
+
83
+ // secondaryFields
84
+ pass.secondaryFields.push(
85
+ {
86
+ key: 'cardNr',
87
+ label: "Kartennummer",
88
+ value: cardNr
89
+ },
90
+ {
91
+ key: 'dateTo',
92
+ label: "Ablaufdatum",
93
+ value: dateTo
94
+ },
95
+ );
96
+
97
+ // auxiliaryFields
98
+ pass.auxiliaryFields.push(
99
+ {
100
+ key: 'dateBirth',
101
+ label: "Geburtsdatum",
102
+ value: dateBirth
103
+ },
104
+ {
105
+ key: 'dateFrom',
106
+ label: "Beginn",
107
+ value: dateFrom
108
+ }
109
+ );
110
+
111
+ // Add a Image to the pass
112
+ // Decode the image from Base64 and save or use it directly
113
+ const imageBuffer = Buffer.from(image, "base64");
114
+
115
+ // Now you can use the image in your PKPass
116
+ pass.addBuffer("thumbnail.png", imageBuffer);
117
+ pass.addBuffer("thumbnail@2x.png", imageBuffer);
118
+
119
+ reply.header('Content-Type', 'application/vnd-apple.pkpass');
120
+ reply.send(pass.getAsBuffer());
121
+ });
122
+
123
+ // Start the server
124
+ fastify.listen({ port: process.env.PORT ?? 3000, host: '0.0.0.0' }, function (err) {
125
+ if (err) {
126
+ fastify.log.error(err);
127
+ process.exit(1);
128
+ }
129
+ fastify.log.info(`Server listening on ${fastify.server.address().port}`);
130
+ });
package-lock.json ADDED
The diff for this file is too large to render. See raw diff
 
package.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "server",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "fastify": "^4.24.3",
14
+ "passkit-generator": "^3.1.11",
15
+ "react-native-wallet-manager": "^0.0.5"
16
+ }
17
+ }