-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
76 lines (69 loc) · 2.28 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const path = require("path");
const express = require("express");
const bodyParser = require("body-parser");
const Cloudinary = require("./src/server/Cloudinary");
const colorUtils = require("./src/server/colorUtils");
const colorData = require("./src/server/colorData");
// function mapColorsToPpms(colors) {
// const key_n60 = colorUtils.findClosestColor(
// colorUtils.nitrate60Colors,
// colors[0]
// );
// const key_n30 = colorUtils.findClosestColor(
// colorUtils.nitrate30Colors,
// colors[1]
// );
// const key_p = colorUtils.findClosestColor(
// colorUtils.phosphateColors,
// colors[2]
// );
// return [
// colorData.nitrate_60s[key_n60],
// colorData.nitrate_30s[key_n30],
// colorData.phosphate[key_p],
// null
// ];
// }
module.exports = {
app: function() {
const app = express();
const indexPath = path.join(__dirname, "index.html");
const publicPath = express.static(path.join(__dirname, "public"));
app.use(bodyParser.json({ limit: "50mb" }));
app.use("/public", publicPath);
app.post("/api/upload", (req, res) => {
console.log(
`<-------------- UPLOADING ${req.body.imgData
.length} TO CLOUDINARY -------------->`
);
Cloudinary.uploadFiles(req.body.imgData) // uploaded in the order nitrate60s, nitrate30s, phosphate, bloom
.then(
imgData =>
new Promise(resolve => resolve(Cloudinary.getColors(imgData)))
)
.then(colors => {
console.log(
`<-------------- CONVERTING ${colors.length} RESULTS -------------->`
);
for (var i = 0; i < colors.length; i += 1) {
var hex_match = null;
if (colors[i]) {
console.log("Starting color conversion process for ", colors[i]);
hex_match = colorUtils.findClosestColor(
colorUtils.colorsArray[i],
colors[i].hex
);
colors[i].hex_match = hex_match;
colors[i].ppm = colorData.ppms[i][hex_match];
colors[i].index = Object.keys(colorData.ppms[i]).indexOf(hex_match);
}
}
res.send(colors);
});
});
app.get("/*", function(_, res) {
res.sendFile(indexPath);
});
return app;
}
};