mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 13:25:19 +00:00
Add a control on sha-1 creation, various
This commit is contained in:
20
index.js
20
index.js
@@ -124,15 +124,16 @@ function generateManifest(fromObject, tempFolderPath) {
|
||||
}
|
||||
|
||||
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) {
|
||||
res.send("Hello there");
|
||||
res.send("Hello there!");
|
||||
});
|
||||
|
||||
instance.get("/gen/:type/", function (req, res) {
|
||||
if (!supportedTypesOfPass.test(req.params.type)) {
|
||||
// 😊
|
||||
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.`});
|
||||
return;
|
||||
@@ -141,6 +142,7 @@ instance.get("/gen/:type/", function (req, res) {
|
||||
fs.readdir(`${passModelsDir}/${req.params.type}.pass`, {}, function (err, files) {
|
||||
/* Invalid path for passModelsDir */
|
||||
if (err) {
|
||||
// 😊
|
||||
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.`});
|
||||
return;
|
||||
@@ -149,17 +151,26 @@ instance.get("/gen/:type/", function (req, res) {
|
||||
let list = removeDotFiles(files);
|
||||
|
||||
if (!list.length) {
|
||||
// 😊
|
||||
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 `});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!list.includes("pass.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?" });
|
||||
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) {
|
||||
if (err) {
|
||||
throw err;
|
||||
@@ -170,6 +181,7 @@ instance.get("/gen/:type/", function (req, res) {
|
||||
let archive = archiver("zip");
|
||||
|
||||
async.each(list, function getHashAndArchive(file, callback) {
|
||||
if (file !== "manifest.json" && file !== "signature") {
|
||||
let passFileStream = fs.createReadStream(`${passModelsDir}/${req.params.type}.pass/${file}`);
|
||||
let hashFlow = crypto.createHash("sha1");
|
||||
|
||||
@@ -188,6 +200,10 @@ instance.get("/gen/:type/", function (req, res) {
|
||||
manifestRaw[file] = hashFlow.digest("hex").trim();
|
||||
return callback();
|
||||
});
|
||||
} else {
|
||||
// skipping files
|
||||
return callback();
|
||||
}
|
||||
}, function end(error) {
|
||||
if (error) {
|
||||
throw new Error(`Unable to compile manifest. ${error}`);
|
||||
|
||||
Reference in New Issue
Block a user