aboutsummaryrefslogtreecommitdiff
path: root/api/routes/receiveZBlock
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2023-03-30 01:09:30 +0300
committerkaotisk <kaotisk@arching-kaos.org>2023-03-30 01:09:30 +0300
commite2da6d2db20093ebd2a65aad35c9991ab1a02176 (patch)
treee5c77a8f4a6fd106b13b659e248cab5768d07cdc /api/routes/receiveZBlock
parenta4901ad47d2945e9a6c6616661840c97ebbf03e7 (diff)
downloadarching-kaos-tools-e2da6d2db20093ebd2a65aad35c9991ab1a02176.tar.gz
arching-kaos-tools-e2da6d2db20093ebd2a65aad35c9991ab1a02176.tar.bz2
arching-kaos-tools-e2da6d2db20093ebd2a65aad35c9991ab1a02176.zip
Introducing an HTTP JSON API
Diffstat (limited to 'api/routes/receiveZBlock')
-rw-r--r--api/routes/receiveZBlock/index.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/api/routes/receiveZBlock/index.js b/api/routes/receiveZBlock/index.js
new file mode 100644
index 0000000..3ad6100
--- /dev/null
+++ b/api/routes/receiveZBlock/index.js
@@ -0,0 +1,28 @@
+/*
+ * Accepts a ZBLOCK!
+ *
+ * Checks:
+ * 1. Exists,
+ * 2. Length is 46 bytes,
+ * 3. Matches regular expression /Qm[A-Za-z0-9]{44}/
+ *
+ * Returns:
+ * - errno on failure
+ * - on success the string is processed for further
+ * validation to the function getvalidity()
+ *
+ */
+const getvalidity = require('../../validators/ZblockValidator')
+module.exports = (req, res) => {
+ console.log("okay we got called")
+ if ( (req.body.zblock) && req.body.zblock.length === 46 ){
+ regex= /Qm[A-Za-z0-9]{44}/;
+ if (regex.test(req.body.zblock)){
+ getvalidity(req.body.zblock,res);
+ } else {
+ res.send({errno:"Invalid data"});
+ }
+ } else {
+ res.send({errno:"Invalid data"});
+ }
+}