Update server.js
Browse files
server.js
CHANGED
|
@@ -1,19 +1,25 @@
|
|
| 1 |
const express = require("express");
|
| 2 |
const multer = require("multer");
|
| 3 |
-
const {
|
| 4 |
|
| 5 |
const app = express();
|
| 6 |
const upload = multer({ storage: multer.memoryStorage() });
|
| 7 |
|
| 8 |
-
app.post("/convert", upload.single("image"),
|
| 9 |
if (!req.file) return res.status(400).send("No image uploaded");
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
});
|
| 18 |
|
| 19 |
app.listen(7860, () => console.log("Server running on port 7860"));
|
|
|
|
| 1 |
const express = require("express");
|
| 2 |
const multer = require("multer");
|
| 3 |
+
const { exec } = require("child_process");
|
| 4 |
|
| 5 |
const app = express();
|
| 6 |
const upload = multer({ storage: multer.memoryStorage() });
|
| 7 |
|
| 8 |
+
app.post("/convert", upload.single("image"), (req, res) => {
|
| 9 |
if (!req.file) return res.status(400).send("No image uploaded");
|
| 10 |
|
| 11 |
+
const width = req.query.width || 50;
|
| 12 |
+
const command = `jp2a --width=${width} -`;
|
| 13 |
+
|
| 14 |
+
const child = exec(command, { encoding: "utf8" });
|
| 15 |
+
|
| 16 |
+
child.stdin.write(req.file.buffer);
|
| 17 |
+
child.stdin.end();
|
| 18 |
+
|
| 19 |
+
let ascii = "";
|
| 20 |
+
child.stdout.on("data", (data) => (ascii += data));
|
| 21 |
+
child.stdout.on("end", () => res.type("text/plain").send(ascii));
|
| 22 |
+
child.stderr.on("data", () => res.status(500).send("Error processing image"));
|
| 23 |
});
|
| 24 |
|
| 25 |
app.listen(7860, () => console.log("Server running on port 7860"));
|