From 4ee1a4a5f2ecfec7881d9215bc5e20b7015bf070 Mon Sep 17 00:00:00 2001 From: Peter Karman Date: Mon, 15 Oct 2018 20:31:24 -0500 Subject: [PATCH 1/2] Merge upstream refactor --- src/api.js | 37 ++- src/formDefinitions/KSAV1.js | 226 +++++++++------ src/formDefinitions/KSAV2.js | 210 +++++++++----- src/formDefinitions/VREN.js | 419 +++++++++++++++++++++------ src/formDefinitions/VRES.js | 545 ++++++++++++++++++++++------------- src/routes/FLEX.js | 75 ----- src/routes/KSAV1.js | 68 ----- src/routes/KSAV2.js | 70 ----- src/routes/VREN.js | 68 ----- src/routes/VRES.js | 70 ----- test.pl | 4 +- 11 files changed, 973 insertions(+), 819 deletions(-) delete mode 100644 src/routes/FLEX.js delete mode 100644 src/routes/KSAV1.js delete mode 100644 src/routes/KSAV2.js delete mode 100644 src/routes/VREN.js delete mode 100644 src/routes/VRES.js diff --git a/src/api.js b/src/api.js index 14d7817..5440e69 100644 --- a/src/api.js +++ b/src/api.js @@ -5,14 +5,14 @@ let newrelic = require('newrelic'); import express from "express"; import bodyParser from "body-parser"; -import VRENroute from "./routes/VREN"; -import VRESroute from "./routes/VRES"; -import KSAV1route from "./routes/KSAV1"; -import KSAV2route from "./routes/KSAV2"; -import FLEXroute from "./routes/FLEX"; +import routeLogic from "./helpers/routeLogic"; +import KSAV1 from "./formDefinitions/KSAV1"; +import KSAV2 from "./formDefinitions/KSAV2"; +import VRES from "./formDefinitions/VRES"; +import VREN from "./formDefinitions/VREN"; const app = express(); -const jsonParser = bodyParser.json({limit: '50mb', extended: true}); +const jsonParser = bodyParser.json({ limit: "50mb", extended: true }); app.locals.newrelic = newrelic; @@ -20,10 +20,25 @@ app.get("/", (req, res) => { res.json({ message: "ok" }); }); -app.post("/vr/en", jsonParser, VRENroute); -app.post("/vr/es", jsonParser, VRESroute); -app.post("/av/ksav1", jsonParser, KSAV1route); -app.post("/av/ksav2", jsonParser, KSAV2route); -app.post("/flex", jsonParser, FLEXroute); +app.post("/vr/en", jsonParser, async (req, res) => { + res.json(await routeLogic(VREN, req.body)); +}); + +app.post("/vr/es", jsonParser, async (req, res) => { + res.json(await routeLogic(VRES, req.body)); +}); + +app.post("/av/ksav1", jsonParser, async (req, res) => { + res.json(await routeLogic(KSAV1, req.body)); +}); + +app.post("/av/ksav2", jsonParser, async (req, res) => { + res.json(await routeLogic(KSAV2, req.body)); +}); + +app.post("/flex", jsonParser, async (req, res) => { + const { formData, formDefinition } = req.body; + res.json(await routeLogic(formDefinition, formData)); +}); export default app; diff --git a/src/formDefinitions/KSAV1.js b/src/formDefinitions/KSAV1.js index 7d37a0c..1eaa5e3 100644 --- a/src/formDefinitions/KSAV1.js +++ b/src/formDefinitions/KSAV1.js @@ -1,87 +1,139 @@ -export default [ - { name: "state", x1: 204, y1: 340, x2: 512, y2: 372, type: "draw" }, - { name: "county_2", x1: 652, y1: 339, x2: 963, y2: 372, type: "draw" }, - { name: "id_number", x1: 1109, y1: 577, x2: 1596, y2: 625, type: "draw" }, - { name: "last_name", x1: 103, y1: 1031, x2: 564, y2: 1077, type: "draw" }, - { name: "first_name", x1: 598, y1: 1031, x2: 1064, y2: 1077, type: "draw" }, - { - name: "middle_initial", - x1: 1097, - y1: 1032, - x2: 1163, - y2: 1077, - type: "draw" - }, - { name: "dob", x1: 1198, y1: 1032, x2: 1600, y2: 1076, type: "draw" }, - { - name: "residential_address", - x1: 99, - y1: 1107, - x2: 748, - y2: 1145, - type: "draw" - }, - { - name: "residential_state", - x1: 1200, - y1: 1108, - x2: 1354, - y2: 1145, - type: "draw" - }, - { - name: "residential_zip", - x1: 1397, - y1: 1108, - x2: 1601, - y2: 1145, - type: "draw" - }, - { name: "democratic", x1: 865, y1: 1196, x2: 884, y2: 1214, type: "fill" }, - { name: "republican", x1: 1029, y1: 1196, x2: 1048, y2: 1214, type: "fill" }, - { - name: "mailing_address", - x1: 101, - y1: 1300, - x2: 746, - y2: 1351, - type: "draw" - }, - { name: "mailing_city", x1: 799, y1: 1299, x2: 1155, y2: 1351, type: "draw" }, - { - name: "mailing_state", - x1: 1198, - y1: 1299, - x2: 1352, - y2: 1348, - type: "draw" - }, - { name: "mailing_zip", x1: 1398, y1: 1299, x2: 1600, y2: 1349, type: "draw" }, - { name: "election_date", x1: 95, y1: 1679, x2: 408, y2: 1718, type: "draw" }, - { name: "signature", x1: 321, y1: 1738, x2: 764, y2: 1833, type: "overlay" }, - { - name: "signature_date", - x1: 799, - y1: 1779, - x2: 1187, - y2: 1833, - type: "draw" - }, - { - name: "phone_number", - x1: 1218, - y1: 1779, - x2: 1594, - y2: 1833, - type: "draw" - }, - { - name: "residential_city", - x1: 799, - y1: 1108, - x2: 1156, - y2: 1143, - type: "draw" - }, - { name: "county_1", x1: 574, y1: 298, x2: 867, y2: 331, type: "draw" } -]; +export default { + baseImg: "https://s3.amazonaws.com/ksvotes/AV1NVRIS.png", + fields: [ + { name: "state", x1: 204, y1: 340, x2: 512, y2: 372, type: "draw" }, + { name: "county_2", x1: 652, y1: 339, x2: 963, y2: 372, type: "draw" }, + { name: "id_number", x1: 1109, y1: 577, x2: 1596, y2: 625, type: "draw" }, + { name: "last_name", x1: 103, y1: 1031, x2: 564, y2: 1077, type: "draw" }, + { + name: "first_name", + x1: 598, + y1: 1031, + x2: 1064, + y2: 1077, + type: "draw" + }, + { + name: "middle_initial", + x1: 1097, + y1: 1032, + x2: 1163, + y2: 1077, + type: "draw" + }, + { name: "dob", x1: 1198, y1: 1032, x2: 1600, y2: 1076, type: "draw" }, + { + name: "residential_address", + x1: 99, + y1: 1107, + x2: 748, + y2: 1145, + type: "draw" + }, + { + name: "residential_state", + x1: 1200, + y1: 1108, + x2: 1354, + y2: 1145, + type: "draw" + }, + { + name: "residential_zip", + x1: 1397, + y1: 1108, + x2: 1601, + y2: 1145, + type: "draw" + }, + { + name: "democratic", + x1: 865, + y1: 1196, + x2: 884, + y2: 1214, + type: "fill" + }, + { + name: "republican", + x1: 1029, + y1: 1196, + x2: 1048, + y2: 1214, + type: "fill" + }, + { + name: "mailing_address", + x1: 101, + y1: 1300, + x2: 746, + y2: 1351, + type: "draw" + }, + { + name: "mailing_city", + x1: 799, + y1: 1299, + x2: 1155, + y2: 1351, + type: "draw" + }, + { + name: "mailing_state", + x1: 1198, + y1: 1299, + x2: 1352, + y2: 1348, + type: "draw" + }, + { + name: "mailing_zip", + x1: 1398, + y1: 1299, + x2: 1600, + y2: 1349, + type: "draw" + }, + { + name: "election_date", + x1: 101, + y1: 1679, + x2: 408, + y2: 1718, + type: "draw" + }, + { + name: "signature", + x1: 301, + y1: 1738, + x2: 764, + y2: 1833, + type: "overlay" + }, + { + name: "signature_date", + x1: 799, + y1: 1779, + x2: 1187, + y2: 1833, + type: "draw" + }, + { + name: "phone_number", + x1: 1218, + y1: 1779, + x2: 1594, + y2: 1833, + type: "draw" + }, + { + name: "residential_city", + x1: 799, + y1: 1108, + x2: 1156, + y2: 1143, + type: "draw" + }, + { name: "county_1", x1: 574, y1: 298, x2: 867, y2: 331, type: "draw" } + ] +}; diff --git a/src/formDefinitions/KSAV2.js b/src/formDefinitions/KSAV2.js index e0cec65..b3e0253 100644 --- a/src/formDefinitions/KSAV2.js +++ b/src/formDefinitions/KSAV2.js @@ -1,79 +1,131 @@ -export default [ - { name: "county_1", x1: 702, y1: 291, x2: 1086, y2: 332, type: "draw" }, - { name: "state", x1: 192, y1: 379, x2: 520, y2: 416, type: "draw" }, - { name: "county_2", x1: 699, y1: 374, x2: 1029, y2: 418, type: "draw" }, - { name: "reason_for_perm", x1: 65, y1: 654, x2: 1611, y2: 706, type: "draw" }, - { name: "last_name", x1: 62, y1: 824, x2: 738, y2: 874, type: "draw" }, - { name: "first_name", x1: 793, y1: 824, x2: 1470, y2: 875, type: "draw" }, - { - name: "middle_initial", - x1: 1524, - y1: 823, - x2: 1623, - y2: 876, - type: "draw" - }, - { - name: "residential_address", - x1: 62, - y1: 930, - x2: 1611, - y2: 977, - type: "draw" - }, - { - name: "residential_city", - x1: 65, - y1: 1024, - x2: 952, - y2: 1076, - type: "draw" - }, - { - name: "residential_state", - x1: 1002, - y1: 1023, - x2: 1156, - y2: 1077, - type: "draw" - }, - { - name: "residential_zip", - x1: 1210, - y1: 1023, - x2: 1617, - y2: 1075, - type: "draw" - }, - { name: "democratic", x1: 307, y1: 1162, x2: 339, y2: 1194, type: "fill" }, - { name: "republican", x1: 564, y1: 1162, x2: 597, y2: 1195, type: "fill" }, - { name: "dob", x1: 1212, y1: 1147, x2: 1617, y2: 1192, type: "draw" }, - { - name: "mailing_address", - x1: 63, - y1: 1311, - x2: 1612, - y2: 1359, - type: "draw" - }, - { name: "mailing_city", x1: 63, y1: 1419, x2: 952, y2: 1460, type: "draw" }, - { - name: "mailing_state", - x1: 1000, - y1: 1420, - x2: 1158, - y2: 1460, - type: "draw" - }, - { name: "mailing_zip", x1: 1212, y1: 1420, x2: 1620, y2: 1461, type: "draw" }, - { name: "signature", x1: 292, y1: 1902, x2: 854, y2: 1978, type: "overlay" }, - { - name: "signature_date", - x1: 896, - y1: 1932, - x2: 1170, - y2: 1977, - type: "draw" - }, - { name: "phone_number", x1: 1202, y1: 1932, x2: 1619, y2: 1977, type: "draw" } -]; +export default { + baseImg: "https://s3.amazonaws.com/ksvotes/PERMVOTINGSTATUS.png", + fields: [ + { name: "county_1", x1: 702, y1: 291, x2: 1086, y2: 332, type: "draw" }, + { name: "state", x1: 192, y1: 379, x2: 520, y2: 416, type: "draw" }, + { name: "county_2", x1: 699, y1: 374, x2: 1029, y2: 418, type: "draw" }, + { + name: "reason_for_perm", + x1: 65, + y1: 654, + x2: 1611, + y2: 706, + type: "draw" + }, + { name: "last_name", x1: 62, y1: 824, x2: 738, y2: 874, type: "draw" }, + { name: "first_name", x1: 793, y1: 824, x2: 1470, y2: 875, type: "draw" }, + { + name: "middle_initial", + x1: 1524, + y1: 823, + x2: 1623, + y2: 876, + type: "draw" + }, + { + name: "residential_address", + x1: 62, + y1: 930, + x2: 1611, + y2: 977, + type: "draw" + }, + { + name: "residential_city", + x1: 65, + y1: 1024, + x2: 952, + y2: 1076, + type: "draw" + }, + { + name: "residential_state", + x1: 1002, + y1: 1023, + x2: 1156, + y2: 1077, + type: "draw" + }, + { + name: "residential_zip", + x1: 1210, + y1: 1023, + x2: 1617, + y2: 1075, + type: "draw" + }, + { + name: "democratic", + x1: 307, + y1: 1162, + x2: 339, + y2: 1194, + type: "fill" + }, + { + name: "republican", + x1: 564, + y1: 1162, + x2: 597, + y2: 1195, + type: "fill" + }, + { name: "dob", x1: 1212, y1: 1147, x2: 1617, y2: 1192, type: "draw" }, + { + name: "mailing_address", + x1: 63, + y1: 1311, + x2: 1612, + y2: 1359, + type: "draw" + }, + { + name: "mailing_city", + x1: 63, + y1: 1419, + x2: 952, + y2: 1460, + type: "draw" + }, + { + name: "mailing_state", + x1: 1000, + y1: 1420, + x2: 1158, + y2: 1460, + type: "draw" + }, + { + name: "mailing_zip", + x1: 1212, + y1: 1420, + x2: 1620, + y2: 1461, + type: "draw" + }, + { + name: "signature", + x1: 272, + y1: 1902, + x2: 854, + y2: 1978, + type: "overlay" + }, + { + name: "signature_date", + x1: 896, + y1: 1932, + x2: 1170, + y2: 1977, + type: "draw" + }, + { + name: "phone_number", + x1: 1202, + y1: 1932, + x2: 1619, + y2: 1977, + type: "draw" + } + ] +}; diff --git a/src/formDefinitions/VREN.js b/src/formDefinitions/VREN.js index 3f25128..85573a1 100644 --- a/src/formDefinitions/VREN.js +++ b/src/formDefinitions/VREN.js @@ -1,82 +1,337 @@ -export default [ - { name: "00_citizen_no", x1: 843, y1: 186, x2: 872, y2: 213, type: "fill" }, - { name: "00_citizen_yes", x1: 706, y1: 186, x2: 735, y2: 213, type: "fill" }, - { - name: "00_eighteenPlus_yes", - x1: 705, - y1: 218, - x2: 735, - y2: 245, - type: "fill" - }, - { - name: "00_eighteenPlus_no", - x1: 842, - y1: 218, - x2: 871, - y2: 245, - type: "fill" - }, - { name: "01_prefix_mr", x1: 151, y1: 319, x2: 180, y2: 345, type: "fill" }, - { name: "01_prefix_mrs", x1: 152, y1: 354, x2: 179, y2: 381, type: "fill" }, - { name: "01_prefix_miss", x1: 254, y1: 319, x2: 283, y2: 346, type: "fill" }, - { name: "01_prefix_ms", x1: 254, y1: 353, x2: 283, y2: 381, type: "fill" }, - { name: "01_suffix_jr", x1: 1482, y1: 328, x2: 1505, y2: 347, type: "fill" }, - { name: "01_suffix_sr", x1: 1485, y1: 364, x2: 1505, y2: 381, type: "fill" }, - { name: "01_suffix_ii", x1: 1548, y1: 315, x2: 1569, y2: 334, type: "fill" }, - { name: "01_suffix_iii", x1: 1548, y1: 342, x2: 1568, y2: 360, type: "fill" }, - { name: "01_suffix_iv", x1: 1548, y1: 369, x2: 1569, y2: 389, type: "fill" }, - { name: "01_lastName", x1: 362, y1: 340, x2: 711, y2: 390, type: "draw" }, - { name: "01_firstName", x1: 719, y1: 341, x2: 1093, y2: 390, type: "draw" }, - { name: "01_middleName", x1: 1100, y1: 340, x2: 1471, y2: 390, type: "draw" }, - { name: "02_homeAddress", x1: 143, y1: 425, x2: 755, y2: 473, type: "draw" }, - { name: "02_aptLot", x1: 765, y1: 428, x2: 908, y2: 471, type: "draw" }, - { name: "02_cityTown", x1: 918, y1: 430, x2: 1234, y2: 474, type: "draw" }, - { name: "02_state", x1: 1241, y1: 426, x2: 1436, y2: 474, type: "draw" }, - { name: "02_zipCode", x1: 1444, y1: 430, x2: 1600, y2: 473, type: "draw" }, - { name: "03_mailAddress", x1: 144, y1: 507, x2: 910, y2: 558, type: "draw" }, - { name: "03_cityTown", x1: 916, y1: 510, x2: 1234, y2: 558, type: "draw" }, - { name: "03_state", x1: 1239, y1: 508, x2: 1437, y2: 559, type: "draw" }, - { name: "03_zipCode", x1: 1445, y1: 511, x2: 1601, y2: 558, type: "draw" }, - { name: "04_dob", x1: 272, y1: 597, x2: 501, y2: 650, type: "draw" }, - { name: "05_telephone", x1: 560, y1: 597, x2: 908, y2: 691, type: "draw" }, - { name: "06_idNumber", x1: 1006, y1: 605, x2: 1544, y2: 742, type: "draw" }, - { name: "07_party", x1: 149, y1: 751, x2: 505, y2: 799, type: "draw" }, - { name: "08_raceEthnic", x1: 558, y1: 749, x2: 909, y2: 798, type: "draw" }, - { name: "09_month", x1: 932, y1: 986, x2: 1040, y2: 1028, type: "draw" }, - { name: "09_day", x1: 1087, y1: 987, x2: 1161, y2: 1028, type: "draw" }, - { name: "09_year", x1: 1201, y1: 987, x2: 1356, y2: 1028, type: "draw" }, - { name: "A_prefix_mr", x1: 150, y1: 1297, x2: 177, y2: 1324, type: "fill" }, - { name: "A_prefix_mrs", x1: 149, y1: 1333, x2: 178, y2: 1359, type: "fill" }, - { name: "A_prefix_miss", x1: 234, y1: 1297, x2: 262, y2: 1323, type: "fill" }, - { name: "A_prefix_ms", x1: 232, y1: 1333, x2: 262, y2: 1358, type: "fill" }, - { name: "A_suffix_jr", x1: 1485, y1: 1302, x2: 1505, y2: 1322, type: "fill" }, - { name: "A_suffix_sr", x1: 1486, y1: 1339, x2: 1506, y2: 1357, type: "fill" }, - { name: "A_suffix_ii", x1: 1546, y1: 1292, x2: 1568, y2: 1311, type: "fill" }, - { - name: "A_suffix_iii", - x1: 1546, - y1: 1318, - x2: 1568, - y2: 1339, - type: "fill" - }, - { name: "A_suffix_iv", x1: 1545, y1: 1346, x2: 1567, y2: 1366, type: "fill" }, - { name: "A_lastName", x1: 323, y1: 1313, x2: 819, y2: 1375, type: "draw" }, - { - name: "A_middleName", - x1: 1166, - y1: 1314, - x2: 1463, - y2: 1375, - type: "draw" - }, - { name: "A_firstName", x1: 826, y1: 1313, x2: 1158, y2: 1375, type: "draw" }, - { name: "B_homeAddress", x1: 144, y1: 1463, x2: 712, y2: 1508, type: "draw" }, - { name: "B_aptLot", x1: 719, y1: 1465, x2: 910, y2: 1508, type: "draw" }, - { name: "B_cityTown", x1: 919, y1: 1466, x2: 1222, y2: 1508, type: "draw" }, - { name: "B_state", x1: 1232, y1: 1464, x2: 1439, y2: 1506, type: "draw" }, - { name: "B_zipCode", x1: 1447, y1: 1464, x2: 1599, y2: 1506, type: "draw" }, - { name: "D_helper", x1: 144, y1: 1945, x2: 1600, y2: 2007, type: "draw" }, - { name: "signature", x1: 856, y1: 815, x2: 1578, y2: 929, type: "overlay" } -]; +export default { + baseImg: "https://s3.amazonaws.com/ksvotes/FEDVRENNVRIS.png", + fields: [ + { + name: "00_citizen_no", + x1: 843, + y1: 186, + x2: 872, + y2: 213, + type: "fill" + }, + { + name: "00_citizen_yes", + x1: 706, + y1: 186, + x2: 735, + y2: 213, + type: "fill" + }, + { + name: "00_eighteenPlus_yes", + x1: 705, + y1: 218, + x2: 735, + y2: 245, + type: "fill" + }, + { + name: "00_eighteenPlus_no", + x1: 842, + y1: 218, + x2: 871, + y2: 245, + type: "fill" + }, + { + name: "01_prefix_mr", + x1: 151, + y1: 319, + x2: 180, + y2: 345, + type: "fill" + }, + { + name: "01_prefix_mrs", + x1: 152, + y1: 354, + x2: 179, + y2: 381, + type: "fill" + }, + { + name: "01_prefix_miss", + x1: 254, + y1: 319, + x2: 283, + y2: 346, + type: "fill" + }, + { + name: "01_prefix_ms", + x1: 254, + y1: 353, + x2: 283, + y2: 381, + type: "fill" + }, + { + name: "01_suffix_jr", + x1: 1482, + y1: 328, + x2: 1505, + y2: 347, + type: "fill" + }, + { + name: "01_suffix_sr", + x1: 1485, + y1: 364, + x2: 1505, + y2: 381, + type: "fill" + }, + { + name: "01_suffix_ii", + x1: 1548, + y1: 315, + x2: 1569, + y2: 334, + type: "fill" + }, + { + name: "01_suffix_iii", + x1: 1548, + y1: 342, + x2: 1568, + y2: 360, + type: "fill" + }, + { + name: "01_suffix_iv", + x1: 1548, + y1: 369, + x2: 1569, + y2: 389, + type: "fill" + }, + { name: "01_lastName", x1: 362, y1: 340, x2: 711, y2: 390, type: "draw" }, + { + name: "01_firstName", + x1: 719, + y1: 341, + x2: 1093, + y2: 390, + type: "draw" + }, + { + name: "01_middleName", + x1: 1100, + y1: 340, + x2: 1471, + y2: 390, + type: "draw" + }, + { + name: "02_homeAddress", + x1: 143, + y1: 425, + x2: 755, + y2: 473, + type: "draw" + }, + { name: "02_aptLot", x1: 765, y1: 428, x2: 908, y2: 471, type: "draw" }, + { + name: "02_cityTown", + x1: 918, + y1: 430, + x2: 1234, + y2: 474, + type: "draw" + }, + { name: "02_state", x1: 1241, y1: 426, x2: 1436, y2: 474, type: "draw" }, + { + name: "02_zipCode", + x1: 1444, + y1: 430, + x2: 1600, + y2: 473, + type: "draw" + }, + { + name: "03_mailAddress", + x1: 144, + y1: 507, + x2: 910, + y2: 558, + type: "draw" + }, + { + name: "03_cityTown", + x1: 916, + y1: 510, + x2: 1234, + y2: 558, + type: "draw" + }, + { name: "03_state", x1: 1239, y1: 508, x2: 1437, y2: 559, type: "draw" }, + { + name: "03_zipCode", + x1: 1445, + y1: 511, + x2: 1601, + y2: 558, + type: "draw" + }, + { name: "04_dob", x1: 272, y1: 597, x2: 501, y2: 650, type: "draw" }, + { + name: "05_telephone", + x1: 560, + y1: 597, + x2: 908, + y2: 691, + type: "draw" + }, + { + name: "06_idNumber", + x1: 1006, + y1: 605, + x2: 1544, + y2: 742, + type: "draw" + }, + { name: "07_party", x1: 149, y1: 751, x2: 505, y2: 799, type: "draw" }, + { + name: "08_raceEthnic", + x1: 558, + y1: 749, + x2: 909, + y2: 798, + type: "draw" + }, + { name: "09_month", x1: 932, y1: 986, x2: 1040, y2: 1028, type: "draw" }, + { name: "09_day", x1: 1087, y1: 987, x2: 1161, y2: 1028, type: "draw" }, + { name: "09_year", x1: 1201, y1: 987, x2: 1356, y2: 1028, type: "draw" }, + { + name: "A_prefix_mr", + x1: 150, + y1: 1297, + x2: 177, + y2: 1324, + type: "fill" + }, + { + name: "A_prefix_mrs", + x1: 149, + y1: 1333, + x2: 178, + y2: 1359, + type: "fill" + }, + { + name: "A_prefix_miss", + x1: 234, + y1: 1297, + x2: 262, + y2: 1323, + type: "fill" + }, + { + name: "A_prefix_ms", + x1: 232, + y1: 1333, + x2: 262, + y2: 1358, + type: "fill" + }, + { + name: "A_suffix_jr", + x1: 1485, + y1: 1302, + x2: 1505, + y2: 1322, + type: "fill" + }, + { + name: "A_suffix_sr", + x1: 1486, + y1: 1339, + x2: 1506, + y2: 1357, + type: "fill" + }, + { + name: "A_suffix_ii", + x1: 1546, + y1: 1292, + x2: 1568, + y2: 1311, + type: "fill" + }, + { + name: "A_suffix_iii", + x1: 1546, + y1: 1318, + x2: 1568, + y2: 1339, + type: "fill" + }, + { + name: "A_suffix_iv", + x1: 1545, + y1: 1346, + x2: 1567, + y2: 1366, + type: "fill" + }, + { + name: "A_lastName", + x1: 323, + y1: 1313, + x2: 819, + y2: 1375, + type: "draw" + }, + { + name: "A_middleName", + x1: 1166, + y1: 1314, + x2: 1463, + y2: 1375, + type: "draw" + }, + { + name: "A_firstName", + x1: 826, + y1: 1313, + x2: 1158, + y2: 1375, + type: "draw" + }, + { + name: "B_homeAddress", + x1: 144, + y1: 1463, + x2: 712, + y2: 1508, + type: "draw" + }, + { name: "B_aptLot", x1: 719, y1: 1465, x2: 910, y2: 1508, type: "draw" }, + { + name: "B_cityTown", + x1: 919, + y1: 1466, + x2: 1222, + y2: 1508, + type: "draw" + }, + { name: "B_state", x1: 1232, y1: 1464, x2: 1439, y2: 1506, type: "draw" }, + { + name: "B_zipCode", + x1: 1447, + y1: 1464, + x2: 1599, + y2: 1506, + type: "draw" + }, + { name: "D_helper", x1: 144, y1: 1945, x2: 1600, y2: 2007, type: "draw" }, + { + name: "signature", + x1: 836, + y1: 815, + x2: 1578, + y2: 929, + type: "overlay" + } + ] +}; diff --git a/src/formDefinitions/VRES.js b/src/formDefinitions/VRES.js index 556dbf1..8e7994c 100644 --- a/src/formDefinitions/VRES.js +++ b/src/formDefinitions/VRES.js @@ -1,208 +1,337 @@ -export default [ - { - name: "00_citizen_yes", - x1: 408, - y1: 220, - x2: 435, - y2: 248, - type: "fill" - }, - { name: "00_citizen_no", x1: 483, y1: 221, x2: 509, y2: 246, type: "fill" }, - { - name: "00_eighteenPlus_yes", - x1: 1068, - y1: 220, - x2: 1093, - y2: 246, - type: "fill" - }, - { - name: "00_eighteenPlus_no", - x1: 1140, - y1: 221, - x2: 1165, - y2: 246, - type: "fill" - }, - { name: "01_prefix_mr", x1: 138, y1: 373, x2: 181, y2: 417, type: "draw" }, - { name: "01_prefix_mrs", x1: 191, y1: 372, x2: 237, y2: 418, type: "draw" }, - { - name: "01_prefix_miss", - x1: 247, - y1: 373, - x2: 295, - y2: 418, - type: "draw" - }, - { name: "01_prefix_ms", x1: 310, y1: 372, x2: 354, y2: 417, type: "draw" }, - { name: "01_lastName", x1: 374, y1: 373, x2: 701, y2: 423, type: "draw" }, - { name: "01_firstName", x1: 714, y1: 374, x2: 1034, y2: 423, type: "draw" }, - { - name: "01_middleName", - x1: 1043, - y1: 375, - x2: 1355, - y2: 425, - type: "draw" - }, - { - name: "01_suffix_jr", - x1: 1363, - y1: 379, - x2: 1390, - y2: 414, - type: "circle" - }, - { - name: "01_suffix_sr", - x1: 1411, - y1: 378, - x2: 1443, - y2: 414, - type: "circle" - }, - { - name: "01_suffix_ii", - x1: 1463, - y1: 379, - x2: 1493, - y2: 414, - type: "circle" - }, - { - name: "01_suffix_iii", - x1: 1508, - y1: 379, - x2: 1543, - y2: 414, - type: "circle" - }, - { - name: "01_suffix_iv", - x1: 1556, - y1: 378, - x2: 1593, - y2: 414, - type: "circle" - }, - { - name: "02_homeAddress", - x1: 138, - y1: 456, - x2: 703, - y2: 492, - type: "draw" - }, - { name: "02_aptLot", x1: 713, y1: 456, x2: 901, y2: 492, type: "draw" }, - { name: "02_cityTown", x1: 909, y1: 456, x2: 1223, y2: 491, type: "draw" }, - { name: "02_state", x1: 1232, y1: 454, x2: 1426, y2: 491, type: "draw" }, - { name: "02_zipCode", x1: 1436, y1: 455, x2: 1590, y2: 490, type: "draw" }, - { - name: "03_mailAddress", - x1: 138, - y1: 523, - x2: 899, - y2: 560, - type: "draw" - }, - { name: "03_cityTown", x1: 909, y1: 524, x2: 1223, y2: 562, type: "draw" }, - { name: "03_state", x1: 1233, y1: 525, x2: 1427, y2: 561, type: "draw" }, - { name: "03_zipCode", x1: 1436, y1: 525, x2: 1590, y2: 562, type: "draw" }, - { name: "04_dob", x1: 246, y1: 601, x2: 481, y2: 633, type: "draw" }, - { name: "05_telephone", x1: 549, y1: 597, x2: 900, y2: 664, type: "draw" }, - { name: "06_idNumber", x1: 964, y1: 619, x2: 1578, y2: 714, type: "draw" }, - { name: "07_party", x1: 215, y1: 720, x2: 493, y2: 765, type: "draw" }, - { name: "08_raceEthnic", x1: 610, y1: 721, x2: 898, y2: 766, type: "draw" }, - { name: "signature", x1: 1013, y1: 795, x2: 1455, y2: 869, type: "overlay" }, - { name: "09_month", x1: 1017, y1: 928, x2: 1113, y2: 963, type: "draw" }, - { name: "09_day", x1: 1162, y1: 927, x2: 1277, y2: 964, type: "draw" }, - { name: "09_year", x1: 1318, y1: 930, x2: 1450, y2: 961, type: "draw" }, - { name: "A_prefix_mr", x1: 141, y1: 1274, x2: 193, y2: 1294, type: "circle" }, - { - name: "A_prefix_mrs", - x1: 142, - y1: 1294, - x2: 207, - y2: 1313, - type: "circle" - }, - { - name: "A_prefix_miss", - x1: 143, - y1: 1314, - x2: 207, - y2: 1335, - type: "circle" - }, - { name: "A_prefix_ms", x1: 143, y1: 1333, x2: 208, y2: 1352, type: "circle" }, - { name: "A_lastName", x1: 304, y1: 1296, x2: 673, y2: 1356, type: "draw" }, - { - name: "A_firstName", - x1: 686, - y1: 1297, - x2: 1048, - y2: 1357, - type: "draw" - }, - { - name: "A_middleName", - x1: 1062, - y1: 1299, - x2: 1398, - y2: 1358, - type: "draw" - }, - { - name: "A_suffix_jr", - x1: 1410, - y1: 1332, - x2: 1432, - y2: 1357, - type: "circle" - }, - { - name: "A_suffix_sr", - x1: 1449, - y1: 1332, - x2: 1476, - y2: 1358, - type: "circle" - }, - { - name: "A_suffix_ii", - x1: 1489, - y1: 1332, - x2: 1513, - y2: 1357, - type: "circle" - }, - { - name: "A_suffix_iii", - x1: 1525, - y1: 1332, - x2: 1551, - y2: 1357, - type: "circle" - }, - { - name: "A_suffix_iv", - x1: 1563, - y1: 1332, - x2: 1591, - y2: 1358, - type: "circle" - }, - { - name: "B_homeAddress", - x1: 139, - y1: 1465, - x2: 673, - y2: 1503, - type: "draw" - }, - { name: "B_aptLot", x1: 684, y1: 1468, x2: 857, y2: 1505, type: "draw" }, - { name: "B_cityTown", x1: 867, y1: 1471, x2: 1215, y2: 1505, type: "draw" }, - { name: "B_state", x1: 1224, y1: 1473, x2: 1431, y2: 1505, type: "draw" }, - { name: "B_zipCode", x1: 1439, y1: 1474, x2: 1591, y2: 1505, type: "draw" }, - { name: "D_helper", x1: 134, y1: 1983, x2: 1593, y2: 2048, type: "draw" } -]; +export default { + baseImg: "https://s3.amazonaws.com/ksvotes/FEDVRENNVRIS_SP.png", + fields: [ + { + name: "00_citizen_yes", + x1: 408, + y1: 220, + x2: 435, + y2: 248, + type: "fill" + }, + { + name: "00_citizen_no", + x1: 483, + y1: 221, + x2: 509, + y2: 246, + type: "fill" + }, + { + name: "00_eighteenPlus_yes", + x1: 1068, + y1: 220, + x2: 1093, + y2: 246, + type: "fill" + }, + { + name: "00_eighteenPlus_no", + x1: 1140, + y1: 221, + x2: 1165, + y2: 246, + type: "fill" + }, + { + name: "01_prefix_mr", + x1: 138, + y1: 373, + x2: 181, + y2: 417, + type: "draw" + }, + { + name: "01_prefix_mrs", + x1: 191, + y1: 372, + x2: 237, + y2: 418, + type: "draw" + }, + { + name: "01_prefix_miss", + x1: 247, + y1: 373, + x2: 295, + y2: 418, + type: "draw" + }, + { + name: "01_prefix_ms", + x1: 310, + y1: 372, + x2: 354, + y2: 417, + type: "draw" + }, + { name: "01_lastName", x1: 374, y1: 373, x2: 701, y2: 423, type: "draw" }, + { + name: "01_firstName", + x1: 714, + y1: 374, + x2: 1034, + y2: 423, + type: "draw" + }, + { + name: "01_middleName", + x1: 1043, + y1: 375, + x2: 1355, + y2: 425, + type: "draw" + }, + { + name: "01_suffix_jr", + x1: 1363, + y1: 379, + x2: 1390, + y2: 414, + type: "circle" + }, + { + name: "01_suffix_sr", + x1: 1411, + y1: 378, + x2: 1443, + y2: 414, + type: "circle" + }, + { + name: "01_suffix_ii", + x1: 1463, + y1: 379, + x2: 1493, + y2: 414, + type: "circle" + }, + { + name: "01_suffix_iii", + x1: 1508, + y1: 379, + x2: 1543, + y2: 414, + type: "circle" + }, + { + name: "01_suffix_iv", + x1: 1556, + y1: 378, + x2: 1593, + y2: 414, + type: "circle" + }, + { + name: "02_homeAddress", + x1: 138, + y1: 456, + x2: 703, + y2: 492, + type: "draw" + }, + { name: "02_aptLot", x1: 713, y1: 456, x2: 901, y2: 492, type: "draw" }, + { + name: "02_cityTown", + x1: 909, + y1: 456, + x2: 1223, + y2: 491, + type: "draw" + }, + { name: "02_state", x1: 1232, y1: 454, x2: 1426, y2: 491, type: "draw" }, + { + name: "02_zipCode", + x1: 1436, + y1: 455, + x2: 1590, + y2: 490, + type: "draw" + }, + { + name: "03_mailAddress", + x1: 138, + y1: 523, + x2: 899, + y2: 560, + type: "draw" + }, + { + name: "03_cityTown", + x1: 909, + y1: 524, + x2: 1223, + y2: 562, + type: "draw" + }, + { name: "03_state", x1: 1233, y1: 525, x2: 1427, y2: 561, type: "draw" }, + { + name: "03_zipCode", + x1: 1436, + y1: 525, + x2: 1590, + y2: 562, + type: "draw" + }, + { name: "04_dob", x1: 246, y1: 601, x2: 481, y2: 633, type: "draw" }, + { + name: "05_telephone", + x1: 549, + y1: 597, + x2: 900, + y2: 664, + type: "draw" + }, + { + name: "06_idNumber", + x1: 964, + y1: 619, + x2: 1578, + y2: 714, + type: "draw" + }, + { name: "07_party", x1: 215, y1: 720, x2: 493, y2: 765, type: "draw" }, + { + name: "08_raceEthnic", + x1: 610, + y1: 721, + x2: 898, + y2: 766, + type: "draw" + }, + { + name: "signature", + x1: 993, + y1: 795, + x2: 1455, + y2: 869, + type: "overlay" + }, + { name: "09_month", x1: 1017, y1: 928, x2: 1113, y2: 963, type: "draw" }, + { name: "09_day", x1: 1162, y1: 927, x2: 1277, y2: 964, type: "draw" }, + { name: "09_year", x1: 1318, y1: 930, x2: 1450, y2: 961, type: "draw" }, + { + name: "A_prefix_mr", + x1: 141, + y1: 1274, + x2: 193, + y2: 1294, + type: "circle" + }, + { + name: "A_prefix_mrs", + x1: 142, + y1: 1294, + x2: 207, + y2: 1313, + type: "circle" + }, + { + name: "A_prefix_miss", + x1: 143, + y1: 1314, + x2: 207, + y2: 1335, + type: "circle" + }, + { + name: "A_prefix_ms", + x1: 143, + y1: 1333, + x2: 208, + y2: 1352, + type: "circle" + }, + { + name: "A_lastName", + x1: 304, + y1: 1296, + x2: 673, + y2: 1356, + type: "draw" + }, + { + name: "A_firstName", + x1: 686, + y1: 1297, + x2: 1048, + y2: 1357, + type: "draw" + }, + { + name: "A_middleName", + x1: 1062, + y1: 1299, + x2: 1398, + y2: 1358, + type: "draw" + }, + { + name: "A_suffix_jr", + x1: 1410, + y1: 1332, + x2: 1432, + y2: 1357, + type: "circle" + }, + { + name: "A_suffix_sr", + x1: 1449, + y1: 1332, + x2: 1476, + y2: 1358, + type: "circle" + }, + { + name: "A_suffix_ii", + x1: 1489, + y1: 1332, + x2: 1513, + y2: 1357, + type: "circle" + }, + { + name: "A_suffix_iii", + x1: 1525, + y1: 1332, + x2: 1551, + y2: 1357, + type: "circle" + }, + { + name: "A_suffix_iv", + x1: 1563, + y1: 1332, + x2: 1591, + y2: 1358, + type: "circle" + }, + { + name: "B_homeAddress", + x1: 139, + y1: 1465, + x2: 673, + y2: 1503, + type: "draw" + }, + { name: "B_aptLot", x1: 684, y1: 1468, x2: 857, y2: 1505, type: "draw" }, + { + name: "B_cityTown", + x1: 867, + y1: 1471, + x2: 1215, + y2: 1505, + type: "draw" + }, + { name: "B_state", x1: 1224, y1: 1473, x2: 1431, y2: 1505, type: "draw" }, + { + name: "B_zipCode", + x1: 1439, + y1: 1474, + x2: 1591, + y2: 1505, + type: "draw" + }, + { name: "D_helper", x1: 134, y1: 1983, x2: 1593, y2: 2048, type: "draw" } + ] +}; diff --git a/src/routes/FLEX.js b/src/routes/FLEX.js deleted file mode 100644 index 64c1247..0000000 --- a/src/routes/FLEX.js +++ /dev/null @@ -1,75 +0,0 @@ -import request from "request"; - -// import VRES from "../formDefinitions/VRES"; -import fillForm from "../helpers/fillForm"; -import renderImage from "../helpers/renderImage"; -import base64RenderToFile from "../helpers/base64RenderToFile"; -import getFormElementDimensions from "../helpers/getFormElementDimensions"; -import resizeImage from "../helpers/resizeImage"; -import overlayImagesThenRender from "../helpers/overlayImagesThenRender"; -import imageToBase64 from "../helpers/imageToBase64"; -import deleteTmpFiles from "../helpers/deleteTmpFiles"; - -// const path = require("path"); - -const Promise = require("bluebird"); -// const fs = require('fs'); -const gm = require("gm").subClass({ imageMagick: true }); -require("gm-base64"); - -Promise.promisifyAll(gm.prototype); - -export default async (req, res) => { - const { formData, formDefinition } = req.body; - - const base = gm(request(formDefinition.baseImg)); - // fill form - const filledForm = await fillForm(base, formDefinition.fields, formData); - // write filled form to tmp - await renderImage(filledForm, "/tmp/filled_form.gif"); - - let hasSignature = false; - if ("signature" in formData) { - hasSignature = true; - // render signature to file - await base64RenderToFile(formData.signature, "/tmp/signature.png"); - - const sigDimensions = getFormElementDimensions( - formDefinition.fields, - "signature" - ); - await resizeImage( - "/tmp/signature.png", - sigDimensions.width, - sigDimensions.height - ); - - // overlay signature on filled form - await overlayImagesThenRender( - "/tmp/signature.png", - "/tmp/filled_form.gif", - sigDimensions.x1, - sigDimensions.y1, - "/tmp/signed_form.gif" - ); - } - - // now we are ready to send response - let response; - if (hasSignature) { - response = { - VR_ES: "form Generated", - img: await imageToBase64("/tmp/signed_form.gif", "png") - }; - } else { - response = { - VR_ES: "form Generated", - img: await imageToBase64("/tmp/filled_form.gif", "png") - }; - } - - // delete tmp files - await deleteTmpFiles("/tmp"); - - res.json(response); -}; diff --git a/src/routes/KSAV1.js b/src/routes/KSAV1.js deleted file mode 100644 index c380f18..0000000 --- a/src/routes/KSAV1.js +++ /dev/null @@ -1,68 +0,0 @@ -import request from "request"; - -import KSAV1 from "../formDefinitions/KSAV1"; -import fillForm from "../helpers/fillForm"; -import renderImage from "../helpers/renderImage"; -import base64RenderToFile from "../helpers/base64RenderToFile"; -import getFormElementDimensions from "../helpers/getFormElementDimensions"; -import resizeImage from "../helpers/resizeImage"; -import overlayImagesThenRender from "../helpers/overlayImagesThenRender"; -import imageToBase64 from "../helpers/imageToBase64"; -import deleteTmpFiles from "../helpers/deleteTmpFiles"; - -// const path = require("path"); - -const Promise = require("bluebird"); -// const fs = require('fs'); -const gm = require("gm").subClass({ imageMagick: true }); -require("gm-base64"); - -Promise.promisifyAll(gm.prototype); - -export default async (req, res) => { - const formPayload = req.body; - - const base = gm(request("https://s3.amazonaws.com/ksvotes/AV1NVRIS.png")); - // fill form - const filledForm = await fillForm(base, KSAV1, formPayload); - // write filled form to tmp - await renderImage(filledForm, "/tmp/filled_form.gif"); - - let hasSignature = false; - let imgPath = "/tmp/filled_form.gif"; - if ("signature" in formPayload) { - hasSignature = true; - imgPath = "/tmp/signed_form.gif"; - // render signature to file - await base64RenderToFile(formPayload.signature, "/tmp/signature.png"); - - const sigDimensions = getFormElementDimensions(KSAV1, "signature"); - await resizeImage( - "/tmp/signature.png", - sigDimensions.width, - sigDimensions.height - ); - - // overlay signature on filled form - await overlayImagesThenRender( - "/tmp/signature.png", - "/tmp/filled_form.gif", - sigDimensions.x1, - sigDimensions.y1, - "/tmp/signed_form.gif" - ); - } - - // now we are ready to send response - let imgB64 = await imageToBase64(imgPath, "png"); - console.log(formPayload["uuid"]+": imgPath="+imgPath+" hasSignature:"+hasSignature+" img:"+imgB64.length+" bytes"); - let response = { - KSAV1: "form Generated", - img: imgB64 - }; - - // delete tmp files - await deleteTmpFiles("/tmp"); - - res.json(response); -}; diff --git a/src/routes/KSAV2.js b/src/routes/KSAV2.js deleted file mode 100644 index cceafb3..0000000 --- a/src/routes/KSAV2.js +++ /dev/null @@ -1,70 +0,0 @@ -import request from "request"; - -import KSAV2 from "../formDefinitions/KSAV2"; -import fillForm from "../helpers/fillForm"; -import renderImage from "../helpers/renderImage"; -import base64RenderToFile from "../helpers/base64RenderToFile"; -import getFormElementDimensions from "../helpers/getFormElementDimensions"; -import resizeImage from "../helpers/resizeImage"; -import overlayImagesThenRender from "../helpers/overlayImagesThenRender"; -import imageToBase64 from "../helpers/imageToBase64"; -import deleteTmpFiles from "../helpers/deleteTmpFiles"; - -// const path = require("path"); - -const Promise = require("bluebird"); -// const fs = require('fs'); -const gm = require("gm").subClass({ imageMagick: true }); -require("gm-base64"); - -Promise.promisifyAll(gm.prototype); - -export default async (req, res) => { - const formPayload = req.body; - - const base = gm( - request("https://s3.amazonaws.com/ksvotes/PERMVOTINGSTATUS.png") - ); - // fill form - const filledForm = await fillForm(base, KSAV2, formPayload); - // write filled form to tmp - await renderImage(filledForm, "/tmp/filled_form.gif"); - - let hasSignature = false; - let imgPath = "/tmp/filled_form.gif"; - if ("signature" in formPayload) { - hasSignature = true; - imgPath = "/tmp/signed_form.gif"; - // render signature to file - await base64RenderToFile(formPayload.signature, "/tmp/signature.png"); - - const sigDimensions = getFormElementDimensions(KSAV2, "signature"); - await resizeImage( - "/tmp/signature.png", - sigDimensions.width, - sigDimensions.height - ); - - // overlay signature on filled form - await overlayImagesThenRender( - "/tmp/signature.png", - "/tmp/filled_form.gif", - sigDimensions.x1, - sigDimensions.y1, - "/tmp/signed_form.gif" - ); - } - - // now we are ready to send response - let imgB64 = await imageToBase64(imgPath, "png"); - console.log(formPayload["uuid"]+": imgPath="+imgPath+" hasSignature:"+hasSignature+" img:"+imgB64.length+" bytes"); - let response = { - KSAV2: "form Generated", - img: imgB64 - }; - - // delete tmp files - await deleteTmpFiles("/tmp"); - - res.json(response); -}; diff --git a/src/routes/VREN.js b/src/routes/VREN.js deleted file mode 100644 index 38b4ea8..0000000 --- a/src/routes/VREN.js +++ /dev/null @@ -1,68 +0,0 @@ -import request from "request"; - -import VREN from "../formDefinitions/VREN"; -import fillForm from "../helpers/fillForm"; -import renderImage from "../helpers/renderImage"; -import base64RenderToFile from "../helpers/base64RenderToFile"; -import getFormElementDimensions from "../helpers/getFormElementDimensions"; -import resizeImage from "../helpers/resizeImage"; -import overlayImagesThenRender from "../helpers/overlayImagesThenRender"; -import imageToBase64 from "../helpers/imageToBase64"; -import deleteTmpFiles from "../helpers/deleteTmpFiles"; - -// const path = require("path"); - -const Promise = require("bluebird"); -// const fs = require('fs'); -const gm = require("gm").subClass({ imageMagick: true }); -require("gm-base64"); - -Promise.promisifyAll(gm.prototype); - -export default async (req, res) => { - const formPayload = req.body; - - const base = gm(request("https://s3.amazonaws.com/ksvotes/FEDVRENNVRIS.png")); - // fill form - const filledForm = await fillForm(base, VREN, formPayload); - // write filled form to tmp - await renderImage(filledForm, "/tmp/filled_form.gif"); - - let hasSignature = false; - let imgPath = "/tmp/filled_form.gif"; - if ("signature" in formPayload) { - hasSignature = true; - imgPath = "/tmp/signed_form.gif"; - // render signature to file - await base64RenderToFile(formPayload.signature, "/tmp/signature.png"); - - const sigDimensions = getFormElementDimensions(VREN, "signature"); - await resizeImage( - "/tmp/signature.png", - sigDimensions.width, - sigDimensions.height - ); - - // overlay signature on filled form - await overlayImagesThenRender( - "/tmp/signature.png", - "/tmp/filled_form.gif", - sigDimensions.x1, - sigDimensions.y1, - "/tmp/signed_form.gif" - ); - } - - // now we are ready to send response - let imgB64 = await imageToBase64(imgPath, "png"); - console.log(formPayload["uuid"]+": imgPath="+imgPath+" hasSignature:"+hasSignature+" img:"+imgB64.length+" bytes"); - let response = { - VR_ENG: "form Generated", - img: imgB64 - }; - - // delete tmp files - await deleteTmpFiles("/tmp"); - - res.json(response); -}; diff --git a/src/routes/VRES.js b/src/routes/VRES.js deleted file mode 100644 index 3d2cb70..0000000 --- a/src/routes/VRES.js +++ /dev/null @@ -1,70 +0,0 @@ -import request from "request"; - -import VRES from "../formDefinitions/VRES"; -import fillForm from "../helpers/fillForm"; -import renderImage from "../helpers/renderImage"; -import base64RenderToFile from "../helpers/base64RenderToFile"; -import getFormElementDimensions from "../helpers/getFormElementDimensions"; -import resizeImage from "../helpers/resizeImage"; -import overlayImagesThenRender from "../helpers/overlayImagesThenRender"; -import imageToBase64 from "../helpers/imageToBase64"; -import deleteTmpFiles from "../helpers/deleteTmpFiles"; - -// const path = require("path"); - -const Promise = require("bluebird"); -// const fs = require('fs'); -const gm = require("gm").subClass({ imageMagick: true }); -require("gm-base64"); - -Promise.promisifyAll(gm.prototype); - -export default async (req, res) => { - const formPayload = req.body; - - const base = gm( - request("https://s3.amazonaws.com/ksvotes/FEDVRENNVRIS_SP.png") - ); - // fill form - const filledForm = await fillForm(base, VRES, formPayload); - // write filled form to tmp - await renderImage(filledForm, "/tmp/filled_form.gif"); - - let hasSignature = false; - let imgPath = "/tmp/filled_form.gif"; - if ("signature" in formPayload) { - hasSignature = true; - imgPath = "/tmp/signed_form.gif"; - // render signature to file - await base64RenderToFile(formPayload.signature, "/tmp/signature.png"); - - const sigDimensions = getFormElementDimensions(VRES, "signature"); - await resizeImage( - "/tmp/signature.png", - sigDimensions.width, - sigDimensions.height - ); - - // overlay signature on filled form - await overlayImagesThenRender( - "/tmp/signature.png", - "/tmp/filled_form.gif", - sigDimensions.x1, - sigDimensions.y1, - "/tmp/signed_form.gif" - ); - } - - // now we are ready to send response - let imgB64 = await imageToBase64(imgPath, "png"); - console.log(formPayload["uuid"]+": imgPath="+imgPath+" hasSignature:"+hasSignature+" img:"+imgB64.length+" bytes"); - let response = { - VR_ES: "form Generated", - img: imgB64 - }; - - // delete tmp files - await deleteTmpFiles("/tmp"); - - res.json(response); -}; diff --git a/test.pl b/test.pl index 1842d35..8378f98 100644 --- a/test.pl +++ b/test.pl @@ -15,6 +15,8 @@ sub run_it { 'test-ab-en-payload.json' => '/av/ksav1', ); +my $base64decode = $^O eq 'linux' ? '-d' : '-D'; + for my $payload ( sort keys %tests ) { ( my $png = $payload ) =~ s/\.json/.png/; my $path = $tests{$payload}; @@ -23,7 +25,7 @@ sub run_it { qq{curl -s -XPOST -H 'Content-Type: application/json' --data \@$payload http://localhost:4500$path > $tmp} ); run_it( - qq{jq .img < $tmp | perl -n -e 's/"data:image\\/png;base64,|"//g; print' | base64 -D > $png} + qq{jq .img < $tmp | perl -n -e 's/"data:image\\/png;base64,|"//g; print' | base64 $base64decode > $png} ); print "PNG saved in $png\n"; } From d9a4d69625553505bf7649b95ee55d3c21739953 Mon Sep 17 00:00:00 2001 From: Peter Karman Date: Mon, 15 Oct 2018 21:19:20 -0500 Subject: [PATCH 2/2] forgot this file --- src/helpers/routeLogic.js | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/helpers/routeLogic.js diff --git a/src/helpers/routeLogic.js b/src/helpers/routeLogic.js new file mode 100644 index 0000000..ab9d5d2 --- /dev/null +++ b/src/helpers/routeLogic.js @@ -0,0 +1,64 @@ +import request from "request"; + +// import KSAV1 from "../formDefinitions/KSAV1"; +import fillForm from "./fillForm"; +import renderImage from "./renderImage"; +import base64RenderToFile from "./base64RenderToFile"; +import getFormElementDimensions from "./getFormElementDimensions"; +import resizeImage from "./resizeImage"; +import overlayImagesThenRender from "./overlayImagesThenRender"; +import imageToBase64 from "./imageToBase64"; +import deleteTmpFiles from "./deleteTmpFiles"; + +const gm = require("gm").subClass({ imageMagick: true }); +require("gm-base64"); + +export default async (formDefinition, formData) => { + const base = gm(request(formDefinition.baseImg)); + // fill form + const filledForm = await fillForm(base, formDefinition.fields, formData); + // write filled form to tmp + await renderImage(filledForm, "/tmp/filled_form.gif"); + + let hasSignature = false; + let imgPath = "/tmp/filled_form.gif"; + if ("signature" in formData) { + hasSignature = true; + imgPath = "/tmp/signed_form.gif"; + // render signature to file + await base64RenderToFile(formData.signature, "/tmp/signature.png"); + + const sigDimensions = getFormElementDimensions( + formDefinition.fields, + "signature" + ); + await resizeImage( + "/tmp/signature.png", + sigDimensions.width, + sigDimensions.height + ); + + // overlay signature on filled form + await overlayImagesThenRender( + "/tmp/signature.png", + "/tmp/filled_form.gif", + sigDimensions.x1, + sigDimensions.y1, + "/tmp/signed_form.gif" + ); + } + + // now we are ready to send response + let imgB64 = await imageToBase64(imgPath, "png"); + console.log(formData["uuid"]+": imgPath="+imgPath+" hasSignature:"+hasSignature+" img:"+imgB64.length+" bytes"); + + let response = { + "msg": "form generated from " + formDefinition.baseImg, + "img": imgB64 + }; + + // delete tmp files + await deleteTmpFiles("/tmp"); + + return response; +};