This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added functionality to create and download pregenerated zip file of m…
…anifest
- Loading branch information
Showing
7 changed files
with
71 additions
and
14 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as express from "express"; | ||
import * as config from "config"; | ||
import * as fs from "fs"; | ||
import * as Zip from "node-zip"; | ||
|
||
export class ManifestCreatorEnd { | ||
|
||
public static getRequestHandler(): express.RequestHandler { | ||
return async function (req: any, res: any, next: any): Promise<void> { | ||
let baseUri = config.get("app.baseUri"); | ||
let appId = config.get("bot.botId"); | ||
let baseUriDomain = baseUri.replace(/^https:\/\/|^http:\/\//, ""); | ||
|
||
fs.readFile("../../manifest/manifest.json", "utf8", (err, data) => { | ||
if (!err) { | ||
fs.mkdir("../../manifest/createdManifest", (err2) => { | ||
if (!err2 || (err2.code && err2.code === "EEXIST")) { | ||
data = data.replace(/<<BASE_URI>>/g, baseUri); | ||
data = data.replace(/<<REGISTERED_BOT_ID>>/g, appId); | ||
data = data.replace(/<<BASE_URI_DOMAIN>>/g, baseUriDomain); | ||
fs.writeFile("../../manifest/createdManifest/manifest.json", data, (err3) => { | ||
if (!err3) { | ||
fs.readFile("../../manifest/createdManifest/bot_blue.png", (err4, data2) => { | ||
if (!err4) { | ||
let zip = new Zip; | ||
zip.file("manifest.json", data); | ||
zip.file("bot_blue.png", data2); | ||
let options = {base64: false, compression: "DEFLATE"}; | ||
let zippedData = zip.generate(options); | ||
fs.writeFile("../../manifest/createdManifest/createdManifest.zip", zippedData, "binary", (err5) => { | ||
if (!err5) { | ||
res.set("Content-Type", "application/zip"); | ||
res.end(zippedData, "binary"); | ||
} else { | ||
console.log(err5); | ||
} | ||
}); | ||
} else { | ||
console.log(err4); | ||
} | ||
}); | ||
} else { | ||
console.log(err3); | ||
} | ||
}); | ||
} else { | ||
console.log(err2); | ||
} | ||
}); | ||
} else { | ||
console.log(err); | ||
} | ||
}); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters