Skip to content

Commit

Permalink
Implement sha256 checksum calculation controller (buerokratt#57)
Browse files Browse the repository at this point in the history
* Implement sha256 checksum calculation method

* Add dependencies
  • Loading branch information
jannostern authored Jun 3, 2024
1 parent e15b9e0 commit f726bca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions controllers/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import express from "express";
import { createHash } from "crypto";
import bodyParser from "body-parser";
import { body, matchedData, validationResult } from "express-validator";

const router = express.Router();
Expand Down Expand Up @@ -27,6 +29,19 @@ router.post("/object-list-contains-id", async (req, res) => {
res.json(exists);
});

router.post(
"/calculate-sha256-checksum",
bodyParser.text({ type: "text/plain" }),
async (req, res) => {
if (Object.keys(req.body).length === 0) {
return res.status(400).json("error: request body is empty");
}
const hash = createHash("sha256");
hash.update(req.body);
res.send(hash.digest("hex"));
}
);

function checkIdExists(array, id) {
for (const element of array) {
if (element.id === id) return true;
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"start": "node server.js"
},
"dependencies": {
"body-parser": "^1.20.2",
"crypto-js": "^4.1.1",
"escape-string-regexp": "^5.0.0",
"express": "^4.18.2",
Expand Down

0 comments on commit f726bca

Please sign in to comment.