mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 14:25:17 +00:00
Add a control on sha-1 creation, various
This commit is contained in:
46
index.js
46
index.js
@@ -124,15 +124,16 @@ function generateManifest(fromObject, tempFolderPath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
instance.listen(80, "0.0.0.0", function(req, res) {
|
instance.listen(80, "0.0.0.0", function(req, res) {
|
||||||
console.log("Listening on 80")
|
console.log("Listening on 80");
|
||||||
});
|
});
|
||||||
|
|
||||||
instance.get("/", function (req, res) {
|
instance.get("/", function (req, res) {
|
||||||
res.send("Hello there");
|
res.send("Hello there!");
|
||||||
});
|
});
|
||||||
|
|
||||||
instance.get("/gen/:type/", function (req, res) {
|
instance.get("/gen/:type/", function (req, res) {
|
||||||
if (!supportedTypesOfPass.test(req.params.type)) {
|
if (!supportedTypesOfPass.test(req.params.type)) {
|
||||||
|
// 😊
|
||||||
res.set("Content-Type", "application/json");
|
res.set("Content-Type", "application/json");
|
||||||
res.status(418).send({ ecode: 418, status: false, message: `Model unsupported. Refer to https://apple.co/2KKcCrB for supported pass models.`});
|
res.status(418).send({ ecode: 418, status: false, message: `Model unsupported. Refer to https://apple.co/2KKcCrB for supported pass models.`});
|
||||||
return;
|
return;
|
||||||
@@ -141,6 +142,7 @@ instance.get("/gen/:type/", function (req, res) {
|
|||||||
fs.readdir(`${passModelsDir}/${req.params.type}.pass`, {}, function (err, files) {
|
fs.readdir(`${passModelsDir}/${req.params.type}.pass`, {}, function (err, files) {
|
||||||
/* Invalid path for passModelsDir */
|
/* Invalid path for passModelsDir */
|
||||||
if (err) {
|
if (err) {
|
||||||
|
// 😊
|
||||||
res.set("Content-Type", "application/json");
|
res.set("Content-Type", "application/json");
|
||||||
res.status(418).send({ ecode: 418, status: false, message: `Model not available for requested type [${res.params.type}]. Provide a folder with specified name and .pass extension.`});
|
res.status(418).send({ ecode: 418, status: false, message: `Model not available for requested type [${res.params.type}]. Provide a folder with specified name and .pass extension.`});
|
||||||
return;
|
return;
|
||||||
@@ -149,17 +151,26 @@ instance.get("/gen/:type/", function (req, res) {
|
|||||||
let list = removeDotFiles(files);
|
let list = removeDotFiles(files);
|
||||||
|
|
||||||
if (!list.length) {
|
if (!list.length) {
|
||||||
|
// 😊
|
||||||
res.set("Content-Type", "application/json");
|
res.set("Content-Type", "application/json");
|
||||||
res.status(418).send({ ecode: 418, status: false, message: `Model for type [${req.params.type}] has no contents. Refer to https://apple.co/2IhJr0Q `});
|
res.status(418).send({ ecode: 418, status: false, message: `Model for type [${req.params.type}] has no contents. Refer to https://apple.co/2IhJr0Q `});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!list.includes("pass.json")) {
|
if (!list.includes("pass.json")) {
|
||||||
|
// 😊
|
||||||
res.set("Content-Type", "application/json");
|
res.set("Content-Type", "application/json");
|
||||||
res.status(418).send({ ecode: 418, status: false, message: "I'm a tea pot. How am I supposed to serve you pass without pass.json in the chosen model as tea without water?" });
|
res.status(418).send({ ecode: 418, status: false, message: "I'm a tea pot. How am I supposed to serve you pass without pass.json in the chosen model as tea without water?" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Creating a temporary directory to keep the manifest.json of each pass.
|
||||||
|
* This is done to pass the file as openssl parameter.
|
||||||
|
* It would be better to pass openssl a buffer but sadly it seems not possible.
|
||||||
|
* Feel free to contribute if you think there's a better way to achieve this.
|
||||||
|
*/
|
||||||
|
|
||||||
fs.mkdtemp(path.join(os.tmpdir(), "passkitWebServer-"), function(err, tempFolder) {
|
fs.mkdtemp(path.join(os.tmpdir(), "passkitWebServer-"), function(err, tempFolder) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -170,24 +181,29 @@ instance.get("/gen/:type/", function (req, res) {
|
|||||||
let archive = archiver("zip");
|
let archive = archiver("zip");
|
||||||
|
|
||||||
async.each(list, function getHashAndArchive(file, callback) {
|
async.each(list, function getHashAndArchive(file, callback) {
|
||||||
let passFileStream = fs.createReadStream(`${passModelsDir}/${req.params.type}.pass/${file}`);
|
if (file !== "manifest.json" && file !== "signature") {
|
||||||
let hashFlow = crypto.createHash("sha1");
|
let passFileStream = fs.createReadStream(`${passModelsDir}/${req.params.type}.pass/${file}`);
|
||||||
|
let hashFlow = crypto.createHash("sha1");
|
||||||
|
|
||||||
// adding the files to the zip - i'm not using .directory method because it adds also hidden files like .DS_Store on macOS
|
// adding the files to the zip - i'm not using .directory method because it adds also hidden files like .DS_Store on macOS
|
||||||
archive.file(`${passModelsDir}/${req.params.type}.pass/${file}`, { name: file });
|
archive.file(`${passModelsDir}/${req.params.type}.pass/${file}`, { name: file });
|
||||||
|
|
||||||
passFileStream.on("data", function(data) {
|
passFileStream.on("data", function(data) {
|
||||||
hashFlow.update(data);
|
hashFlow.update(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
passFileStream.on("error", function(e) {
|
passFileStream.on("error", function(e) {
|
||||||
return callback(e);
|
return callback(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
passFileStream.on("end", function() {
|
passFileStream.on("end", function() {
|
||||||
manifestRaw[file] = hashFlow.digest("hex").trim();
|
manifestRaw[file] = hashFlow.digest("hex").trim();
|
||||||
|
return callback();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// skipping files
|
||||||
return callback();
|
return callback();
|
||||||
});
|
}
|
||||||
}, function end(error) {
|
}, function end(error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
throw new Error(`Unable to compile manifest. ${error}`);
|
throw new Error(`Unable to compile manifest. ${error}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user