mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 19:25:23 +00:00
Added some path.resolve, fixed misconfiguration, improved support for pass naming
This commit is contained in:
23
index.js
23
index.js
@@ -317,25 +317,27 @@ function RequestHandler(request, response) {
|
|||||||
|
|
||||||
archive.append(signatureBuffer, { name: "signature" });
|
archive.append(signatureBuffer, { name: "signature" });
|
||||||
|
|
||||||
|
let passName = (request.query.name || request.body.name || request.params.type + (new Date()).toISOString().split('T')[0].replace(/-/ig, ""));
|
||||||
|
|
||||||
response.set({
|
response.set({
|
||||||
"Content-type": "application/vnd.apple.pkpass",
|
"Content-type": "application/vnd.apple.pkpass",
|
||||||
"Content-disposition": `attachment; filename=${request.query.name || request.body.name || request.params.type + (new Date()).toISOString().split('T')[0].replace(/-/ig, "") }.pkpass`
|
"Content-disposition": `attachment; filename=${passName}.pkpass`
|
||||||
})
|
});
|
||||||
|
|
||||||
if (Configuration.output.shouldWrite && Configuration.output.dir != null && request.params.name) {
|
if (Configuration.output.shouldWrite && !!Configuration.output.dir) {
|
||||||
// Memorize and then make it download
|
// Memorize and then make it download
|
||||||
let outputWS = fs.createWriteStream(`${Configuration.output.dir}/${request.params.type}.pkpass`);
|
let wstreamOutputPass = fs.createWriteStream(path.resolve(Configuration.output.dir, `${passName}.pkpass`));
|
||||||
|
archive.pipe(wstreamOutputPass);
|
||||||
|
|
||||||
archive.pipe(outputWS);
|
wstreamOutputPass.on("close", function() {
|
||||||
|
response.status(201).download(path.resolve(Configuration.output.dir, `${passName}.pkpass`), `${passName}.pkpass`, {
|
||||||
outputWS.on("close", function() {
|
|
||||||
response.status(201).download(`${Configuration.output.dir}/${request.params.type}.pkpass`, `${request.params.type}.pkpass`, {
|
|
||||||
cacheControl: false
|
cacheControl: false
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
archive.pipe(response)
|
// Streaming directly the buffer
|
||||||
response.status(201)
|
archive.pipe(response);
|
||||||
|
response.status(201);
|
||||||
}
|
}
|
||||||
|
|
||||||
archive.finalize();
|
archive.finalize();
|
||||||
@@ -392,6 +394,7 @@ function init(configPath) {
|
|||||||
|
|
||||||
if (!paths[1] && setup.output.shouldWrite) {
|
if (!paths[1] && setup.output.shouldWrite) {
|
||||||
Configuration.output.dir = setup.output.dir;
|
Configuration.output.dir = setup.output.dir;
|
||||||
|
Configuration.output.shouldWrite = true
|
||||||
}
|
}
|
||||||
|
|
||||||
Certificates.wwdr = certs[0];
|
Certificates.wwdr = certs[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user